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.
classVisualEditorParameter{element;constructor(el){this.element=el;}getname(){// get first child, its first child, and the innerTextreturnthis.element.children[0].children[0].textContent??'';}setValue(val){// set value of the input elementconstel=this.element.children[2].children[0].children[0];if(el.value.toString().length===0){el.value=val;}}focus(){// focus the input elementconstel=this.element.children[2].children[0].children[0];el.focus();}}/** * Finds a parameter by name in the given parameters array. * @param {VisualEditorParameter[]} params the list of params * @param {string} name the name of the parameter to find * @return {VisualEditorParameter | undefined} the parameter with the given name, or null if not found */functionfindParam(params,name){// find the parameter with the given namereturnparams.find((param)=>param.name===name);}document.addEventListener('paste',(event)=>{constpastedInput=event.target;if(!pastedInput){return;}// Ensure the paste is happening in an input elementif(!(pastedInputinstanceofHTMLInputElement)){console.log('Pasted input is not an HTMLInputElement.');return;}// Get the pasted text from the clipboardconstpastedText=event.clipboardData?.getData('text/plain')||'';letdate='';leturl='';// Ensure the pasted text is a "web.archive.org" linkif(pastedText.startsWith('https://web.archive.org/web/')){url=pastedText.replace(/https:\/\/web\.archive\.org\/web\/\d{14}\//,'');consttimestampMatch=/https:\/\/web\.archive\.org\/web\/(\d{14})\//.exec(pastedText);if(timestampMatch){consttimestamp=timestampMatch[1];// Get the timestamp (14 digits)if(!timestamp){return;}constyear=timestamp.slice(0,4);constmonth=timestamp.slice(4,6);constday=timestamp.slice(6,8);// Create the YYYY-MM-DD date stringdate=`${year}-${month}-${day}`;}}elseif(pastedText.startsWith('https://archive.today/')||pastedText.startsWith('http://archive.today/')){// must match http://archive.today/2013.08.02-201601/url_to_useurl=pastedText.replace(/https?:\/\/archive\.today\/\d{4}\.\d{2}\.\d{2}-\d{6}\//,'');consttimestampMatch=/https?:\/\/archive\.today\/(\d{4}\.\d{2}\.\d{2})-\d{6}\//.exec(pastedText,);if(timestampMatch){date=timestampMatch[1].replaceAll('.','-');// Get the date (YYYY.MM.DD)}else{console.error('Invalid date format in archive.today URL.');return;// Exit if the date format is invalid}}else{console.error('Pasted text is not a web.archive.org nor archive.today link.');return;// Exit if it's not a valid Web Archive URL}constparameters=Array.from(document.querySelectorAll('.ve-ui-mwParameterPage')).map((el)=>newVisualEditorParameter(el),);// Simplify the repetitive DOM access to a single constantconsturlInput=findParam(parameters,'URL');constarchiveUrl=findParam(parameters,'Archive URL');constarchiveDate=findParam(parameters,'Archive date');if(urlInput){urlInput.setValue(url);setTimeout(()=>{urlInput.focus();},50);}else{console.error('URL parameter not found.');}if(archiveDate){archiveDate.setValue(date);setTimeout(()=>{archiveDate.focus();},100);}else{console.error('Archive Date parameter not found.');}setTimeout(()=>{archiveUrl.focus();},200);});