User:MSK/rdp.js
Appearance
< User:MSK
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.
This code will be executed when previewing this page.
This user script seems to have a documentation page at User:MSK/rdp.
// {{Wikipedia:USync|repo=https://github.com/potatolover68/pillbug|ref=refs/heads/rdp|path=index.js}}
/*! pillbug - GPL-3.0-or-later - https://github.com/potatolover68/pillbug */
(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return typeof e==`object`&&!!e&&typeof e.getNamespaceId==`function`&&typeof e.getPrefixedDb==`function`}function n(e){if(typeof e==`string`)return e;if(t(e))return e.getPrefixedText();throw Error(`Expected string or wiki/title`)}function r(e,t){let n=RegExp(`^${t}\\s*:\\s*`,`i`);return e.replace(n,``).trim()}function i(e){return r(n(e).replace(/_/g,` `).trim(),`Template`)}function a(e){return e.replace(/_/g,` `).trim().toLowerCase()}function o(e){return e instanceof Error&&e.name===`AbortError`}var s=null,c=null;function l(e){s=e}function u(e){c=e}function ee(e){if(!s)throw Error(`Page fetch is not available (app bridge not installed)`);return s(e)}async function te(e,t){if(t?.aborted)throw t.reason instanceof Error?t.reason:new DOMException(`Aborted`,`AbortError`);if(c)return c(e,t);if(s)return s(e);throw Error(`Page fetch is not available (app bridge not installed)`)}var ne={ß:``,ʼn:``,ƀ:``,ƚ:``,Dž:``,dž:`Dž`,Lj:``,lj:`Lj`,Nj:``,nj:`Nj`,ǰ:``,Dz:``,dz:`Dz`,ȼ:``,ȿ:``,ɀ:``,ɂ:``,ɇ:``,ɉ:``,ɋ:``,ɍ:``,ɏ:``,ɐ:``,ɑ:``,ɒ:``,ɜ:``,ɡ:``,ɥ:``,ɦ:``,ɪ:``,ɫ:``,ɬ:``,ɱ:``,ɽ:``,ʂ:``,ʇ:``,ʉ:``,ʌ:``,ʝ:``,ʞ:``,"ͅ":``,ͱ:``,ͳ:``,ͷ:``,ͻ:``,ͼ:``,ͽ:``,ΐ:``,ΰ:``,ϗ:``,ϲ:`Σ`,ϳ:``,ϸ:``,ϻ:``,ӏ:``,ӷ:``,ӻ:``,ӽ:``,ӿ:``,ԑ:``,ԓ:``,ԕ:``,ԗ:``,ԙ:``,ԛ:``,ԝ:``,ԟ:``,ԡ:``,ԣ:``,ԥ:``,ԧ:``,ԩ:``,ԫ:``,ԭ:``,ԯ:``,և:``,ა:``,ბ:``,გ:``,დ:``,ე:``,ვ:``,ზ:``,თ:``,ი:``,კ:``,ლ:``,მ:``,ნ:``,ო:``,პ:``,ჟ:``,რ:``,ს:``,ტ:``,უ:``,ფ:``,ქ:``,ღ:``,ყ:``,შ:``,ჩ:``,ც:``,ძ:``,წ:``,ჭ:``,ხ:``,ჯ:``,ჰ:``,ჱ:``,ჲ:``,ჳ:``,ჴ:``,ჵ:``,ჶ:``,ჷ:``,ჸ:``,ჹ:``,ჺ:``,ჽ:``,ჾ:``,ჿ:``,ᏸ:``,ᏹ:``,ᏺ:``,ᏻ:``,ᏼ:``,ᏽ:``,ᲀ:``,ᲁ:``,ᲂ:``,ᲃ:``,ᲄ:``,ᲅ:``,ᲆ:``,ᲇ:``,ᲈ:``,ᵹ:``,ᵽ:``,ᶎ:``,ẖ:``,ẗ:``,ẘ:``,ẙ:``,ẚ:``,ỻ:``,ỽ:``,ỿ:``,ὐ:``,ὒ:``,ὔ:``,ὖ:``,ᾀ:`ᾈ`,ᾁ:`ᾉ`,ᾂ:`ᾊ`,ᾃ:`ᾋ`,ᾄ:`ᾌ`,ᾅ:`ᾍ`,ᾆ:`ᾎ`,ᾇ:`ᾏ`,ᾈ:``,ᾉ:``,ᾊ:``,ᾋ:``,ᾌ:``,ᾍ:``,ᾎ:``,ᾏ:``,ᾐ:`ᾘ`,ᾑ:`ᾙ`,ᾒ:`ᾚ`,ᾓ:`ᾛ`,ᾔ:`ᾜ`,ᾕ:`ᾝ`,ᾖ:`ᾞ`,ᾗ:`ᾟ`,ᾘ:``,ᾙ:``,ᾚ:``,ᾛ:``,ᾜ:``,ᾝ:``,ᾞ:``,ᾟ:``,ᾠ:`ᾨ`,ᾡ:`ᾩ`,ᾢ:`ᾪ`,ᾣ:`ᾫ`,ᾤ:`ᾬ`,ᾥ:`ᾭ`,ᾦ:`ᾮ`,ᾧ:`ᾯ`,ᾨ:``,ᾩ:``,ᾪ:``,ᾫ:``,ᾬ:``,ᾭ:``,ᾮ:``,ᾯ:``,ᾲ:``,ᾳ:`ᾼ`,ᾴ:``,ᾶ:``,ᾷ:``,ᾼ:``,ῂ:``,ῃ:`ῌ`,ῄ:``,ῆ:``,ῇ:``,ῌ:``,ῒ:``,ΐ:``,ῖ:``,ῗ:``,ῢ:``,ΰ:``,ῤ:``,ῦ:``,ῧ:``,ῲ:``,ῳ:`ῼ`,ῴ:``,ῶ:``,ῷ:``,ῼ:``,ⅎ:``,ⅰ:``,ⅱ:``,ⅲ:``,ⅳ:``,ⅴ:``,ⅵ:``,ⅶ:``,ⅷ:``,ⅸ:``,ⅹ:``,ⅺ:``,ⅻ:``,ⅼ:``,ⅽ:``,ⅾ:``,ⅿ:``,ↄ:``,"ⓐ":``,"ⓑ":``,"ⓒ":``,"ⓓ":``,"ⓔ":``,"ⓕ":``,"ⓖ":``,"ⓗ":``,"ⓘ":``,"ⓙ":``,"ⓚ":``,"ⓛ":``,"ⓜ":``,"ⓝ":``,"ⓞ":``,"ⓟ":``,"ⓠ":``,"ⓡ":``,"ⓢ":``,"ⓣ":``,"ⓤ":``,"ⓥ":``,"ⓦ":``,"ⓧ":``,"ⓨ":``,"ⓩ":``,ⰰ:``,ⰱ:``,ⰲ:``,ⰳ:``,ⰴ:``,ⰵ:``,ⰶ:``,ⰷ:``,ⰸ:``,ⰹ:``,ⰺ:``,ⰻ:``,ⰼ:``,ⰽ:``,ⰾ:``,ⰿ:``,ⱀ:``,ⱁ:``,ⱂ:``,ⱃ:``,ⱄ:``,ⱅ:``,ⱆ:``,ⱇ:``,ⱈ:``,ⱉ:``,ⱊ:``,ⱋ:``,ⱌ:``,ⱍ:``,ⱎ:``,ⱏ:``,ⱐ:``,ⱑ:``,ⱒ:``,ⱓ:``,ⱔ:``,ⱕ:``,ⱖ:``,ⱗ:``,ⱘ:``,ⱙ:``,ⱚ:``,ⱛ:``,ⱜ:``,ⱝ:``,ⱞ:``,ⱡ:``,ⱥ:``,ⱦ:``,ⱨ:``,ⱪ:``,ⱬ:``,ⱳ:``,ⱶ:``,ⲁ:``,ⲃ:``,ⲅ:``,ⲇ:``,ⲉ:``,ⲋ:``,ⲍ:``,ⲏ:``,ⲑ:``,ⲓ:``,ⲕ:``,ⲗ:``,ⲙ:``,ⲛ:``,ⲝ:``,ⲟ:``,ⲡ:``,ⲣ:``,ⲥ:``,ⲧ:``,ⲩ:``,ⲫ:``,ⲭ:``,ⲯ:``,ⲱ:``,ⲳ:``,ⲵ:``,ⲷ:``,ⲹ:``,ⲻ:``,ⲽ:``,ⲿ:``,ⳁ:``,ⳃ:``,ⳅ:``,ⳇ:``,ⳉ:``,ⳋ:``,ⳍ:``,ⳏ:``,ⳑ:``,ⳓ:``,ⳕ:``,ⳗ:``,ⳙ:``,ⳛ:``,ⳝ:``,ⳟ:``,ⳡ:``,ⳣ:``,ⳬ:``,ⳮ:``,ⳳ:``,ⴀ:``,ⴁ:``,ⴂ:``,ⴃ:``,ⴄ:``,ⴅ:``,ⴆ:``,ⴇ:``,ⴈ:``,ⴉ:``,ⴊ:``,ⴋ:``,ⴌ:``,ⴍ:``,ⴎ:``,ⴏ:``,ⴐ:``,ⴑ:``,ⴒ:``,ⴓ:``,ⴔ:``,ⴕ:``,ⴖ:``,ⴗ:``,ⴘ:``,ⴙ:``,ⴚ:``,ⴛ:``,ⴜ:``,ⴝ:``,ⴞ:``,ⴟ:``,ⴠ:``,ⴡ:``,ⴢ:``,ⴣ:``,ⴤ:``,ⴥ:``,ⴧ:``,ⴭ:``,ꙁ:``,ꙃ:``,ꙅ:``,ꙇ:``,ꙉ:``,ꙋ:``,ꙍ:``,ꙏ:``,ꙑ:``,ꙓ:``,ꙕ:``,ꙗ:``,ꙙ:``,ꙛ:``,ꙝ:``,ꙟ:``,ꙡ:``,ꙣ:``,ꙥ:``,ꙧ:``,ꙩ:``,ꙫ:``,ꙭ:``,ꚁ:``,ꚃ:``,ꚅ:``,ꚇ:``,ꚉ:``,ꚋ:``,ꚍ:``,ꚏ:``,ꚑ:``,ꚓ:``,ꚕ:``,ꚗ:``,ꚙ:``,ꚛ:``,ꜣ:``,ꜥ:``,ꜧ:``,ꜩ:``,ꜫ:``,ꜭ:``,ꜯ:``,ꜳ:``,ꜵ:``,ꜷ:``,ꜹ:``,ꜻ:``,ꜽ:``,ꜿ:``,ꝁ:``,ꝃ:``,ꝅ:``,ꝇ:``,ꝉ:``,ꝋ:``,ꝍ:``,ꝏ:``,ꝑ:``,ꝓ:``,ꝕ:``,ꝗ:``,ꝙ:``,ꝛ:``,ꝝ:``,ꝟ:``,ꝡ:``,ꝣ:``,ꝥ:``,ꝧ:``,ꝩ:``,ꝫ:``,ꝭ:``,ꝯ:``,ꝺ:``,ꝼ:``,ꝿ:``,ꞁ:``,ꞃ:``,ꞅ:``,ꞇ:``,ꞌ:``,ꞑ:``,ꞓ:``,ꞔ:``,ꞗ:``,ꞙ:``,ꞛ:``,ꞝ:``,ꞟ:``,ꞡ:``,ꞣ:``,ꞥ:``,ꞧ:``,ꞩ:``,ꞵ:``,ꞷ:``,ꞹ:``,ꞻ:``,ꞽ:``,ꞿ:``,ꟃ:``,ꭓ:``,ꭰ:``,ꭱ:``,ꭲ:``,ꭳ:``,ꭴ:``,ꭵ:``,ꭶ:``,ꭷ:``,ꭸ:``,ꭹ:``,ꭺ:``,ꭻ:``,ꭼ:``,ꭽ:``,ꭾ:``,ꭿ:``,ꮀ:``,ꮁ:``,ꮂ:``,ꮃ:``,ꮄ:``,ꮅ:``,ꮆ:``,ꮇ:``,ꮈ:``,ꮉ:``,ꮊ:``,ꮋ:``,ꮌ:``,ꮍ:``,ꮎ:``,ꮏ:``,ꮐ:``,ꮑ:``,ꮒ:``,ꮓ:``,ꮔ:``,ꮕ:``,ꮖ:``,ꮗ:``,ꮘ:``,ꮙ:``,ꮚ:``,ꮛ:``,ꮜ:``,ꮝ:``,ꮞ:``,ꮟ:``,ꮠ:``,ꮡ:``,ꮢ:``,ꮣ:``,ꮤ:``,ꮥ:``,ꮦ:``,ꮧ:``,ꮨ:``,ꮩ:``,ꮪ:``,ꮫ:``,ꮬ:``,ꮭ:``,ꮮ:``,ꮯ:``,ꮰ:``,ꮱ:``,ꮲ:``,ꮳ:``,ꮴ:``,ꮵ:``,ꮶ:``,ꮷ:``,ꮸ:``,ꮹ:``,ꮺ:``,ꮻ:``,ꮼ:``,ꮽ:``,ꮾ:``,ꮿ:``,ff:``,fi:``,fl:``,ffi:``,ffl:``,ſt:``,st:``,ﬓ:``,ﬔ:``,ﬕ:``,ﬖ:``,ﬗ:``,𐑎:``,𐑏:``,𐓘:``,𐓙:``,𐓚:``,𐓛:``,𐓜:``,𐓝:``,𐓞:``,𐓟:``,𐓠:``,𐓡:``,𐓢:``,𐓣:``,𐓤:``,𐓥:``,𐓦:``,𐓧:``,𐓨:``,𐓩:``,𐓪:``,𐓫:``,𐓬:``,𐓭:``,𐓮:``,𐓯:``,𐓰:``,𐓱:``,𐓲:``,𐓳:``,𐓴:``,𐓵:``,𐓶:``,𐓷:``,𐓸:``,𐓹:``,𐓺:``,𐓻:``,𐳀:``,𐳁:``,𐳂:``,𐳃:``,𐳄:``,𐳅:``,𐳆:``,𐳇:``,𐳈:``,𐳉:``,𐳊:``,𐳋:``,𐳌:``,𐳍:``,𐳎:``,𐳏:``,𐳐:``,𐳑:``,𐳒:``,𐳓:``,𐳔:``,𐳕:``,𐳖:``,𐳗:``,𐳘:``,𐳙:``,𐳚:``,𐳛:``,𐳜:``,𐳝:``,𐳞:``,𐳟:``,𐳠:``,𐳡:``,𐳢:``,𐳣:``,𐳤:``,𐳥:``,𐳦:``,𐳧:``,𐳨:``,𐳩:``,𐳪:``,𐳫:``,𐳬:``,𐳭:``,𐳮:``,𐳯:``,𐳰:``,𐳱:``,𐳲:``,𑣀:``,𑣁:``,𑣂:``,𑣃:``,𑣄:``,𑣅:``,𑣆:``,𑣇:``,𑣈:``,𑣉:``,𑣊:``,𑣋:``,𑣌:``,𑣍:``,𑣎:``,𑣏:``,𑣐:``,𑣑:``,𑣒:``,𑣓:``,𑣔:``,𑣕:``,𑣖:``,𑣗:``,𑣘:``,𑣙:``,𑣚:``,𑣛:``,𑣜:``,𑣝:``,𑣞:``,𑣟:``,𖹠:``,𖹡:``,𖹢:``,𖹣:``,𖹤:``,𖹥:``,𖹦:``,𖹧:``,𖹨:``,𖹩:``,𖹪:``,𖹫:``,𖹬:``,𖹭:``,𖹮:``,𖹯:``,𖹰:``,𖹱:``,𖹲:``,𖹳:``,𖹴:``,𖹵:``,𖹶:``,𖹷:``,𖹸:``,𖹹:``,𖹺:``,𖹻:``,𖹼:``,𖹽:``,𖹾:``,𖹿:``,𞤢:``,𞤣:``,𞤤:``,𞤥:``,𞤦:``,𞤧:``,𞤨:``,𞤩:``,𞤪:``,𞤫:``,𞤬:``,𞤭:``,𞤮:``,𞤯:``,𞤰:``,𞤱:``,𞤲:``,𞤳:``,𞤴:``,𞤵:``,𞤶:``,𞤷:``,𞤸:``,𞤹:``,𞤺:``,𞤻:``,𞤼:``,𞤽:``,𞤾:``,𞤿:``,𞥀:``,𞥁:``,𞥂:``,𞥃:``},d=0,re=1,ie=-1;function f(e){return(e||``).toLowerCase().replace(/ /g,`_`)}function ae(e){return e.replace(/[\u0080-\u07FF\uD800-\uDFFF]/g,`**`).replace(/[\u0800-\uD7FF\uE000-\uFFFF]/g,`***`).length}function p(e){if(e===d)return``;let t=g.idNameMap[e];if(t===void 0)throw Error(`Unknown namespace id ${e}`);return t.replace(/ /g,`_`)+`:`}function m(e){if(typeof e!=`string`)return!1;let t=g.nameIdMap[e.toLowerCase()];return t!==void 0&&t}function h(e,t){g.checkData();let n=/[\u200E\u200F\u202A-\u202E]+/g,r=/[ _\u00A0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]+/g,i=/^_+|_+$/g,a=/^(.+?)_*:_*(.*)$/,o=RegExp(`[^ %!"$&'()*,\\-./0-9:;=?@A-Z\\\\\\^_\`a-z~+\\u0080-\\uFFFF]|%[\\dA-Fa-f]{2}|&[\\dA-Za-z-�]+;|&#\\d+;|&#x[\\dA-Fa-f]+;`),s=t===void 0?d:t,c;if(e=e.replace(n,``).replace(r,`_`).replace(i,``),e!==``&&e[0]===`:`&&(s=d,e=e.slice(1).replace(i,``)),e===``)return!1;let l=e.match(a);if(l){let t=m(l[1]);if(t!==!1&&(s=t,e=l[2],s===re&&(l=e.match(a))&&m(l[1])!==!1))return!1}let u=e.indexOf(`#`);return u===-1?c=null:(c=e.slice(u+1).replace(/_/g,` `),e=e.slice(0,u).replace(i,``)),o.test(e)||e.indexOf(`.`)!==-1&&(e===`.`||e===`..`||e.indexOf(`./`)===0||e.indexOf(`../`)===0||e.indexOf(`/./`)!==-1||e.indexOf(`/../`)!==-1||e.slice(-2)===`/.`||e.slice(-3)===`/..`)||e.indexOf(`[[User:DeadbeefBot II|DeadbeefBot II]] ([[User talk:DeadbeefBot II|talk]])`)!==-1||s!==ie&&ae(e)>255||e===``&&s!==d||e[0]===`:`?!1:{namespace:s,title:e,fragment:c}}var g=class e{static idNameMap={};static nameIdMap={};static legaltitlechars=``;static caseSensitiveNamespaces=[];title;namespace;fragment;static processNamespaceData(t){e.idNameMap={},e.nameIdMap={},Object.values(t.query.namespaces).forEach(t=>{e.idNameMap[t.id]=t.name,e.nameIdMap[f(t.name)]=t.id,t.canonical&&(e.nameIdMap[f(t.canonical)]=t.id)}),t.query.namespacealiases.forEach(t=>{e.nameIdMap[f(t.alias)]=t.id}),e.legaltitlechars=t.query.general.legaltitlechars,e.caseSensitiveNamespaces=Object.values(t.query.namespaces).filter(e=>e.case===`case-sensitive`).map(e=>e.id)}static checkData(){if(!e.nameIdMap||!Object.keys(e.nameIdMap).length||!e.idNameMap||!e.legaltitlechars)throw Error(`namespace data unavailable: run getSiteInfo() or login() first`)}constructor(e,t){let n=h(e,t);if(!n)throw Error(`Unable to parse title`);this.namespace=n.namespace,this.title=n.title,this.fragment=n.fragment}getNamespaceId(){return this.namespace}getNamespacePrefix(){return p(this.namespace)}getMain(){return e.caseSensitiveNamespaces.indexOf(this.namespace)!==-1||!this.title.length?this.title:e.phpCharToUpper(this.title[0])+this.title.slice(1)}getMainText(){return this.getMain().replace(/_/g,` `)}getPrefixedDb(){return this.getNamespacePrefix()+this.getMain()}getPrefixedText(){return this.getPrefixedDb().replace(/_/g,` `)}getFragment(){return this.fragment}isTalkPage(){return e.isTalkNamespace(this.getNamespaceId())}getTalkPage(){return this.canHaveTalkPage()?this.isTalkPage()?this:e.makeTitle(this.getNamespaceId()+1,this.getMainText()):null}getSubjectPage(){return this.isTalkPage()?e.makeTitle(this.getNamespaceId()-1,this.getMainText()):this}canHaveTalkPage(){return this.getNamespaceId()>=d}getExtension(){let e=this.title.lastIndexOf(`.`);return e===-1?null:this.title.slice(e+1)||null}getDotExtension(){let e=this.getExtension();return e===null?``:`.`+e}static newFromText(t,n=0){let r=h(t,n);if(!r)return null;let i=Object.create(e.prototype);return i.namespace=r.namespace,i.title=r.title,i.fragment=r.fragment,i}static makeTitle(t,n){return e.newFromText(p(t)+n)}static isTalkNamespace(e){return!!(e>d&&e%2)}static phpCharToUpper(e){let t=ne[e];return t===``?e:t||e.toUpperCase()}toString(){return this.getPrefixedDb()}toText(){return this.getPrefixedText()}};function oe(e){let t=[],n=``,r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(o===`{`&&e[a+1]===`{`){r+=1,n+=`{{`,a+=1;continue}if(o===`}`&&e[a+1]===`}`){r=Math.max(0,r-1),n+=`}}`,a+=1;continue}if(o===`[`&&e[a+1]===`[`){i+=1,n+=`[[`,a+=1;continue}if(o===`]`&&e[a+1]===`]`){i=Math.max(0,i-1),n+=`]]`,a+=1;continue}if(o===`|`&&r===0&&i===0){t.push(n),n=``;continue}n+=o}return t.push(n),t}function _(e){let t=``;for(let n of e)t+=n.kind===`text`?n.text:S(n.template);return t}function v(e){let t=e.indexOf(`:`);return t<1?!1:/^[A-Z][A-Z_]*$/.test(e.slice(0,t).trim())}function se(e){return e.trim().startsWith(`#`)}function ce(e){return!v(e)&&!se(e)}function y(e,t=0){let n=[],r=0,i=0;for(;r<e.length;){if(r<e.length-1&&e[r]===`{`&&e[r+1]===`{`){if(e[r+2]===`{`){r+=3;continue}r>i&&n.push({kind:`text`,text:e.slice(i,r)});let a=r,o=2;for(r+=2;r<e.length&&o>0;){if(e[r]===`{`&&e[r+1]===`{`){o+=2,r+=2;continue}if(e[r]===`}`&&e[r+1]===`}`){o-=2,r+=2;continue}r+=1}if(o===0){let o=e.slice(a,r),s=o.slice(2,-2),c=(/^([^|{}\n]+)/.exec(s)?.[1]??``).trim();c&&ce(c)?n.push({kind:`template`,template:x({raw:o,start:t+a,end:t+r,name:c,inner:s})}):n.push({kind:`text`,text:o}),i=r;continue}break}r+=1}return i<e.length&&n.push({kind:`text`,text:e.slice(i)}),n.length===0?[{kind:`text`,text:``}]:n}function le(e){return y(e,0)}function ue(e){let t=[];for(let n of e)n.kind===`template`&&t.push(n.template);return t}function b(e){return y(_(e).trim())}function x(e){let t=oe(e.inner),n=t[0]??``,r=/^\s*/.exec(n)?.[0]??``,i=n.length===0?``:/\s*$/.exec(n.slice(r.length))?.[0]??``,a=[],o=0,s=e.start+2,c=0;for(let e=0;e<t.length;e++){let n=t[e],r=c;if(c+=n.length,e<t.length-1&&(c+=1),e===0)continue;let i=/^(\s*)([^=|]+?)(\s*)=(.*)$/s.exec(n);if(i){let e=i[4],t=n.length-e.length;a.push({kind:`named`,name:i[2].trim(),value:y(e,s+r+t),wsBefore:i[1],wsAfterName:i[3]})}else o+=1,a.push({kind:`positional`,index:o,value:y(n,s+r)})}return{name:e.name,params:a,start:e.start,end:e.end,raw:e.raw,nameWsLeading:r,nameWsTrailing:i,pristine:!0}}function S(e){if(e.pristine)return e.raw;let t=`${e.nameWsLeading}${e.name}${e.nameWsTrailing}`,n=e.params.map(e=>e.kind===`named`?`${e.wsBefore}${e.name}${e.wsAfterName}=${_(e.value)}`:_(e.value));return`{{${n.length===0?t:`${t}|${n.join(`|`)}`}}}`}function de(e){let t=e.params.filter(e=>e.kind===`named`).map(e=>e.name.length),n=t.length>0?Math.max(...t):0,r=[`{{${e.name}`];for(let t of e.params){let e=_(t.value).trim();if(t.kind===`named`){let i=` `.repeat(Math.max(0,n-t.name.length));r.push(`| ${t.name}${i} = ${e}`)}else r.push(`| ${e}`)}return r.push(`}}`),r.join(`
`)}function fe(e){let t=e.params.map(e=>e.kind===`named`?{...e,value:b(e.value),wsBefore:` `,wsAfterName:` `}:{...e,value:b(e.value)}),n={...e,params:t,nameWsLeading:``,nameWsTrailing:``,pristine:!1};return{...n,raw:de(n),pristine:!0}}function pe(e){let t=0;return e.map(e=>e.kind===`positional`?(t+=1,{...e,index:t}):e)}function me(e,t){let n=t.trim();return n?e.kind===`named`?e.name.toLowerCase()===n.toLowerCase():String(e.index)===n:!1}function he(e,t){let n=t.trim();if(!n)return``;let r=e.params.find(e=>e.kind===`named`&&e.name.toLowerCase()===n.toLowerCase());if(r)return _(r.value);let i=e.params.find(e=>e.kind===`positional`&&String(e.index)===n);return i?_(i.value):``}function C(e,t){let n=t.trim();if(!n)return e;let r=e.params.filter(e=>!me(e,n));return r.length===e.params.length?e:{...e,params:pe(r),pristine:!1}}function w(e,t,n){let r=t.trim(),i=n.trim();if(!r||!i||r===i)return e;let a=!1,o=e.params.map(e=>e.kind!==`named`||e.name!==r?e:(a=!0,{...e,name:i}));return a?{...e,params:o,pristine:!1}:e}function ge(e,t){let n=e=>{t(e);for(let t of e.params)for(let e of t.value)e.kind===`template`&&n(e.template)};for(let t of e)n(t)}function T(e,t){let n=!1,r=e.params.map(e=>{let r=!1,i=e.value.map(e=>{if(e.kind===`text`)return e;let i=T(e.template,t);return i===e.template?e:(r=!0,n=!0,{kind:`template`,template:i})});return r?{...e,value:i}:e});return t(n?{...e,params:r,pristine:!1}:e)}function _e(e,t,n){let r=Array.isArray(t)?t:[t];return e.map(e=>T(e,e=>r.some(t=>D(e.name,t))?n(e):e))}function ve(e){let t=new Set;return ge(e,e=>{let n=e.name.trim();!n||n.startsWith(`#`)||v(n)||t.add(i(n))}),[...t]}function ye(e,t,n){return Se(e,_e(E(e),t,n))}function E(e){return ue(le(e))}function be(e,t){return t.start>=e.start&&t.end<=e.end&&(t.start>e.start||t.end<e.end)}function xe(e){for(let t=0;t<e.length;t++)for(let n=0;n<e.length;n++)if(t!==n&&be(e[t],e[n]))throw Error(`Expected root templates only; nested spans must not be applied or deleted separately (use map-templates-by-name / mapTemplatesInContent)`)}function Se(e,t){xe(t);let n=[...t].sort((e,t)=>t.start-e.start),r=e;for(let e of n)r=r.slice(0,e.start)+S(e)+r.slice(e.end);return r}function Ce(e){let t=[],n=[],r=0,i=0;for(;i<e.length-1;){if(e[i]===`{`&&e[i+1]===`{`){if(e[i+2]===`{`){r+=1,i+=3;continue}n.push(i),i+=2;continue}if(e[i]===`}`&&e[i+1]===`}`){if(e[i+2]===`}`&&r>0){--r,i+=3;continue}if(n.length>0){let r=n.pop(),a=i+2,o=e.slice(r,a),s=o.slice(2,-2),c=(/^([^|{}\n]+)/.exec(s)?.[1]??``).trim();c&&!v(c)&&t.push({raw:o,start:r,end:a,name:c,inner:s}),i+=2;continue}}i+=1}return t}function D(e,t){return a(i(e))===a(i(t))}function O(e){let t=a(i(e));return t.startsWith(`infobox`)||t.includes(`infobox`)}var we={renames:[],remove:[],regexps:[]},k=new Map,A=new Map,j=3600*1e3,Te=`pillbug-rdp`,Ee=2,M=`deprecated-rules`,De=new Set([`_category`,`preview`,`ignoreblank`]),Oe=/^_regexp[1-9][0-9]*$/i,ke=[`#invoke:Check for deprecated parameters`,`#invoke:Module:Check for deprecated parameters`];function Ae(e){let t=a(e);return ke.some(e=>a(e)===t)}function N(e){return Date.now()-e<j}function P(){return typeof indexedDB>`u`?Promise.resolve(null):new Promise(e=>{try{let t=indexedDB.open(Te,Ee);t.onerror=()=>e(null),t.onupgradeneeded=()=>{let e=t.result;e.objectStoreNames.contains(M)||e.createObjectStore(M,{keyPath:`key`})},t.onsuccess=()=>e(t.result)}catch{e(null)}})}async function je(e){let t=await P();return t?new Promise(n=>{try{let r=t.transaction(M,`readonly`).objectStore(M).get(e);r.onerror=()=>{t.close(),n(null)},r.onsuccess=()=>{t.close();let e=r.result;if(!e||!e.rules||typeof e.cachedAt!=`number`){n(null);return}let a=Array.isArray(e.matchNames)&&e.matchNames.length>0?e.matchNames:[i(e.key)];n({rules:e.rules,matchNames:a,cachedAt:e.cachedAt})}}catch{try{t.close()}catch{}n(null)}}):null}async function Me(e,t){let n=await P();if(n)return new Promise(r=>{try{let i=n.transaction(M,`readwrite`);i.oncomplete=()=>{n.close(),r()},i.onerror=()=>{n.close(),r()},i.objectStore(M).put({key:e,...t})}catch{try{n.close()}catch{}r()}})}async function F(){let e=await P();if(e)return new Promise(t=>{try{let n=e.transaction(M,`readwrite`);n.oncomplete=()=>{e.close(),t()},n.onerror=()=>{e.close(),t()},n.objectStore(M).clear()}catch{try{e.close()}catch{}t()}})}function Ne(e){return e.replace(/<(nowiki|noinclude)\b[^>]*>([\s\S]*?)<\/\1\s*>/gi,e=>` `.repeat(e.length))}function I(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===`%`){let r=e[n+1];if(r==null){t+=`%`,n+=1;continue}switch(n+=2,r){case`%`:t+=`%`;break;case`d`:t+=`\\d`;break;case`a`:t+=`[A-Za-z]`;break;case`w`:t+=`[A-Za-z0-9_]`;break;case`s`:t+=`\\s`;break;case`.`:case`(`:case`)`:case`+`:case`*`:case`-`:case`?`:case`[`:case`]`:case`^`:case`$`:t+=`\\`+r;break;default:t+=r.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);break}continue}if(r===`.`){t+=`[\\s\\S]`,n+=1;continue}if(r===`(`||r===`)`||r===`?`||r===`*`||r===`+`){t+=r,n+=1;continue}if(r===`-`){t+=`\\-`,n+=1;continue}if(r===`[`){let r=n+1,i=`[`;for(;r<e.length;){let t=e[r];if(t===`%`&&e[r+1]){let t=e[r+1];r+=2,t===`d`?i+=`\\d`:t===`a`?i+=`A-Za-z`:t===`w`?i+=`A-Za-z0-9_`:t===`s`?i+=`\\s`:i+=t;continue}if(t===`]`){i+=`]`,r+=1;break}i+=t,r+=1}t+=i,n=r;continue}/[\\^$|{}]/.test(r)?t+=`\\`+r:t+=r,n+=1}return t}function Pe(e){return e.replace(/%([1-9])/g,(e,t)=>`$${t}`)}function Fe(e,t){try{return RegExp(`^(?:${I(t)})$`).test(e)}catch{return!1}}function Ie(e,t,n){try{let r=RegExp(`^(?:${I(t)})$`);return e.replace(r,Pe(n))}catch{return e}}function Le(e){let t=[],n=[],r=[];for(let i of e){if(i.kind!==`named`)continue;let e=i.name.trim(),a=_(i.value).trim();if(e&&!De.has(e.toLowerCase())){if(e.toLowerCase()===`_remove`){for(let e of a.split(`;`)){let t=e.trim();t&&n.push(t)}continue}if(Oe.test(e)){if(!a.includes(`=`))continue;let e=a.split(/\s*=\s*/);if(e.length<2)continue;let t=(e[0]??``).trim(),n=e.slice(1).join(`=`).trim();t&&r.push({find:t,replace:n});continue}a&&t.push({from:e,to:a})}}return{renames:t,remove:n,regexps:r}}function L(e){let t=Ce(Ne(e)).find(e=>Ae(e.name));return t?Le(x({...t,raw:e.slice(t.start,t.end),inner:e.slice(t.start+2,t.end-2)}).params):{...we,renames:[],remove:[],regexps:[]}}function R(e){if(t(e))return e.getPrefixedText();let r=n(e).trim();if(!r)throw Error(`Template title is empty`);try{let e=g.nameIdMap.template;return e===void 0?new g(r).getPrefixedText():new g(r,e).getPrefixedText()}catch{return/^Template\s*:/i.test(r)||/^[^:\s]+:/.test(r)?r.replace(/_/g,` `):`Template:${r.replace(/_/g,` `)}`}}var Re=/^#\s*redirect\s*:?\s*\[\[([^\]|#]+)(?:\|[^\]]*)?\]\]/i;function z(e){let t=Re.exec(e.trim());return t&&t[1].replace(/_/g,` `).trim()||null}var B=5;function V(e,t){let n=i(t);n&&e.add(n)}function ze(e){let t=new Set;V(t,e);let n=e;for(let e=0;e<B;e++){let e=ee(n);if(!e.exists)throw Error(`Template page not found: ${n}`);if(e.resolvedTitle){if(V(t,e.resolvedTitle),!z(e.content))return{source:e.content,matchNames:[...t]};n=e.resolvedTitle}let r=z(e.content);if(!r)return{source:e.content,matchNames:[...t]};n=R(r),V(t,n)}throw Error(`Too many template redirects starting at ${e}`)}async function Be(e,t){let n=new Set;V(n,e);let r=e;for(let e=0;e<B;e++){let e=await te(r,t);if(!e.exists)throw Error(`Template page not found: ${r}`);if(e.resolvedTitle){if(V(n,e.resolvedTitle),!z(e.content))return{source:e.content,matchNames:[...n]};r=e.resolvedTitle}let i=z(e.content);if(!i)return{source:e.content,matchNames:[...n]};r=R(i),V(n,r)}throw Error(`Too many template redirects starting at ${e}`)}function Ve(e){let t=R(e),n=k.get(t);if(n)return n;let r=ze(t),i={rules:L(r.source),matchNames:r.matchNames};return k.set(t,i),i}async function H(e,t){let n=R(e),r=A.get(n);if(r&&N(r.cachedAt))return{rules:r.rules,matchNames:r.matchNames};let i=await je(n);if(i&&N(i.cachedAt))return A.set(n,i),{rules:i.rules,matchNames:i.matchNames};let a=await Be(n,t),o={rules:L(a.source),matchNames:a.matchNames,cachedAt:Date.now()};return A.set(n,o),Me(n,o),{rules:o.rules,matchNames:o.matchNames}}async function U(e){return(await H(e)).rules}function He(){k.clear(),A.clear(),F()}async function Ue(){k.clear(),A.clear(),await F()}var We=[`Infobox person`,`Infobox officeholder`,`Infobox military person`,`Infobox Christian leader`,`Infobox college coach`,`Infobox academic`,`Infobox Latter Day Saint biography`],Ge=new Set([`enwiki`,`testwiki`,`test2wiki`]),Ke=new Set([`en.wikipedia.org`,`test.wikipedia.org`,`test2.wikipedia.org`]),qe=null;function W(e){let t=globalThis;try{return t.mw?.config?.get?.(e)}catch{return}}function Je(){let e=W(`wgServerName`);if(typeof e==`string`&&e.trim())return e.trim().toLowerCase();let t=qe?.();if(t)try{return new URL(t).hostname.toLowerCase()}catch{return}}function Ye(){let e=W(`wgDBname`);if(typeof e==`string`&&Ge.has(e))return!0;let t=Je();return t!=null&&Ke.has(t)}function Xe(e){let t=e.params.find(e=>e.kind===`named`&&e.name.toLowerCase()===`alma_mater`);return!t||t.kind!==`named`?e:he(e,`alma_mater`).trim()?w(C(e,`education`),t.name,`education`):C(e,t.name)}function Ze(e){return e.some(e=>We.some(t=>D(e,t)))}function Qe(e,t){let n=e;for(let{from:e,to:r}of t.renames)n=w(n,e,r);for(let e of t.remove)n=C(n,e);if(t.regexps.length>0){let e=n.params.filter(e=>e.kind===`named`);for(let r of e)if(r.kind===`named`)for(let e of t.regexps){if(!Fe(r.name,e.find))continue;let t=Ie(r.name,e.find,e.replace);t&&t!==r.name&&(n=w(n,r.name,t));break}}return n}function G(e,t,n,r){let i=r.renames.length>0||r.remove.length>0||r.regexps.length>0,a=Ye()&&Ze(e);return!i&&!n&&!a?t:ye(t,e,e=>{let t=e;return a&&(t=Xe(t)),i&&(t=Qe(t,r)),n&&(t=fe(t)),t})}function K(e,t,n){let{rules:r,matchNames:i}=Ve(e);return G(i,t,n,r)}async function q(e,t,n,r){let{rules:i,matchNames:a}=await H(e,r);return G(a,t,n,i)}var J=`removed deprecated parameters using [[User:MSK/rdp|rdp]]`;function Y(){let e=document.getElementById(`wpSummary`);if(!e)return;let t=e.value.trim();t.includes(`[[User:MSK/rdp|rdp]]`)||(e.value=t?`${t} · ${J}`:J,e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})))}async function $e(){await mw.loader.using([`jquery.textSelection`,`mediawiki.util`]);function e(){return String($(`#wpTextbox1`).textSelection(`getContents`)??``)}function t(e){$(`#wpTextbox1`).textSelection(`setContents`,e)}async function n(n){let r=e(),i=await q(n,r,O(n));return i!==r&&t(i),i!==r}function r(){let r=$(`#wikiEditor-ui-toolbar .sections`);if(!r.length||r.data(`rdp-buttons`))return!1;r.data(`rdp-buttons`,!0);let i=$(`<button>`).attr({type:`button`,title:`Replace deprecated parameters for one template`}).attr(`style`,`margin: 5px;`).text(`RDP (one)`).on(`click`,async()=>{let e=window.prompt(`Template name (Template: implied if omitted):`,``);if(!(e==null||!e.trim()))try{let t=await n(e.trim());t&&Y(),mw.notify(t?`Deprecated parameters replaced.`:`No changes.`,{type:t?`success`:`info`})}catch(e){let t=e;mw.notify(String(t?.message||e),{type:`error`})}}),a=$(`<button>`).attr({type:`button`,title:`Replace deprecated parameters for every template`}).attr(`style`,`margin: 5px;`).text(`RDP (all)`).on(`click`,async()=>{try{let n=e(),r=ve(E(n));if(!r.length){mw.notify(`No templates found.`,{type:`info`});return}let i=[];await Promise.all(r.map(async e=>{try{await U(e)}catch(t){let n=t;i.push(`${e}: ${n?.message||t}`)}}));let a=!1;for(let e of r)try{let t=await q(e,n,O(e));t!==n&&(a=!0,n=t)}catch(t){let n=`${e}: ${t?.message||t}`;i.includes(n)||i.push(n)}a&&(t(n),Y()),i.length?mw.notify(`Done with ${i.length} error(s). First: ${i[0]}`,{type:`warn`}):mw.notify(a?`Updated (${r.length} unique template(s)).`:`No changes (${r.length} unique template(s)).`,{type:a?`success`:`info`})}catch(e){let t=e;mw.notify(String(t?.message||e),{type:`error`})}});return r.append(i,a),!0}if(!r()){mw.hook(`wikiEditor.toolbarReady`).add(()=>{r()});let e=Date.now(),t=setInterval(()=>{(r()||Date.now()-e>15e3)&&clearInterval(t)},250)}}function et(){if(typeof mw>`u`)return;let e=mw.config.get(`wgAction`);e!==`edit`&&e!==`submit`||$e().catch(e=>{let t=e;mw.notify(`RDP toolbar failed: `+String(t?.message||e),{type:`error`})})}var X=`/w/api.php`;function tt(e){let t=e.revisions?.[0];if(!t)return null;let n=t.slots?.main;if(n){let e=n[`*`]??n.content;if(typeof e==`string`)return e}return typeof t[`*`]==`string`?t[`*`]:null}function nt(e,t){let n=e.query?.redirects;return n&&n.length>0?n[n.length-1].to:typeof t.title==`string`?t.title:void 0}function Z(e){let t;try{t=JSON.parse(e)}catch{throw Error(`Failed to parse wiki API response`)}if(t.error)throw Error(t.error.info??t.error.code??`Wiki API error`);let n=t.query?.pages;if(!n)return{exists:!1,content:``};for(let e of Object.values(n)){if(e.missing!==void 0||e.invalid!==void 0)return{exists:!1,content:``};let n=nt(t,e),r=tt(e);return r==null?{exists:!0,content:``,resolvedTitle:n}:{exists:!0,content:r,resolvedTitle:n}}return{exists:!1,content:``}}function rt(e){let t=new URLSearchParams({action:`query`,format:`json`,prop:`revisions`,rvprop:`content`,rvslots:`main`,redirects:`1`,titles:e}),n=X.includes(`?`)?`&`:`?`;return`${X}${n}${t.toString()}`}function it(e){let t=e.trim();if(!t)return{exists:!1,content:``};let n=rt(t),r=new XMLHttpRequest;r.open(`GET`,n,!1),r.withCredentials=!0;try{r.send(null)}catch(e){throw Error(e instanceof Error?`Failed to fetch page: ${e.message}`:`Failed to fetch page`)}if(r.status<200||r.status>=300)throw Error(`Failed to fetch page (HTTP ${r.status})`);return Z(r.responseText)}async function at(e,t){let n=e.trim();if(!n)return{exists:!1,content:``};let r=rt(n),i;try{i=await fetch(r,{credentials:`same-origin`,signal:t})}catch(e){throw o(e)?e:Error(e instanceof Error?`Failed to fetch page: ${e.message}`:`Failed to fetch page`)}if(!i.ok)throw Error(`Failed to fetch page (HTTP ${i.status})`);return Z(await i.text())}function ot(){l(it),u(at)}function st(e={}){typeof e.apiRoot==`string`&&e.apiRoot.trim()&&(X=e.apiRoot.trim()),ot()}function Q(e){if(typeof e!=`string`)throw Error(`Expected string content`);return e}function ct(e){return{contentAfter:K(e.title,Q(e.content),e.fixindent===!0)}}async function lt(e){return{contentAfter:await q(e.title,Q(e.content),e.fixindent===!0)}}ot(),et(),e.RULES_CACHE_TTL_MS=j,e.clearDeprecatedParamsCache=He,e.clearDeprecatedParamsCacheAsync=Ue,e.configure=st,e.execute=ct,e.executeAsync=lt,e.getDeprecatedParamsRulesAsync=U,e.replaceDeprecatedParametersInContent=K,e.replaceDeprecatedParametersInContentAsync=q,e.setPageContentsFetcher=l,e.setPageContentsFetcherAsync=u})(this.pillbugRdp=this.pillbugRdp||{});