User:BethNaught/testing.js

/** * This script facilitates testing of functions I create. * It is not useful unless you want to debug my scripts. */ // Imports: mw.loader.load('//en.wikisource.org/w/index.php?title=User:BethNaught/retrievePagenum.js&action=raw&ctype=text/javascript');

/** * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor. * @see https://meta.wikimedia.org/wiki/TemplateScript * @update-token */ $.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function {	pathoschild.TemplateScript.add([ // to test retrievePagenum.js; Page: NS only { category: 'Test', name: 'retrievePagenum', script: function(editor) { alert(retrievePagenum); },		 forNamespaces: 'page' },		// Put header material on the first line, separate parts with pipes, // and click this to transfer to a RunningHeader. Could be customised // per work by editing exactly how the header is changed. // Currently: Generic { category: 'BN dev', name: 'HeaderHelp', script: function(editor) { var firstLine, parts, numParts, numberRegex, newHeader; firstLine = /^.*\n/.exec(editor.get)[0]; parts = firstLine.split(/ +/).map(x => x.trim); numParts = parts.length; numberRegex = /[0-9]+/; if (numberRegex.test(parts[0])) { newHeader = ''; } else if (numberRegex.test(parts[numParts - 1])) { newHeader = ''; } else { alert('Failed to parse first line as a header, aborting'); return; }		 	editor.forField('#wpHeaderTextbox').set(newHeader); editor.replace(/^.*\n/, ''); },		 forNamespaces: 'page' }	]); });