Jump to content

User:Enterprisey/links-in-logs.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Enterprisey (talk | contribs) at 04:43, 16 August 2018 (bugfix). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
$( function() {
    if( mw.config.get( "wgPageName" ).indexOf( "Special:Log" ) >= 0 ) {
        var allItems = document.querySelectorAll( "li[class^=mw-logline-]" );
        var newLink, timestamp;
        for( var i = 0, numItems = allItems.length; i < numItems; i++ ) {
            timestamp = /\d?\d:\d\d, \d\d \w+ \d{4}/.exec( allItems[i].childNodes[0].textContent );
            newLink = document.createElement( "a" );
            newLink.href = "https://en.wikipedia.org/w/index.php?title=Special%3ALog&logid=" + allItems[i].dataset.mwLogid;
            newLink.textContent = timestamp;
            allItems[i].childNodes[0].textContent = allItems[i].childNodes[0].textContent.replace( timestamp, "" );
            allItems[i].insertBefore( newLink, allItems[i].childNodes[0] );
        }
    }
} );