User:机智的小鱼君/common.js

/** Special:LookupContribs & Special:LookupUser **/ var url = location.href; var urlreg = /\/wiki[^\/]*\/([^\/]+)/; var rootpage = url.match(urlreg) [1]; if (rootpage == 'Special:LookupContribs' || rootpage == 'Special:LookupUser') { $('.page-header__page-subtitle').after(   $('')    .addClass('wds-button wds-is-secondary wds-global-navigation__link-button')    .text('所有链接在新页面打开')    .click(function  { $('#mw-content-text a').attr('target', '_blank'); }) ) }

/** Special:InterLinkEdit **/ if (window.WikiUtil) return; /**    * Constructor for WikiUtil * Use fromURL or fromPartial to fill in the fields * @return {WikiUtil} a generic representation of a wiki */   var WikiUtil = function  { this.lang = ''; this.wiki = ''; this.domain = ''; this.id = '0'; this.switched = false; return this; };   // All allowed languages WikiUtil.languages = ['de', 'en', 'es', 'fr', 'it', 'ja', 'pl', 'pt-br', 'ru', 'zh', 'zh-tw', 'aa', 'ab', 'ace', 'af', 'ak', 'aln', 'am', 'anp', 'ar', 'arc', 'arn', 'ary', 'arz', 'as', 'av', 'avk', 'ay', 'az', 'ba', 'bat-smg', 'bcc', 'bcl', 'be', 'be-tarask', 'be-x-old', 'bg', 'bh', 'bho', 'bi', 'bjn', 'bm', 'bn', 'bo', 'bpy', 'bqi', 'br', 'brh', 'bs', 'bug', 'bxr', 'ca', 'cbk-zam', 'cdo', 'ce', 'ceb', 'ch', 'cho', 'chr', 'chy', 'ckb', 'co', 'cps', 'cr', 'crh', 'crh-cyrl', 'crh-latn', 'cs', 'csb', 'cu', 'cv', 'cy', 'da', 'de', 'diq', 'dsb', 'dtp', 'dv', 'dz', 'ee', 'el', 'eml', 'en', 'eo', 'es', 'et', 'eu', 'ext', 'fa', 'ff', 'fi', 'fiu-vro', 'fj', 'fo', 'fr', 'frp', 'frr', 'fur', 'fy', 'ga', 'gag', 'gan', 'gan-hans', 'gan-hant', 'gd', 'gl', 'glk', 'gn', 'got', 'grc', 'gsw', 'gu', 'gv', 'ha', 'hak', 'haw', 'he', 'hi', 'hif', 'hif-latn', 'hil', 'ho', 'hr', 'hsb', 'ht', 'hu', 'hy', 'hz', 'id', 'ig', 'ii', 'ik', 'ike-cans', 'ike-latn', 'ilo', 'inh', 'io', 'is', 'it', 'iu', 'ja', 'jam', 'jbo', 'jut', 'jv', 'ka', 'kaa', 'kab', 'kbd', 'kbd-cyrl', 'kg', 'khw', 'ki', 'kiu', 'kj', 'kk', 'kk-arab', 'kk-cn', 'kk-cyrl', 'kk-kz', 'kk-latn', 'kk-tr', 'kl', 'km', 'kn', 'ko', 'ko-kp', 'koi', 'kr', 'krc', 'kri', 'krj', 'ks', 'ks-arab', 'ks-deva', 'ku', 'ku-arab', 'ku-latn', 'kv', 'kw', 'ky', 'la', 'lad', 'lb', 'lbe', 'lez', 'lfn', 'lg', 'li', 'lij', 'liv', 'lmo', 'ln', 'lo', 'loz', 'lt', 'ltg', 'lv', 'lzh', 'lzz', 'mai', 'map-bms', 'mdf', 'mg', 'mh', 'mhr', 'mi', 'min', 'mk', 'ml', 'mn', 'mo', 'mr', 'mrj', 'ms', 'mt', 'mus', 'my', 'myv', 'mzn', 'na', 'nah', 'nan', 'nap', 'ne', 'new', 'ng', 'niu', 'nl', 'nl-informal', 'nn', 'no', 'nov', 'nrm', 'nso', 'nv', 'ny', 'oc', 'om', 'or', 'os', 'pa', 'pag', 'pam', 'pap', 'pcd', 'pi', 'pih', 'pl', 'pms', 'pnb', 'pnt', 'prg', 'ps', 'pt', 'pt-br', 'qu', 'qug', 'rgn', 'rif', 'rm', 'rmy', 'rn', 'ro', 'roa-rup', 'roa-tara', 'ru', 'rue', 'rup', 'ruq', 'ruq-cyrl', 'ruq-latn', 'rw', 'sa', 'sah', 'sc', 'scn', 'sco', 'sd', 'sdc', 'se', 'sei', 'sg', 'sgs', 'sh', 'shi', 'shi-latn', 'shi-tfng', 'si', 'sk', 'sl', 'sli', 'sm', 'sma', 'sn', 'so', 'sq', 'sr', 'sr-ec', 'sr-el', 'srn', 'ss', 'st', 'stq', 'su', 'sv', 'sw', 'szl', 'ta', 'tcy', 'te', 'tet', 'tg', 'tg-cyrl', 'tg-latn', 'th', 'ti', 'tk', 'tl', 'tly', 'tn', 'to', 'tpi', 'tr', 'ts', 'tt', 'tt-cyrl', 'tt-latn', 'tum', 'tw', 'ty', 'tyv', 'udm', 'ug', 'ug-arab', 'ug-latn', 'uk', 'ur', 'uz', 'val', 've', 'vec', 'vep', 'vi', 'vls', 'vmf', 'vo', 'vot', 'vro', 'wa', 'war', 'wo', 'wuu', 'xal', 'xh', 'xmf', 'yi', 'yo', 'yue', 'za', 'zea', 'zh', 'zh-hk', 'zh-tw', 'zu']; WikiUtil.shortURLs = { 'c': 'community', 'a': 'answers', 'rs': 'runescape', 'osrs': 'oldschoolrunescape' };   WikiUtil.defaultDomain = 'fandom'; /**    * Trims a URL of various parts * @param {String} url a wikia.com or fandom.com URL * @returns {String} a cleaned up URL */   WikiUtil._trimURL = function (url) { // Clean up leading/trailing spaces url = url.replace(/(^\s*|\s*$)/g, ''); // Remove http/s url = url.replace(/(https?:)?\/\//g, ''); // Add a / at the end url = url.replace(/$/g, '/').replace(/\/+$/g, '/'); return url; };   /**     * Split URL into components * @param {String} url a wikia.com or fandom.com URL, e.g. https://witcher.fandom.com/es * @return {WikiUtil} the updated WikiUtil */   WikiUtil.prototype.fromURL = function (url) { url = WikiUtil._trimURL(url); url = url.toLowerCase; this.lang = ''; this.wiki = url; this.domain = WikiUtil.defaultDomain; if (url.match(/fandom\.com/g)) { this.domain = 'fandom'; // Grab .fandom.com/ var fcomponents = url.match(/^([^\.]*)\.fandom\.com\/([^\/]*)\/{0,1}.*/i); if (fcomponents) { this.wiki = fcomponents[1]; if (WikiUtil.languages.indexOf(fcomponents[2]) > -1) { this.lang = fcomponents[2]; }           }        }        else if (url.match(/wikia\.org/g)) { this.domain = 'org'; // Grab .wikia.org/ var ocomponents = url.match(/^([^\.]*)\.wikia\.org\/([^\/]*)\/{0,1}.*/i); if (ocomponents) { this.wiki = ocomponents[1]; if (WikiUtil.languages.indexOf(ocomponents[2]) > -1) { this.lang = ocomponents[2]; }           }        }        else if (url.match(/wikia\.com/g)) { this.domain = 'wikia'; // Grab. .wikia.com var wcomponents = url.match(/^([^\.]*?)\.*([^\.]*)\.wikia\.com.*/i); if (wcomponents) { this.wiki = wcomponents[2]; if (WikiUtil.languages.indexOf(wcomponents[1]) > -1) { this.lang = wcomponents[1]; }           }        }        // Short URLs cause redirect problems, deal with these with hardcoded values if (WikiUtil.shortURLs[this.wiki]) { this.wiki = WikiUtil.shortURLs[this.wiki]; }       return this; };   /**     * Split a partial and domain into components * @param {String} partial, a standard-style wikiname, e.g. es.community * @param {String} domain, 'wikia' or 'fandom' * @return {WikiUtil} the updated WikiUtil */   WikiUtil.prototype.fromPartial = function (partial, domain) { partial = partial.toLowerCase; if (!domain) domain = WikiUtil.defaultDomain; domain = domain.toLowerCase; this.lang = ''; this.wiki = partial; this.domain = domain; if (['wikia', 'fandom', 'org'].indexOf(domain) < 0) { this.domain = 'wikia'; }       // If it has a. between at least one character, separate out lang var pcomponents = partial.match(/^(.+)\.(.+)$/i); if (pcomponents) { if (WikiUtil.languages.indexOf(pcomponents[1]) > -1) { this.lang = pcomponents[1]; }           this.wiki = pcomponents[2]; }       // Short URLs cause redirect problems, deal with these with hardcoded values if (WikiUtil.shortURLs[this.wiki]) { this.wiki = WikiUtil.shortURLs[this.wiki]; }       return this; };   /**     * Decide whether to process URL/partial, and split into components * @param {String} input a URL or partial * @param {String} domain optional/if applicable, a wikia domain category * @return {WikiUtil} the updated WikiUtil */   WikiUtil.prototype.fromUnknown = function (input, domain) { input = input.toLowerCase; if (domain) { domain = domain.toLowerCase; }       if (input.match(/\.(wikia|fandom)\.(org|com)/i)) { // Assume the input is a URL this.fromURL(input); if (domain) this.domain = domain; } else { // Assume the input is a partial this.fromPartial(input, domain); }       return this; };   /**     * Combine components into a standardised wiki URL * @return {String} a base URL for the wiki */   WikiUtil.prototype.toURL = function  { if (this.domain === 'fandom') { if (this.lang === '') { return 'https://' + this.wiki + '.fandom.com/'; }           return 'https://' + this.wiki + '.fandom.com/' + this.lang + '/'; }       else if (this.domain === 'org') { if (this.lang === '') { return 'https://' + this.wiki + '.wikia.org/'; }           return 'https://' + this.wiki + '.wikia.org/' + this.lang + '/'; }       else { if (this.lang === '') { return 'https://' + this.wiki + '.wikia.com/'; }           return 'http://' + this.lang + '.' + this.wiki + '.wikia.com/'; }   };    /**     * Combine components into a short form wiki URL for display * @return {String} a display URL for the wiki */   WikiUtil.prototype.toDisplayURL = function  { if (this.domain === 'fandom') { if (this.lang === '') { return this.wiki + '.fandom.com'; }           return this.wiki + '.fandom.com/' + this.lang; }       else if (this.domain === 'org') { if (this.lang === '') { return this.wiki + '.wikia.org'; }           return this.wiki + '.wikia.org/' + this.lang; }       else { if (this.lang === '') { return this.wiki + '.wikia.com'; }           return this.lang + '.' + this.wiki + '.wikia.com'; }   };    /**     * Returns the wiki's partial * @return {String} the wiki's partial, e.g. ru.community */   WikiUtil.prototype.toPartial = function  { if (this.lang === '') { return this.wiki; }       return this.lang + '.' + this.wiki; };   /**     * Return script path * @return {String} an api.php URL for the wiki */   WikiUtil.prototype.toScriptPath = function  { return this.toURL + 'api.php'; };   /**     * Check if a wiki exists and returns wiki data * Automatically checks if the equivalent wikia.com/fandom.com wiki exists * If such a wiki exists, 'switched' becomes true and 'id' is updated * @return {Deferred} containing data containing wiki id, wiki name and other information, null otherwise */   WikiUtil.prototype.getWikiData = function  { var self = this; // http://www.wikia.com/wikia.php?controller=WikisApi&method=getByString&lang=en&string=runescape.&includeDomain=1&limit=200 return $.ajax({           url: 'https://community.wikia.com/wikia.php',            type: 'GET',            data: {                controller: 'WikisApi',                method: 'getByString',                    lang: self.lang ===  ? 'en' : self.lang,                string: self.wiki + '.',                includeDomain: 1,                limit: 200            },            dataType: 'json'        }).then(function (data) {            if (data.total === 0) {                return null;            }            var rewikia = new RegExp('^' + self.lang + '\\.' + self.wiki + '\\.wikia\\.com$');            var refandom = new RegExp('^' + self.wiki + '\\.' + 'fandom\\.com\\/' + self.lang + '$');            var reorg = new RegExp('^' + self.wiki + '\\.' + 'wikia\\.org\\/' + self.lang + '$');            if (self.lang === ) {                rewikia = new RegExp('^' + self.wiki + '\\.wikia\\.com$'); refandom = new RegExp('^' + self.wiki + '\\.' + 'fandom\\.com$'); reorg = new RegExp('^' + self.wiki + '\\.' + 'wikia\\.org$'); }           var foundWiki = null; data.items.forEach(function (wiki) {               if (wiki.domain.match(rewikia)) {                    self.id = wiki.id;                    foundWiki = wiki;                    if (self.domain !== 'wikia') {                        console.warn('WikiUtil: Using the domain "wikia", instead of ' + self.toURL);                        self.domain = 'wikia';                        self.switched = true;                    }                }                else if (wiki.domain.match(reorg)) {                    self.id = wiki.id;                    foundWiki = wiki;                    if (self.domain !== 'org') {                        console.warn('WikiUtil: Using the domain "wikia.org", instead of ' + self.toURL);                        self.domain = 'org';                        self.switched = true;                    }                }                else if (wiki.domain.match(refandom)) { self.id = wiki.id; foundWiki = wiki; if (self.domain !== 'fandom') { console.warn('WikiUtil: Using the domain "fandom", instead of ' + self.toURL); self.domain = 'fandom'; self.switched = true; }               }            });            return foundWiki;        }); };   window.WikiUtil = WikiUtil; mw.hook('vstf.wikiutil').fire(window.WikiUtil); })(window, jQuery); /* Multiple Interwiki links - by Monchoman45 */ window.InterwikiEdit = {   buffer: true,    threads: 10,    running: 0,    ids: [],    queue: [] }; InterwikiEdit.onload = function  {    if (wgCanonicalSpecialPageName == 'InterwikiEdit' && !mw.util.getParamValue('action')) {        mw.hook('vstf.wikiutil').add(function { var gui = document.createElement('div'); gui.innerHTML = 'Multiple List each domain (eg. ), one on each line. This will link each specified wiki to every other specified wiki.    '; document.getElementById('mw-content-text').appendChild(gui); });   } }; $(InterwikiEdit.onload); InterwikiEdit.getWikiData = function (wiki) {    // Create WikiUtils for them    var wikiutil;    if (wiki.match(/wikia\.com/) || wiki.match(/fandom\.com/) || wiki.match(/wikia\.org/)) {        wikiutil = new WikiUtil.fromURL(wiki);    } else {        wikiutil = new WikiUtil.fromPartial(wiki, 'wikia');    }    // Find the wiki ID    return wikiutil.getWikiData; }; InterwikiEdit.linkAll = function (wikis) {    InterwikiEdit.ids = [];    var promises = [];    for (var i = 0; i < wikis.length; i++) {        promises.push(InterwikiEdit.getWikiData(wikis[i]).then(function(data) {            InterwikiEdit.ids.push(data);        }));    }    $.when.apply($, promises).then(function { var numberFailed = InterwikiEdit.ids.length; InterwikiEdit.ids = InterwikiEdit.ids.filter(function(el) {           return el != null;        }); numberFailed = numberFailed - InterwikiEdit.ids.length; if (numberFailed > 0) { $('#interwiki-multiple-button').after(' Error, ' + numberFailed + ' wikis failed to be found. '); }       $('#interwiki-multiple-button').after(' '); $('#interwiki-successfulwikis').append(' ID  Domain  Language  '); for (var i = 0; i < InterwikiEdit.ids.length; i++) { var wiki = InterwikiEdit.ids[i]; $('#interwiki-successfulwikis').append(' ' + wiki.id + '  ' + wiki.domain + '  ' + wiki.language + '  '); }       for (var i = 0; i < InterwikiEdit.ids.length - 1; i++) { for (var j = i + 1; j < InterwikiEdit.ids.length; j++) { var wiki1 = InterwikiEdit.ids[i]; var wiki2 = InterwikiEdit.ids[j]; if (wiki1.id != wiki2.id) { if (!InterwikiEdit.buffer || InterwikiEdit.running < InterwikiEdit.threads) { InterwikiEdit.link(wiki1.id, wiki2.id, wiki1.domain, wiki2.domain, InterwikiEdit.linkAllCallback); InterwikiEdit.running++; } else { InterwikiEdit.queue.push([wiki1.id, wiki2.id, wiki1.domain, wiki2.domain]); }               } else { console.log(i + ' == ' + j); }           }        }    }); }; InterwikiEdit.link = function (wikiid1, wikiid2, wiki1, wiki2, callback) {    if (!wikiid1 || !wikiid2) {        return false;    }    var get = new XMLHttpRequest;    var url = '/wiki/Special:InterwikiEdit?action=Link&wikia_id=' + wikiid1 + '&ext_wikia_id=' + wikiid2 + '&useskin=wikia';    get.open('GET', url, true);    get.onreadystatechange = function  {        if (this.readyState == 4 && this.status == 200) {            var html = document.createElement('html');            html.innerHTML = this.responseText;            var form = html.getElementsByTagName('form');            for (var i = 0; i < form.length; i++) {                if (form[i].id == 'chooseaction') {                    form = form[i];                    break;                }            }            var post = new XMLHttpRequest;            post.open('POST', url, true); post.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); post.onreadystatechange = function { if (this.readyState == 4 && this.status == 200 && typeof callback == 'function') { callback.call(this, wiki1, wiki2); }           };            post.send('action=commit_link&wikia_id=' + form['wikia_id'].value + '&ext_wikia_id=' + form['ext_wikia_id'].value); }   };    get.send; return get; }; InterwikiEdit.linkAllCallback = function (wiki1, wiki2) { var output = document.getElementById('interwiki-multiple-output'); var scroll = false; if (output) { if (output.offsetHeight + output.scrollTop >= output.scrollHeight) { scroll = true; }       output.innerHTML += wiki1 + ' >=< ' + wiki2 + '\n'; }   if (InterwikiEdit.queue.length > 0) { var nextwikidata = InterwikiEdit.queue.shift; InterwikiEdit.link(nextwikidata[0], nextwikidata[1], nextwikidata[2], nextwikidata[3], InterwikiEdit.linkAllCallback); } else { InterwikiEdit.running--; if (InterwikiEdit.running == 0 && output) { output.innerHTML += '-\n'; }   }    if (scroll) { output.scrollTop = output.scrollHeight; } };
 * (function (window, $) {