User:Erutuon/common.js: Difference between revisions
Appearance
Content deleted Content added
load scripts conditionally |
|||
Line 192: | Line 192: | ||
} |
} |
||
if ([ "edit", "submit" ].includes(mw.config.get("wgPageAction"))) { |
|||
⚫ | |||
importScript('User:Erutuon/scripts/ |
importScript('User:Erutuon/scripts/charinsert-names.js'); |
||
⚫ | |||
} |
Revision as of 09:04, 9 February 2019
// <nowiki>
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
pathoschild.TemplateScript.add([
// add your own templates or scripts here
{
name: 'proto wikt-lang',
enabled: false,
script: function(editor) {
editor
.replace(/'*\*?\[\[:?wikt:Reconstruction:Proto-Germanic\/([^\|\]]+)\|\*?([^\]]+)\]\]'*/g, '{{wikt-lang|gem-pro|*$2}}')
.replace(/'*\*?\[\[:?wikt:Reconstruction:Proto-Indo-European\/([^\|\]]+)\|\*?([^\]]+)\]\]'*/g, '{{wikt-lang|ine-pro|*$2}}')
.replace(/'*\*?\[\[:?wikt:Reconstruction:Proto-Hellenic\/([^\|\]]+)\|\*?([^\]]+)\]\]'*/g, '{{wikt-lang|grk-pro|*$2}}')
.replace(/'*\*?\[\[:?wikt:Reconstruction:Proto-Slavic\/([^\|\]]+)\|\*?([^\]]+)\]\]'*/g, '{{wikt-lang|sla-pro|*$2}}')
.appendEditSummary('simplified links to Wiktionary with [[Template:wikt-lang]]');
},
},
{
name: 'fix refs',
enabled: false,
script: function(editor) {
editor
.replace(/(<ref[^\w\s\"]*\>[^<>]*<\/ref\>)([\.\,\;\:\)]{1,3})/g, '$2$1') // Move refs after 1-3 punctuation characters.
.replace(/(\{\{[s|r?e]fn[^\}]+\}\})([\.\,\;\:\)]{1,3})/g, '$2$1') // Move refn and efn templates after 1-3 punctuation characters.
.replace(/(\{\{[Cc]itation needed[^\}]+\}\})([\.,;:\)]{1,3})/g, '$2$1'); // Move citation needed templates after 1-3 punctuation characters.
}
},
{
name: 'tag Amharic',
category: 'formatting',
enabled: false,
isMinorEdit: true,
script: function(editor) {
editor
.replace(/([ሀ-᎙ⶀ-ⷞꬁ-ꬮ]+)(?=[\s\)\;\:\.\,\!\|<\'])/g, '{{lang|am|$1}}')
.appendEditSummary('tag Amharic text with the help of [[m:TemplateScript|TemplateScript]]');
}
},
{
name: 'add IPA template',
category: 'formatting',
enabled: false,
script: function(editor) {
editor
.replaceSelection(function (selected) {
return selected
.replace(/(\/[^\/]+\/)/g, '{{IPA|$1}}')
.replace(/(\[[^\]]+\])/g, '{{IPA|$1}}');
})
.appendEditSummary('added IPA template with the help of [[m:TemplateScript|TemplateScript]]');
},
},
{
name: 'IPA link template cleanup',
category: 'formatting',
enabled: false,
script: function(editor) {
editor
.replace(/\/\{\{IPA ?link\|([^\}]+)\}\}\//g, '{{IPAslink|$1}}')
.replace(/\[\{\{IPA ?link\|([^\}]+)\}\}\]/g, '{{IPAblink|$1}}');
}
},
{
name: 'tag Armenian',
category: 'formatting',
isMinorEdit: true,
enabled: false,
script: function(editor) {
editor
.replace(/([Ա-֏ﬓ-ﬗ]+)(?=[\s\)\;\:\.\,\!\|<\'])/g, '{{lang|hy|$1}}')
.replace(/\}\}(\'+)\{\{lang\|hy\|/g, '$1')
.replace(/(\'+)(\{\{lang\|hy\|)/g, '$2$1')
.appendEditSummary('tag Armenian text with the help of [[m:TemplateScript|TemplateScript]]');
}
},
]);
});
// [[User:Erutuon/ScriptInstaller.js]]
mw.loader.load( "//en.wiktionary.org/enwiki/w/index.php?title=User:Erutuon/ScriptInstaller.js&action=raw&ctype=text/javascript" );
// Add or modify CharInsert entries
window.charinsertCustom = {
"Latin": ' ꟾ {{lang|la|+}} {{wikt-lang|la|+}}',
"Arabic": ' {{lang|ar|+}} {{wikt-lang|ar|+}}',
"Cyrillic": ' {{lang|ru|+}} {{wikt-lang|ru|+}} {{lang|orv|+}} {{lang|cu|+}} {{lang|uk|+}} {{lang|be|+}}',
"Greek": ' {{wikt-lang|grc|+}}',
"IPA": ' ◌ {{IPA|{{subst:x2i|+}}}}',
"Templates": ' {{lang|ang|+}} {{IPA|+}} {{lang|zh|+}}',
};
// </nowiki>
window.simplePopups = false;
importScript('User:PleaseStand/userinfo.js'); //Linkback: [[User:PleaseStand/userinfo.js]] Added by Script installer
importScript('User:Kephir/gadgets/jssand.js'); //Linkback: [[User:Kephir/gadgets/jssand.js]]
mw.loader.load('//en.wikipedia.org/enwiki/w/index.php?title=User%3ATheopolisme%2FScripts%2Fautocompleter.js&action=raw&ctype=text/javascript'); // [[User:Theopolisme/Scripts/autocompleter.js]]
importScript('User:Epicgenius/stubtag.js'); // Backlink: [[User:Epicgenius/stubtag.js]]
importScript('User:Gary/subjects age from year.js'); // [[User:Gary/subjects age from year.js]]
importScript('User:Σ/Testing facility/Archiver.js'); // Backlink: [[User:Σ/Testing facility/Archiver]]
/*
If text with the language attribute "grc" (Ancient and Medieval Greek) contains
non-Greek scripts, marks it with the class "error".
*/
/* globals $ */
const LatnToGrek = {
'E': 'Ε', 'M': 'Μ', 'v': 'ν', 'o': 'ο', 'ó': 'ό', 'ò': 'ὸ',
};
$.getScript(
"//en.wikipedia.org/enwiki/w/index.php?action=raw&title=User:Erutuon/scripts/scriptRecognition.js&ctype=text/javascript&smaxage=21600&maxage=86400",
function () {
const countScripts = window.countSignificantScripts;
const fixGreek = function(str) {
return str.replace(/./g, function(char) {
return LatnToGrek[char] || char;
});
};
$("[lang=grc]").addClass(
function() {
const innerHTML = this.innerHTML;
for (const script in countScripts(innerHTML.replace(/<\/?[^>]+>/g, ""))) {
if (script !== "Grek") {
console.log("Non-Latin script " + script + " in "
+ innerHTML + " (corrected: " + fixGreek(innerHTML) + ").");
return "error";
}
}
});
});
// </nowiki>
if (mw.config.get("wgCanonicalNamespace") === ""
&& [ "edit", "submit" ].includes(mw.config.get("wgAction"))) {
importScript('User:Uglemat/RefMan.js'); // Backlink: [[User:Uglemat/RefMan.js]]
// importScript('User:Erutuon/scripts/cleanup.js'); // Backlink: [[User:Erutuon/scripts/cleanup.js]]
}
function importWiktionaryScript(pageName) {
return mw.loader.load("//en.wiktionary.org/enwiki/w/index.php?title=" + pageName
+ "&action=raw&ctype=text/javascript");
}
window.withWiktionaryScript = function (pageName, successCallback, failureCallback) {
return $.getScript('//en.wiktionary.org/enwiki/w/index.php?title=' + pageName
+ '&action=raw&ctype=text/javascript')
.done(successCallback)
.fail(failureCallback);
};
if ([ "css", "javascript", "Scribunto" ].includes(mw.config.get("wgPageContentModel")))
mw.loader.using("mediawiki.util").done(function () {
importWiktionaryScript("MediaWiki:Gadget-CodeLinks.js");
});
if (mw.config.get("wgPageName") === "MediaWiki:Gadgets-definition")
importWiktionaryScript("User:Erutuon/scripts/gadgets-definition.js");
if ([ 'edit', 'submit' ].includes(mw.config.get("wgAction"))) {
var addApiResultToTextbox = function (funcName) {
return function (str) {
return withWiktionaryScript('User:Erutuon/scripts/apiWrapper.js', function () {
if (!(funcName in apiWrapper))
throw new Error("Function " + funcName + " not in apiWrapper");
apiWrapper[funcName](str, function (result) {
var $textbox = $('#wpTextbox1');
try { // avoid error: currSelection is undefined
$textbox.textSelection('replaceSelection', result);
} catch (e) {
$textbox.textSelection('setContents', result);
}
});
});
};
};
// Insert expanded wikitext into the text box, as if from
// [[Special:ExpandTemplates]].
window.insertExpandedTemplate = addApiResultToTextbox('expandTemplates');
// Replace selection in text box with the wikitext of a page.
window.insertWikitext = addApiResultToTextbox('getWikitext');
}
if ([ "edit", "submit" ].includes(mw.config.get("wgPageAction"))) {
importScript('User:Erutuon/scripts/charinsert-names.js');
importScript('User:Erutuon/scripts/cleanup.js');
}