Content deleted Content added
Opencooper (talk | contribs) tweak |
Opencooper (talk | contribs) m remove space from click target |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1:
/
// License: CC0
// FIXME: isn't case insensitive; see [[The Psycho Ex-Wife]]
// FIXME: Doesn't work with TLDs like .co.uk
function setup() {
Line 6 ⟶ 11:
&& mw.config.get("wgIsArticle")
&& !___location.search.split('oldid=')[1]
&& !mw.config.get("
}▼
// Make sure we have somewhere to put result
if (!$("#contentSub").length) {
return;
}
Line 36 ⟶ 46:
if (typeof response.claims.P856 != "undefined") {
wikidataUrl = response.claims.P856[0].mainsnak.datavalue.value;
retrievalMethod = "
} else {
// console.log("domainRedirect.js: Wikidata failed");
Line 54 ⟶ 64:
if (infoboxUrl) {
retrievalMethod = "{{Url}}";
return;
} else {
}
Line 70 ⟶ 80:
if (infoboxUrl) {
retrievalMethod = "website=";
} else {
// console.log("domainRedirect.js: Infobox website= failed");
Line 82 ⟶ 92:
var officialUrl = $(".official-website a").first().attr("href");
if (officialUrl) {
return;
} else {
Line 90 ⟶ 100:
// Then try the external links section and the first link that says official
var externalUrl = $("h2").has("#External_links").nextUntil("h2")
.find("li a.external").first(); if (externalUrl && /Official/i.test(externalUrl.text())) {
} else {
// console.log("domainRedirect.js: No external links list found");
Line 101 ⟶ 112:
}
function
// API docs: https://www.mediawiki.org/wiki/API:Redirects▼
candidateDomain = candidateDomain.replace(/^w+\d*\./, ""); // get rid of www
var apiUrl = ___location.origin + "/w/api.php";
$.ajax({
url:
data: {
action: "query",
prop: "redirects",▼
format: "json",
titles:
rdprop: "title",▼
rdshow: "!fragment",▼
rdlimit: "max"▼
},
success: function(response) {
// console.log("domainRedirect.js: No inbound redirects");▼
displayCandidate(candidateUrl);
}
}
Line 128 ⟶ 138:
}
function
▲ }
▲ return;
▲ }
▲ displayCandidate(candidateUrl);
}▼
▲ var pageTitle = mw.config.get("wgPageName").replace(/_/g, " ");
var parser = new URL(candidateUrl);
var candidateDomain = parser.hostname;
candidateDomain = candidateDomain.replace(/^w+\d*\./, ""); // get rid of www
var domainType = "___domain";
if (candidateDomain.split(".").length-1 >= 2) {
domainType = "subdomain";
} else if (parser.pathname != "/") {
domainType = "subpage";
if (domainType != "___domain") {
console.info("domainRedirect.js: Ignoring " + domainType + " redirect: "
+ candidateDomain);
$("#domainRedirect").hide();
▲ }
+ candidateDomain + "&action=edit";
var editSummary = "Create redirect (using "
+ "[[User:Opencooper/domainRedirect|domainRedirect.js]])";
var editSummaryEncoded = encodeURIComponent(editSummary);
+ pageTitle + "&summary=" + editSummaryEncoded;
var domainMarkup = "<a title='via " + retrievalMethod + "' href='"
var candidateText = "Possible " + domainType + " redirect: " + domainMarkup;
var visitLink = "";
if (candidateUrl.replace(/\/$/, "") != parser.origin) {
visitLink = " <a href='" + candidateUrl + "' title='Visit Original Link'>"
}
$("#domainRedirect").append(" (" + candidateText + createLink
▲ var createUrl = "https://en.wikipedia.org/w/index.php?title=" + candidateDomain + "&action=edit";
▲ var preload = "&preload=User:Opencooper/domainRedirectPreloads.js&preloadparams[]=" + pageTitle
▲ var createLink = "<a href='" + createUrl + preload + "' title='via "
▲ + retrievalMethod + ": " + candidateUrl + "'>"
▲ + candidateDomain + "</a>";
▲ $("#contentSub").append("<span class='mw-redirectedfrom' id='domainRedirect'>"
▲ + " (Possible ___domain redirect: "
▲ + createLink + ")</span>");
}
|