User:Inductiveload/Hyphenated word.js

/* * Does a lookup on the previous page to see if there is a hyphenated * word and tries to complete it * * To use this script, add the following to your .js: *    importScript('User:Inductiveload/Hyphenated word.js'); * */ function check_hws(data) {   try { var editbox = document.getElementsByName('wpTextbox1')[0]; if (editbox && !data.query.pages["-1"]) { for (var ids in data.query.pages) { var content = data.query.pages[ids].revisions[0]['*']; var match = content.match( /{{ *([Hh]ws|[Hh]yphenated word start)\|([^\|}]*)\|?([^\|}]*)?}}/ )

if (match != undefined && match.length > 3) { var hws = match[2]; var word = match[3]; var hwe = word.slice(hws.length) var hwestring = ' ' editbox.value = hwestring + editbox.value }

break; }       }    }    catch (err) { } } function hyphenated_word {   var r = new RegExp("(\\d+)$"); var page = Number(r.exec(mw.config.get('wgPageName'))[1]) - 1; //previous page var pagename = mw.config.get('wgPageName').replace(/\d+$/g, page); var url = mw.config.get('wgServer') + wgScriptPath + "/api.php?action=query&prop=revisions&callback=check_hws&rvprop=content" + "&format=json&titles=" + encodeURIComponent(pagename); $('body').append(''); } $ (function {	var tb = document.getElementById("toolbar");	if(tb){		var image = document.createElement("img");		image.width = 23;		image.height = 23;		image.border = 0;		image.className = "mw-toolbar-editbutton";		image.style.cursor = "pointer";		image.alt = "Hyph. word";		image.title = "Add hyphenated word started on the previous page";		image.src = "http://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Button_hyphenated_word.svg/23px-Button_hyphenated_word.svg.png";		image.onclick = hyphenated_word;		tb.appendChild(image);        }    } );