User:Doc Taxon II/common.js

var ns = mw.config.get("wgCanonicalNamespace"); if (ns === "") { page = mw.config.get("wgTitle"); } else { page = ns + ":" + mw.config.get("wgTitle"); } var srv   = mw.config.get("wgServer"); var srvla = srv.slice(2, srv.indexOf(".")); var self  = srvla + ": " + page; var iwlist = document.getElementById("p-lang"); // var iwul  = iwlist.getElementsByTagName("ul")[0].innerHTML;

$("a.interlanguage-link-target").each(function(index, element) {     var la  = element.href.slice(8, element.href.indexOf("."));      var pos = element.title.lastIndexOf(" –");      if (pos === -1) {      	 title = element.title;      } else {      	 title = element.title.slice(0, pos);      }      var lenfound = function(data) {      	 var pt =  data.query.pages[data.query.pageids[0]].title;   	     var len = data.query.pages[data.query.pageids[0]].length;   	     window.console.info("Seitenlänge: " + len);         if (len === undefined) len = "<>"; //         alert(element.innerHTML + la + ": " + pt + "\u2066 | " + len + "\u2069");         element.innerHTML = la + ": " + pt + "\u2066 | " + len + "\u2069";      };      var lenfault = function {         window.console.warn("API-Abfrage hat nicht geklappt.");         alert("Fehler");      };      var lenfire = function {      	  var host = document.location.hostname, url = document.location.protocol + "//" + la + host.substr(host.indexOf(".")) + mw.util.wikiScript("api"), or =  document.location.origin; if (or.slice(8, or.indexOf(".")) === la) { prop = {prop: "info", titles: title, indexpageids: true}; } else { prop = {origin: or, prop: "info", titles: title, indexpageids: true}; }  	     new mw.Api.get(prop, {url: url}).done(lenfound).fail(lenfault); };     mw.loader.using(["mediawiki.api", "mediawiki.util"], lenfire); });

var selflenfound = function(data) { var pt = data.query.pages[data.query.pageids[0]].title; var len = data.query.pages[data.query.pageids[0]].length; window.console.info("Seitenlänge: " + len); if (len === undefined) len = "<>"; var prep  = "" + self + "\u2066 | " + len + "\u2069" +""; iwlist.getElementsByTagName("ul")[0].innerHTML = prep + iwlist.getElementsByTagName("ul")[0].innerHTML; //        element.innerHTML = la + ": " + pt + "\u2066 | " + len + "\u2069"; };     var selflenfault = function { window.console.warn("API-Abfrage hat nicht geklappt."); alert("Fehler"); };     var selflenfire = function { var host = document.location.hostname, url = document.location.protocol + "//" + srvla + host.substr(host.indexOf(".")) + mw.util.wikiScript("api"), or =  document.location.origin; prop = {prop: "info", titles: page, indexpageids: true}; new mw.Api.get(prop, {url: url}).done(selflenfound).fail(selflenfault); };     mw.loader.using(["mediawiki.api", "mediawiki.util"], selflenfire);