User:Eejit43/scripts/displaytitle-editor.js

// // Note: This script was compiled and minified from TypeScript. For a more readable version, see https://github.com/Eejit43/wikipedia-scripts/blob/main/scripts/displaytitle-editor.ts

"use strict";mw.loader.using(["mediawiki.util","oojs-ui-core","oojs-ui.styles.icons-editing-core"],=>{if(mw.config.get("wgNamespaceNumber")<0||!mw.config.get("wgIsProbablyEditable"))return;mw.util.addCSS(` margin-right: 0; margin-left: 3px; font-size: 15px; }
 * 1) displaytitle-edit-button {

display: inline-block; ${mw.config.get("skin")==="modern"?"margin-top: 2px;":""} margin-bottom: 2px; width: 200px; max-width: 200px; font-size: 15px; }`),mw.config.get("skin")==="modern"&&mw.util.addCSS(` height: 2.5em; }
 * 1) displaytitle-edit-box {
 * 1) mw_header {

top: 2.5em; }
 * 1) p-personal {

margin-top: 4em; }`);const i=new OO.ui.ButtonWidget({icon:"edit",framed:!1,id:"displaytitle-edit-button"});i.on("click",async=>{i.setDisabled(!0),mw.config.get("skin")==="modern"&&mw.util.addCSS(`   height: 3em; }
 * 1) mw_main {
 * 1) mw_header {

top: 3em; }
 * 1) p-personal {

margin-top: 4.5em; }`);const s=mw.config.get("wgPageName").replaceAll("_"," "),e=new OO.ui.TextInputWidget({placeholder:s,id:"displaytitle-edit-box"});e.on("enter",async=>{e.setDisabled(!0),e.pushPending,await new mw.Api.edit(mw.config.get("wgPageName"),a=>{const t=a.content.replaceAll(/\n?/gi,"");if(!e.getValue||e.getValue.replaceAll("_"," ")===s)return{text:t,summary:"Removing DISPLAYTITLE (via script)"};const o=t===a.content;return/{{short description/i.test(t)?{text:t.replace(/{{short description(.*?)}}/i,`{{short description$1}} {{DISPLAYTITLE:${e.getValue}}}`),summary:`${o?"Adding DISPLAYTITLE of":"Changing DISPLAYTITLE to"} "${e.getValue}" (via script)`}:{text:`{{DISPLAYTITLE:${e.getValue}}} ${t}`,summary:`${o?"Adding DISPLAYTITLE of":"Changing DISPLAYTITLE to"} "${e.getValue}" (via script)`}}),mw.notify("Successfully updated DISPLAYTITLE, reloading...",{type:"success"}),window.location.reload}),e.setDisabled(!0),e.pushPending,i.$element[0].after(e.$element[0]);const n=(await new mw.Api.get({action:"query",formatversion:"2",prop:"revisions",rvprop:"content",rvslots:"main",titles:mw.config.get("wgPageName")})).query.pages[0].revisions[0].slots.main.content.match(//gi);n&&e.setValue(n.at(-1).replace(//i,"$1")),e.setDisabled(!1),e.popPending}),document.querySelector("#firstHeading")?.append(i.$element[0])});
 * 1) mw_main {

// //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc2NyaXB0cy9kaXNwbGF5dGl0bGUtZWRpdG9yLnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJpbXBvcnQgeyBBcGlRdWVyeVJldmlzaW9uc1BhcmFtcyB9IGZyb20gJ3R5cGVzLW1lZGlhd2lraS9hcGlfcGFyYW1zJztcbmltcG9ydCB7IFBhZ2VSZXZpc2lvbnNSZXN1bHQgfSBmcm9tICcuLi9nbG9iYWwtdHlwZXMnO1xuXG5tdy5sb2FkZXIudXNpbmcoWydtZWRpYXdpa2kudXRpbCcsICdvb2pzLXVpLWNvcmUnLCAnb29qcy11aS5zdHlsZXMuaWNvbnMtZWRpdGluZy1jb3JlJ10sICgpID0+IHtcbiAgICBpZiAobXcuY29uZmlnLmdldCgnd2dOYW1lc3BhY2VOdW1iZXInKSA8IDApIHJldHVybjsgLy8gRG9uJ3QgcnVuIGluIHZpcnR1YWwgbmFtZXNwYWNlc1xuICAgIGlmICghbXcuY29uZmlnLmdldCgnd2dJc1Byb2JhYmx5RWRpdGFibGUnKSkgcmV0dXJuOyAvLyBEb24ndCBydW4gaWYgdXNlciBjYW4ndCBlZGl0IHBhZ2VcblxuICAgIG13LnV0aWwuYWRkQ1NTKGBcbiNkaXNwbGF5dGl0bGUtZWRpdC1idXR0b24ge1xuICAgIG1hcmdpbi1yaWdodDogMDtcbiAgICBtYXJnaW4tbGVmdDogM3B4O1xu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