User:BethNaught/BNUtils.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 * @update-token [[File:Pathoschild/templatescript.js]]
 */
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	
	// Page: NS
	pathoschild.TemplateScript.add([
		{ category: 'BNUtils',
		  name: 'Append {{nop}}',
		  script: function(editor) {
		  	editor.append('\n{{nop}}')
		  }
		},

		{ category: 'BNUtils', 
		  name: 'Blank footer', 
		  script: function(editor) {
		  	editor.forField('#wpFooterTextbox').set("")
		  }
		},

		{ category: 'BNUtils',
		   name: 'Delig. fi, fl',
		   script: function(editor) {
		  	editor.replace(/fi/g, 'fi');
		  	editor.replace(/fl/g, 'fl')
		    }
		 },

		{ category: 'BNUtils',
		  name: 'Despace emdashes',
		  script: function(editor) {
		  	editor.replace(/ —/g, '—');
		  	editor.replace(/— /g, '—');
		  }
		},
		
		{ category: 'BNUtils',
		  name: 'Gen. misc. cleanup',
		  script: function(editor) {
		  	editor.replace(/\n" /g, '\n"');
		  	editor.replace(/\/'/g, ',"')
		  }
		},
		
		{ category: 'BNUtils',
		  name: 'Insert {{bar|2}}',
		  template: '{{bar|2}}',
		  position: 'cursor'
		},

		{ category: 'BNUtils',
		  name: 'Remove first line',
		  script: function(editor) {
		  	editor.replace(/^.*\n/, '');
		  },
		},

		/** Not currently in use
		
		{ category: 'BNUtils',
		  name: 'smaller B.C./A.D.',
		  script: function(editor) {
		  	editor.replace(/(B\.C\.|A\.D\.)/g, '{{smaller|$1}}')
		  }
		}, **/
	],
	{ forNamespaces: 'page' }
	);
	
	// Main NS
	pathoschild.TemplateScript.add([
		{ category: 'BNUtils',
		  name: '<pages>',
		  template: '<pages index="" from= to= />',
		  position: 'cursor'
		},
		
		{ category: 'BNUtils',
		  name: 'break',
		  template: '{{page break|label=}}',
		  position: 'cursor'
		},
		
		{ category: 'BNUtils',
		  name: '{{PD/US}}',
		  template: '{{PD/US|}}',
		  position: 'cursor'
		}
	],
	{ forNamespaces: [0] }
	)
});