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.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>(function(){'use strict';constUSERSCRIPT_NAME='Vectron';constconfig={wikipage:'[[w:User:Andrybak/Scripts/${USERSCRIPT_NAME}|${USERSCRIPT_NAME}]]',version:'6'};constLOG_PREFIX=`[${USERSCRIPT_NAME} v${config.version}]:`;constmw=window.mw;// a hack to trick my JS editor into believing that `mw` exists// TODO: Not sure if still need to support the toggle button. Keep it for now.constTOGGLE_BUTTON_SELECTOR='#p-dock-bottom button.vector-limited-width-toggle';constSTANDARD_WIDTH_RADIO_BUTTON_SELECTOR='#skin-client-pref-vector-feature-limited-width-value-1';constWIDE_WIDTH_RADIO_BUTTON_SELECTOR='#skin-client-pref-vector-feature-limited-width-value-0';constANY_CONTROL_SELECTOR=`${TOGGLE_BUTTON_SELECTOR}, ${STANDARD_WIDTH_RADIO_BUTTON_SELECTOR}, ${WIDE_WIDTH_RADIO_BUTTON_SELECTOR}`;/* * MediaWiki has automatic scrolling to (and highlighting of) messages * with mentions. This hash disappears quickly from document.location, * so we have to remember it separately from function maybeShowHashTarget(). */letmentionHash=null;functionerror(...toLog){console.error(LOG_PREFIX,...toLog);}functionwarn(...toLog){console.warn(LOG_PREFIX,...toLog);}functioninfo(...toLog){console.info(LOG_PREFIX,...toLog);}functiondebug(...toLog){console.debug(LOG_PREFIX,...toLog);}functiongetLimitedWidthToggleButton(){returndocument.querySelector(TOGGLE_BUTTON_SELECTOR);}functionisWideVector(){returndocument.querySelector('html').classList.contains('vector-feature-limited-width-clientpref-0');}functionisNarrowVector(){return!isWideVector();}/* * Because we are messing with the layout of the page * on the fly, we need to ensure that the user sees * the linked section or linked mention on a discussion page. */functionmaybeShowHashTarget(){/* * These aren't regular #Section_heading anchors, but rather special * tags used by MediaWiki to highlight mentions. */if(mentionHash!==null){/* * MediaWiki adds an empty <span> at the _start_ of a message with the * corresponding `id`. * This id also corresponds to the attribute `data-mw-thread-id` stored * in an empty <span> at the _end_ of the same message after the "Reply" * button ([[mw:Extension:DiscussionTools]]), right after the signature. */constmaybeMentionMessage=document.getElementById(mentionHash.slice(1));/* * `null` will be returned in following cases: * - when the message was removed (e.g. into an archive) * - when the timestamp in the signature was re-generated (e.g. [[:en:Special:Diff/1222421941]]) */if(maybeMentionMessage!==null){maybeMentionMessage.scrollIntoView();return;}}/* * If a mention wasn't highlighted, try to scroll to a regular * anchor of a section. */if(document.location.hash===""){return;}consttargetId=document.location.hash.slice(1).replaceAll(' ','_');document.getElementById(targetId)?.scrollIntoView();}functionensureNeededWidth(checkFn,adjective,verb,controlClass){if(checkFn()){debug(`Already ${adjective}.`);return;}info(verb);constcontrol=document.querySelector(controlClass);control.click();maybeShowHashTarget();}functionensureWide(){ensureNeededWidth(isWideVector,'wide','Widening.',`${WIDE_WIDTH_RADIO_BUTTON_SELECTOR}, ${TOGGLE_BUTTON_SELECTOR}`);}functionensureNarrow(){ensureNeededWidth(isNarrowVector,'narrow','Narrowing.',`${STANDARD_WIDTH_RADIO_BUTTON_SELECTOR}, ${TOGGLE_BUTTON_SELECTOR}`);}/* * The main function of the script. */functionrunScript(){/* * Reference documentation about keys and values in mw.config: * https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#mw.config */if(!mw.config.get('wgIsArticle')){// This variable is badly named -- it is not related to a page being a main namespace "article".info('Not a wiki page.');ensureWide();return;}if(mw.config.get('wgDiffNewId')!=null||mw.config.get('wgDiffOldId')!=null){info('Diff view.');ensureWide();return;}constnamespaceNumber=mw.config.get('wgNamespaceNumber');if(namespaceNumber===-1){info('This is a "Special:" page.');ensureWide();return;}constcontentModel=mw.config.get("wgPageContentModel");// ['javascript', 'css', 'sanitized-css', 'Scribunto'].includes(contentModel)if(contentModel!=='wikitext'){info('Content model of the page is for source code (Lua, JS, CSS, etc).');ensureWide();return;}info('Assuming wiki page.');ensureNarrow();}functionwait(message){info(message);setTimeout(lazyLoadVectron,200);}functionrememberMentionHash(){constparams=newURLSearchParams(document.location.search);if(params.get('markasread')!==null){mentionHash=document.location.hash;info('Remembered comment hash:',mentionHash);}}/* * Infrastructure to ensure the script can run. */functionlazyLoadVectron(){debug('Loading...');constskinId=mw.config.get("skin");if(skinId===null){wait('Skin is not loaded yet. Waiting...');return;}if(skinId!=='vector-2022'){warn(`Skin ${skinId} is not supported by the script. Aborting.`);return;}constanyControl=document.querySelector(ANY_CONTROL_SELECTOR);if(anyControl===null){wait('The UI controls are not loaded yet. Waiting...');return;}constbutton=getLimitedWidthToggleButton();if(button!==null){consttheAttribute=button.getAttribute('data-event-name');if(theAttribute===null){wait('Attribute "data-event-name" of the toggle button is not loaded yet. Waiting...');return;}}runScript();}rememberMentionHash();if(document.readyState!=='loading'){lazyLoadVectron();}else{warn('Cannot load yet. Setting up a listener...');document.addEventListener('DOMContentLoaded',lazyLoadVectron);}})();// </nowiki>