User:Msh210/hyphenate.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, it will take 5-10 minutes before the changes take effect. You may also have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

//many thanks to [[w:User:Splarka]] for help with this script
function hyphenate() {
 hyphenated=wgPageName.replace(/_/g,"-");
 apiurl=wgServer;
 apiurl+="/w/api.php?action=query&list=logevents&letype=delete&lelimit=1&prop=info&format=json&callback=existence";
 apiurl+="&titles="+hyphenated+"&letitle="+hyphenated;
 mw.loader.load(apiurl);
}
function existence(param) {
 en=document.getElementById("English");
 n=document.getElementById("Noun");
 if (!en || !n) return;
 hyphenated=wgPageName.replace(/_/g,"-");
 autoedit="s~~{{subst:new_en_adj_attr_bot|" + wgTitle + "|'''" + hyphenated + "''' ~g;";
 url=wgServer+"/wiki/"+hyphenated+"?action=edit&autoedit="+autoedit;//+"&autoclick=wpDiff";
 a=document.createElement('a');
 a.setAttribute('href',url);
 a.appendChild(document.createTextNode(hyphenated));
 a.setAttribute('style','color:#22cc00');//match WT:ACCEL
//
 goodforcreation=1;
 if (!(param['query']['pages']['-1'])) goodforcreation=0;
// if (param['query']['logevents'][0]) goodforcreation=0;
 if (goodforcreation) {
  en.parentNode.parentNode.insertBefore(a,en.parentNode.nextSibling.nextSibling.nextSibling);//right after the h2; FF-specific?
 }
}
if (wgNamespaceNumber==0 && wgAction=="view" && wgPageName.indexOf("_")!=-1) addOnloadHook(hyphenate);

function ligate() {
 ligated=wgPageName.replace(/אל/g,"ﭏ");
 apiurl=wgServer;
 apiurl+="/w/api.php?action=query&list=logevents&letype=delete&lelimit=1&prop=info&format=json&callback=existence2";
 apiurl+="&titles="+ligated+"&letitle="+ligated;
 mw.loader.load(apiurl);
}
function existence2(param) {
 he=document.getElementById("Hebrew");
 if (!he) return;
 ligated=wgPageName.replace(/אל/g,"ﭏ");
 autoedit="s~~#redirect [[" + wgTitle + "]] typographic variant~g;";
 url=wgServer+"/wiki/"+ligated+"?action=edit&redlink=1&autoedit="+autoedit;
 a=document.createElement('a');
 a.setAttribute('href',url);
 a.appendChild(document.createTextNode(ligated));
 a.setAttribute('style','color:#22cc00');//match WT:ACCEL
//
 goodforcreation=1;
 if (!(param['query']['pages']['-1'])) goodforcreation=0;
// if (param['query']['logevents'][0]) goodforcreation=0;
 if (goodforcreation) {
  he.parentNode.parentNode.insertBefore(a,he.parentNode.nextSibling.nextSibling);
 }
}
if (wgNamespaceNumber==0 && wgAction=="view" && wgPageName.indexOf("אל")!=-1) addOnloadHook(ligate);