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:40, 30 November 2018 (further fixes). 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() {
    var pageName = mw.config.get( "wgPageName" );
    if( pageName.indexOf( "Special:Log" ) === 0 || pageName.indexOf( "Special:UserRights" ) === 0 ) {
        var DATE_RGX = /\d\d:\d\d, (\d\d? \w+|\w+ \d\d?,) \d{4}/;
        var allItems = document.querySelectorAll( "li[class^=mw-logline-]" );
console.log(allItems)
        var newLink, timestampMatch;
        for( var i = 0, numItems = allItems.length; i < numItems; i++ ) {
            for( var j = 0, numChildren = allItems[i].childNodes.length; j < numChildren; j++ ) {
                if( allItems[i].childNodes[j].nodeType === 3 &&
                        ( ( timestampMatch = DATE_RGX.exec( allItems[i].childNodes[j].textContent ) ) !== null ) ) {
console.log(allItems[i].childNodes[j].textContent );
                    newLink = document.createElement( "a" );
                    newLink.href = "https://en.wikipedia.org/w/index.php?title=Special:Log&logid=" + allItems[i].dataset.mwLogid;
                    newLink.textConten t= timestampMatch[0];
                    allItems[i].childNodes[j].textContent = allItems[i].childNodes[j].textContent.replace( timestamp, "" );
                    allItems[i].insertBefore( newLink, allItems[i].childNodes[j] );
                    break; // inner loop
                }
            }
        }
    }
} );