MediaWiki:Common.js
Från Seriewikin
Version från den 5 mars 2008 kl. 21.51 av MikkeX (diskussion | bidrag) (Ny sida: // <pre><nowiki> →OCR button: function addOCR(form,value){ if(value =="OCR"){ form.elements["wpSummary"].value="→OCR: "; s = form.elements["wpTextbox1"].value; form.elemen...)
Obs! När du har sparat måste du rensa webbläsarens cache-minne innan du kan se några ändringar: Mozilla: klicka på Reload/Uppdatera sidan (eller tryck på Ctrl-R), IE / Opera: Ctrl-F5, Safari: Kommando-R, Konqueror Ctrl-R.
// <pre><nowiki> /* OCR button */ function addOCR(form,value){ if(value =="OCR"){ form.elements["wpSummary"].value="/*OCR*/"; s = form.elements["wpTextbox1"].value; form.elements["wpTextbox1"].value="{"+"{"+"OCR"+"}"+"}"; } } function addOCRButton(){ if((wgCanonicalNamespace == "Page") && (!wgCurRevisionId) && (self.proofreadPageViewURL)){ var sb = document.getElementById("wpSave"); if(sb){ sb.parentNode.innerHTML = '<input id="wpOcr" name="ocr" type="submit" tabindex="5" accesskey="o" value="OCR" title="OCR" onclick="addOCR(this.form,this.value);"/>'+sb.parentNode.innerHTML; } var msg = document.getElementById("noTextMsg"); if(msg){ s = msg.innerHTML; s = s.replace(/vous pouvez <a href=(.*?)<\/a> ou (.*?)modifier cette page<\/a>\./g, 'vous pouvez ajouter le texte, ou demander une OCR automatique depuis la $2page d\'édition</a>.' ); msg.innerHTML=s; } var msg = document.getElementById("msgNewarticletext"); if(msg){ msg.innerHTML='You are editing a page that does not exist.<br/>You may request an OCR by clicking on the OCR button at the bottom of this page.'; } } } //addOnloadHook(addOCRButton); var proofreadpage_debug=1; /********************** *** Undocumented *** by unknown **********************/ function interwikiExtra() { // iterate over all <span>-elements for(var i=0; a = document.getElementsByTagName("span")[i]; i++) { // if found a linkInfo span if(a.className == "interwiki-info") { // iterate over all <li>-elements var count=0; for(var j=0; b = document.getElementsByTagName("li")[j]; j++) { if(b.className == "interwiki-" + a.id) { b.innerHTML = b.innerHTML + " "+a.title; if(a.title == "(vo)") { b.title = "Texte original"; } } else if(b.className == "interwiki-" + a.id.substr(0,a.id.length-1)) { count = count+1; if(a.id.charAt(a.id.length-1) == count) { b.innerHTML = b.innerHTML + " "+a.title; } } } } } } addOnloadHook(interwikiExtra); /********************** *** Quality indicators on "article" tab *** by [[user:ThomasV]] **********************/ function icon_src(t){ var src=''; switch(t){ case "0%": src='http://upload.wikimedia.org/wikipedia/commons/8/8f/00%25.png'; break; case "25%": src='http://upload.wikimedia.org/wikipedia/commons/5/5b/25%25.png'; break; case "50%": src='http://upload.wikimedia.org/wikipedia/commons/3/3a/50%25.png'; break; case "75%": src='http://upload.wikimedia.org/wikipedia/commons/c/cd/75%25.png'; break; case "100%": src='http://upload.wikimedia.org/wikipedia/commons/6/64/100%25.png'; break; } return src; } function pageQuality() { var a = document.getElementById("ca-nstab-main"); if(!a) return; var q = document.getElementById("textquality") if(q) { var new_img = document.createElement("img"); new_img.setAttribute("src", icon_src(q.className)); a.firstChild.appendChild(new_img); } for(var i=0; spanElem = document.getElementsByTagName("span")[i]; i++) { if (spanElem.className == "pagequality") { var new_img = document.createElement("img"); new_img.setAttribute("src", icon_src(spanElem.title)); if(wgCanonicalNamespace == "Page") { a.firstChild.appendChild(new_img); } else { s1 = spanElem.parentNode.previousSibling; opttext = s1.firstChild.firstChild; img = opttext.firstChild.nextSibling.nextSibling.nextSibling; next = img.nextSibling; opttext.removeChild(img); opttext.insertBefore(new_img,next); } } } } addOnloadHook(pageQuality); /********************** *** Add quality buttons on edit view *** by [[user:ThomasV]] **********************/ function addQuality(form,value){ var text=""; switch(value){ case "25%": text = "Incomplete"; break; case "50%": text = "Not formatted"; break; case "75%": text = "Complete and formatted"; break; case "100%": text = "Proofread"; break; } form.elements["wpSummary"].value="/* "+text+" */"; if(wgCanonicalNamespace == "Page") { s = form.elements["headerTextbox"].value; s = s.replace(/\{\{PageQuality\|(.*?)\}\}/gi,"") form.elements["headerTextbox"].value="{"+"{PageQuality|"+value+"}"+"}"+s; } else { s = form.elements["wpTextbox1"].value; s = s.replace(/\{\{TextQuality\|(.*?)\}\}/gi,"") form.elements["wpTextbox1"].value="{"+"{TextQuality|"+value+"}"+"}"+s; } } function addQualityButtons(){ if( wgNamespaceNumber != 0) { return; } var ig = document.getElementById("wpWatchthis"); if(ig) { var f = document.createElement("span"); f.innerHTML = ' <input type="radio" name="quality" value="25%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/Special:Filepath/25%25.png">'+'<input type="radio" name="quality" value="50%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/Special:Filepath/50%25.png">'+'<input type="radio" name="quality" value="75%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/Special:Filepath/75%25.png">'+'<input type="radio" name="quality" value="100%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/Special:Filepath/100%25.png"> Text advancement'; ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling) } } addOnloadHook(addQualityButtons); /********************** *** Add arrows on sidebar to compare current page to interlanguage link'd page *** by [[user:Pathoschild]], based on older script by unknown **********************/ function BilingualLink() { if(document.getElementById('p-lang') != null) { // get list of links var biboxes = document.getElementById('p-lang').getElementsByTagName('li'); // iterate over links for(var i=0; i<biboxes.length; i++) { // get link var bilink = biboxes[i].getElementsByTagName('a')[0]; // create new URL var bilang = bilink.getAttribute('href').match(/http:\/\/([^\.]+)\.wikisource/)[1]; var bilanglink = wgServer + '/wiki/' + wgPageName + '?match=' + bilang; // create link var bianchor = document.createElement('a'); bianchor.setAttribute('href',bilanglink); bianchor.setAttribute('title','Compare this page with the '+bilang+' version.'); bianchor.appendChild(document.createTextNode(' ⇔')); // add link biboxes[i].appendChild(bianchor); } } } addOnloadHook(BilingualLink); /********************** *** add menu on edit page /for selecting subsets of secial characters *** by [[user:Pathoschild]] *** - note: must match MediaWiki:Edittools **********************/ function addCharSubsetMenu() { var specialchars = document.getElementById('specialchars'); if (specialchars) { var menu = "<select style=\"display:inline\" onChange=\"chooseCharSubset(selectedIndex)\">"; menu += "<option>Select</option>"; menu += "<option>Ligatures and symbols</option>"; menu += "<option>Accents</option>"; menu += "<option>Tildes</option>"; menu += "<option>Cedillas</option>"; menu += "<option>Diareses</option>"; menu += "<option>Circumflexes</option>"; menu += "<option>Macrons</option>"; menu += "<option>Other diacritics</option>"; menu += "<option>Greek</option>"; menu += "<option>Hebrew</option>"; menu += "<option>Cyrillic</option>"; menu += "</select>"; specialchars.innerHTML = menu + specialchars.innerHTML.replace(/_newline_/gm, "\n"); /* default subset - try to use a cookie some day */ chooseCharSubset(0); } } /* select subsection of special characters */ function chooseCharSubset(s) { var l = document.getElementById('specialchars').getElementsByTagName('p'); for (var i = 0; i < l.length ; i++) { l[i].style.display = i == s ? 'inline' : 'none'; l[i].style.visibility = i == s ? 'visible' : 'hidden'; } } addOnloadHook(addCharSubsetMenu); /********************** *** Display options (see [[template:option]]) *** by [[user:ThomasV]] **********************/ //Cookies function SetCookie(name,value) { document.cookie = name + "=" + escape(value); } function GetCookie(name) { var i =0; while (i < document.cookie.length) { if (document.cookie.substr(i,name.length) == name) { var valend = document.cookie.indexOf(";",i+name.length+1); if (valend == -1) { valend = document.cookie.length; } return unescape(document.cookie.substring(i+name.length+1,valend)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) { break; } } } function OptionText() { var indexNavigationBar = 0; // iterate over all < span >-elements until class "OptionText" is found for(var i=0; SpanElem = document.getElementsByTagName("span")[i]; i++) { // if found an option span if (SpanElem.className == "OptionText") { //SpanElem.style.display = 'none'; OptionTitle = SpanElem.title; OptionStyle = SpanElem.firstChild.getAttribute('style'); //check if option was already encountered... if(!document.getElementById(OptionTitle)) { //read cookie var DisplayOptionDefault = true; CookieDisplayOption = GetCookie("Display"+OptionTitle); if (CookieDisplayOption ) { if (CookieDisplayOption == "false") { DisplayOptionDefault = false; } } var PageDisplay = document.createElement("li"); PageDisplay.setAttribute('id', OptionTitle); var PageDisplayLink = document.createElement("a"); OptionText = document.createTextNode("Désactiver "+OptionTitle); PageDisplayLink.appendChild(OptionText); PageDisplayLink.setAttribute('href','javascript:displayOptionText("'+OptionTitle+'","' + OptionStyle +'", '+DisplayOptionDefault+');'); PageDisplay.appendChild(PageDisplayLink); var optlist = document.getElementById("optlist"); if(!optlist) { var displayOptions = document.createElement("div"); displayOptions.style.marginTop = "0.7em"; displayOptions.innerHTML = '<h5>display options<\/h5><div class="pBody"><ul id="optlist"></ul><\/div>'; document.getElementById("p-tb").appendChild(displayOptions); optlist = document.getElementById("optlist"); } optlist.appendChild(PageDisplay); displayOptionText(OptionTitle,OptionStyle,DisplayOptionDefault); } } } } function displayOptionText(optiontitle, optionstyle, bool) { SetCookie ("Display"+optiontitle,bool); var PageDisplayLink = document.getElementById(optiontitle).firstChild;; // iterate over all < span >-elements for(var i=0; SpanElem = document.getElementsByTagName("span")[i]; i++) { // if found an option text if ((SpanElem.className == "OptionText") && (SpanElem.title == optiontitle)) { if(bool==true ) { SpanElem.setAttribute('style',optionstyle); PageDisplayLink.firstChild.data = (optiontitle); PageDisplayLink.setAttribute('href', 'javascript:displayOptionText("'+optiontitle+'","'+optionstyle+'", false);'); } if(bool==false) { SpanElem.setAttribute('style','null'); PageDisplayLink.firstChild.data = (optiontitle); PageDisplayLink.setAttribute('href', 'javascript:displayOptionText("'+optiontitle+'","'+optionstyle+'", true);'); } } } } addOnloadHook(OptionText); /********************** *** Automatically generate page footer from values in {{header}} *** by [[user:GrafZahl]] **********************/ function DisplayFooter() { if(document.getElementById && wgNamespaceNumber==0) { nofooter = document.getElementById('nofooter'); hp = document.getElementById('headerprevious'); hn = document.getElementById('headernext'); content = document.getElementById('bodyContent'); catlinks = document.getElementById('catlinks'); footer = document.createElement('table'); if((!((hp) && (hn) && (content) && (footer))) || (nofooter)) return; footer.setAttribute('class', 'headertemplate'); footer.setAttribute('id', 'footertemplate'); /* Begin footer HTML code */ tr = document.createElement('tr'); td = document.createElement('td'); td.setAttribute('align', 'left'); td.setAttribute('width', '33%'); fp = hp.cloneNode(true); fp.setAttribute('id', 'footerprevious'); td.appendChild(fp); tr.appendChild(td); td = document.createElement('td'); td.setAttribute('align', 'center'); td.setAttribute('width', '34%'); a = document.createElement('a'); a.setAttribute('href', '#top'); text = document.createTextNode('Return to the top of the page.'); a.appendChild(text); td.appendChild(a); tr.appendChild(td); td = document.createElement('td'); td.setAttribute('align', 'right'); td.setAttribute('width', '33%'); fn = hn.cloneNode(true); fn.setAttribute('id', 'footernext'); td.appendChild(fn); tr.appendChild(td); footer.appendChild(tr); /* End footer HTML code */ if(catlinks) // place footer before category box content.insertBefore(footer, catlinks); else content.appendChild(footer); } } addOnloadHook(DisplayFooter); /************* *** Execute JS file in MediaWiki namespace with &usejs parameter on any page *** by [[m:user:Pathoschild]] <http://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Usejs> *************/ document.write('<script type="text/javascript" src="' + 'http://meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Usejs.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); // </nowiki></pre>