User:Incnis Mrsi/revision №.js

// The script adds a Special:Diff link for each “revision {number}” comment

// This filters out Wikidata stuff and, generally, any comment having non-local link function CommentIsNotLocal ( el ) { var p = el.parentNode; if (!p) return(false); if (p.tagName == 'SPAN') { p = p.parentNode; if (!p) return(false); };   if (p.tagName != 'TD') return(false); // this is the cell showing most information on the diff if (p.childNodes.length < 2) return(false); var second = p.childNodes[1]; // the link inside (⋯) if (second.tagName != 'A') { var container = p.childNodes[0]; // sometimes the stuff lies under one extra level, in intermediate if (container.children.length < 2) return(false); second = container.children[1]; // the link inside (⋯) console.log(second); if (second.tagName != 'A') return(false); };   var href = second.getAttribute('href'); if (!href) return(false); return( href.charAt[0] != '/' ); };

var REVISION = /\srevision\s([1-9]\d{8})\s/;

function RevisionLinks { var comments = document.getElementsByClassName( "comment" ); for(var i = 0, n = comments.length; i < n; i++) { var el = comments[i]; var Match; if (          ( Match = REVISION.exec(el.innerHTML) )        && ! CommentIsNotLocal (el)        && ! el.innerHTML.match('‽')        ) { var diff = document.createElement( "a" ); //       		diff.setAttribute('class', "?" ); diff.setAttribute('href', "/wiki/Special:Diff/" + Match[1] ); diff.innerHTML = '‽'; el.parentNode.insertBefore(diff, el); }   } };

$( document ).load( RevisionLinks ); mw.hook( 'wikipage.content' ).add( RevisionLinks );