User:Connel MacKenzie/diff.js

function addWiktDiffQuestion { //disambig-see-also, .disambig-see-also-2 var wiktSpans = document.getElementsByTagName('div'); var wiktDisambigSeeAlso; if (wiktSpans) { for (var i=0; i<wiktSpans.length; i++ ) { if ( wiktSpans[i].getAttribute('class') ) { if ( wiktSpans[i].getAttribute('class') == 'disambig-see-also' ) {wiktDisambigSeeAlso = wiktSpans[i];} if ( wiktSpans[i].getAttribute('class') == 'disambig-see-also-2' ) {wiktDisambigSeeAlso = wiktSpans[i];} }   }  }  if ( (wiktDisambigSeeAlso) ) { var wiktAs = wiktDisambigSeeAlso; for (var x=0; wiktAs.childNodes[x]; x++ ) { wiktAs2 = wiktAs.childNodes[x].innerHTML; if ( wiktAs2 ) { if ( wiktAs2.split('"')[0] == '<a href=' ) {       var what2d = wiktAs2.split('/wiki/')[1];        if (what2d) what2d = what2d.split('"')[0]; if (what2d) { var newa = document.createElement('a'); newa.href = '/w/index.php?title=' + what2d + '&diff=next&oldid=' + wgCurRevisionId; var newl = document.createTextNode('(diff)'); newa.appendChild(newl); var newsp = document.createTextNode(' '); wiktAs.childNodes[x].appendChild(newsp); wiktAs.childNodes[x].appendChild(newa); }     }      }    }  }

/* remove this cruft until a better place for the input box is suggested. var box = document.createElement('input'); box.type = 'text'; box.width = 30 box.id = 'wiktDiff'; box.name = 'wiktDiff';

var wiktBoxButton = document.createElement('input'); wiktBoxButton.type = 'submit'; wiktBoxButton.name = 'Diff'; wiktBoxButton.value = 'diff'; wiktBoxButton.onclick = function { document.location = 'http://en.wiktionary.org/w/index.php?title=' + document.getElementById('wiktDiff').value.replace(' ', '_') + '&diff=next&oldid=' + wgCurRevisionId; }

var captionforBox = document.createTextNode(' - compare to some other page: '); var firsthd = document.getElementsByTagName('H1')[0].childNodes[0]; firsthd.parentNode.appendChild( captionforBox ); firsthd.parentNode.appendChild( box ); firsthd.parentNode.appendChild( wiktBoxButton ); }

$( addWiktDiffQuestion );