User:Aaron Liu/AutowIll.js
Appearance
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. |
Documentation for this user script can be added at User:Aaron Liu/AutowIll. |
/**
* This script is an indepedently-usable AutoEd module. If you already have AutoEd installed, please see [[Wikipedia:AutoEd/Customization]] for how to load this module. If you don't have AutoEd installed, then you don't need to do anything; just install this script the normal way.
* Known false positive occurs when interlanguage link is placed after a template invocation within a citation template. Make sure this does not happen by checking the page preview for errors.
*/
function autoEdwIll( str ) {
str = str.replace( /\[https?:\/\/([^\.]*)\.(?:m\.)?wikipedia\.org\/wiki\/(\S*)(?:\s*([^\]]*)])/g, ( match, p1, p2, p3 ) => {
if ( p3 === undefined ) {
return `[[:${ p1 }:${ p2 }]]`;
}
return `[[:${ p1 }:${ p2 }|${ p3 }]]`;
} );
str = str.replace( /(?<!{{\s*cit[^}]*)\[\[:(.*?):([^|\]]*)(?:\|([^\]]*))?]]/g, ( match, p1, p2, p3 ) => {
if ( p3 === undefined ) {
return `{{ill|${ p2 }|${ p1 }}}`;
}
return `{{ill|${ p3 }|${ p1 }|${ p2 }}}`;
} );
return str;
}
$.when( $.ready ).then( () => {
if ( importScript( 'Wikipedia:AutoEd/core.js' ) ) { // if not otherwise using AutoEd
console.log( 'imported' );
window.autoEdFunctions = function () {
const $box = $( '#wpTextbox1' );
const str = $box.textSelection('getContents');
const newstr = autoEdwIll( str );
if ( newstr !== str ) { // don't confuse or tag if no fixes
$box.textSelection('setContents', newstr);
} else {
autoEdTag = '';
autoEdClick = false;
mw.notify( 'No changes needed!' );
}
};
autoEdMinor = false;
autoEdLinkName = 'AutowIll';
autoEdLinkHover = 'Automatically wikify and template straightforward foreign-language links';
autoEdTag = 'converted foreign-language links to use {{ill}} with [[User:Aaron Liu/AutowIll.js]]';
}
} );