User:Technical 13/SandBox/timestampLinks.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* <nowiki>
 *
*/

/* Disable these for now... Will need to think more about them... Need to get class work done for now though...
function postNotes(target, user, summary, content){
    
}
*/

$('span.localcomments').each(function(){
    var timestamp = $(this).attr('timestamp');
    $(this).attr('id', timestamp);
    var revisionInfoQ = {
        action: 'query',
        prop: 'revisions',
        format: 'json',
        rvlimit: 1,
        rvprop: 'ids|user|comment',
        pageids: mw.config.get('wgArticleId'),
        rvstartid: timestamp,
        continue: ""
    };
    $.get(mw.config.get( 'wgScriptPath' )+"/api.php", revisionInfoQ, function(revisionInfoR){

console.log('%O', revisionInfoR);

        var revisionUser = $(revisionInfoR).find('user').text();
        var revisionSection = $(revisionInfoR).find('comment').text();
        revisionSection = revisionSection.match(/\/\* *(.*?) *\*\//);
        var revId = $(revisionInfoR).find('revid').text();

console.log('{user: "%s", sectionTitle: "%s", revid: %d}', revisionUser, revisionSection, revId);

        var tslbSep = '&thinsp;&#124;&thinsp;';
        var tslbLB = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=";
        var timestamplinkbar = '<small class="timestampLinks">(&thinsp;';
        timestamplinkbar += '<a href="' + tslbLB + 'User:' + revisionUser + '" title="User:' + revisionUser + '">u</a>';
        timestamplinkbar += tslbSep;
        timestamplinkbar += '<a href="' + tslbLB + 'User_talk:' + revisionUser + '" title="User_talk:' + revisionUser + '">t</a>';
        timestamplinkbar += tslbSep;
        timestamplinkbar += '<a href="#TalkBack" onClick="alert(\'This will eventually post a Talkback\')" title="Send {{Talkback}} to this section">TB</a>';
        timestamplinkbar += tslbSep;
        timestamplinkbar += '<a href="#Trout" onClick="alert(\'This will eventually trout the user for the revision.\')" title="Trout ' + revisionUser + '"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/Rainbow_trout_transparent.png/15px-Rainbow_trout_transparent.png" title="Trout!" /></a>';
        timestamplinkbar += tslbSep;
        timestamplinkbar += '<a href="' + tslbLB + 'Special:Contributions/' + revisionUser + '" title="Contributions">c</a>';
        timestamplinkbar += '&thinsp;)</small>';
        $('span#' + timestamp).prepend(timestamplinkbar);
    });
});

//</nowiki>