Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* Determine whether or not the current article has a redirect from its URL pointing to it */functionsetup(){// If we're not reading an article, do nothingif(!(mw.config.get("wgAction")==="view"&&mw.config.get("wgIsArticle")&&mw.config.get("wgRevisionId")===mw.config.get("wgCurRevisionId")&&mw.config.get("wgPageName")!=="Main_Page")){return;}getWikidata();}// First try to get the official site off WikidatafunctiongetWikidata(){varwikidataId=mw.config.get('wgWikibaseItemId');if(wikidataId===null){return;}// API docs: https://www.wikidata.org/w/api.php?action=help&modules=wbgetclaimsvarurl;$.ajax({url:"https://www.wikidata.org/w/api.php",data:{action:"wbgetclaims",entity:wikidataId,property:"P856",languages:"en",format:"json",origin:"*"},success:function(response){if(typeofresponse.claims.P856!="undefined"){wikidataUrl=response.claims.P856[0].mainsnak.datavalue.value;console.log("domainRedirect.js: Found Url via wikidata: "+wikidataUrl);getRedirects(wikidataUrl);}else{console.log("domainRedirect.js: Wikidata failed");getInfobox();}}});}// Then try getting a website in the infoboxfunctiongetInfobox(){varinfoboxUrl;$(".infobox tr").each(function(){if($(this).children("th").text()=="Website"){infoboxUrl=$(this).children("td").children("a").attr("href");returnfalse;}});if(infoboxUrl){console.log("domainRedirect.js: Found Url via infobox: "+infoboxUrl);getRedirects(infoboxUrl);}else{console.log("domainRedirect.js: Infobox failed");getExternals();}}// Finally, try to get it from the external linksfunctiongetExternals(){// First try getting {{official website}}varofficialUrl=$(".official-website a").attr("href");if(officialUrl){console.log("domainRedirect.js: Found Url via {{official site}}: "+officialUrl);getRedirects(officialUrl);}else{console.log("domainRedirect.js: No official site");console.log("domainRedirect.js: No candidates found");}// Then try the external links section and grab the first link we find/* var externalUrl = $("h2").has("#External_links").nextUntil("h2").find("li a.external").first().attr("href"); if (externalUrl) { console.log("domainRedirect.js: Found Url via External links section: " + externalUrl); getRedirects(externalUrl); } else { console.log("domainRedirect.js: No external links list found"); } */}functiongetRedirects(candidateUrl){// API docs: https://www.mediawiki.org/wiki/API:Redirects$.ajax({url:"https://en.wikipedia.org/w/api.php",data:{action:"query",prop:"redirects",format:"json",titles:mw.config.get("wgPageName"),rdprop:"title",rdshow:"!fragment",rdlimit:"max"},success:function(response){varpageId=mw.config.get("wgArticleId");varredirectObject=response.query.pages[pageId];if(typeofredirectObject.redirects!="undefined"){redirects=redirectObject.redirects;checkRedirectExistence(redirects,candidateUrl);}else{console.log("domainRedirect.js: No inbound redirects");displayCandidate(candidateUrl);}}});}functioncheckRedirectExistence(redirects,candidateUrl){for(varrofredirects){vartitle=r.title;if(!/\./.test(title)){continue;}console.log("domainRedirect.js: Looking for "+title+" in "+candidateUrl);vartitleEscaped=mw.RegExp.escape(title);varre=newRegExp(titleEscaped,"i");if(re.test(candidateUrl)){console.log("domainRedirect.js: Domain redirect present: "+title);return;}}displayCandidate(candidateUrl);}functiondisplayCandidate(candidateUrl){varparser=newURL(candidateUrl);candidateDomain=parser.hostname;console.log("domainRedirect.js: Proposing redirect for Domain: "+candidateDomain);$("#contentSub").after("<span class='mw-redirectedfrom'> (Possible ___domain redirect: "+candidateDomain+")</span>");}$(setup);