User:Yodin/common.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.

mw.loader.load('//en.wikisource.org/w/index.php?title=User:Samwilson/CurlyQuotes.js&action=raw&ctype=text/javascript');

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see [[meta:TemplateScript]]
 * @update-token [[File:Pathoschild/templatescript.js]]
 */
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js');

/**
 * 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]]
 */
// <nowiki>
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add({
	name:'Prose format',
	forNamespaces: 'page',
	script: function(editor) {
		editor
			.replace(/([^\n])\n([^\n])/g, '$1 $2')
			.replace(/[ ]+/g, ' ')
			.replace(/(\s|^)\"/g, '$1“')
			.replace(/\"/g, '”')
			.replace(/(\s|^|“)\'/g, '$1‘')
			.replace(/\'/g, '’')
			.replace(/([“‘])\s+/g,'$1')
			.replace(/\s+”/g,'”')
			.replace(/\s+([!?:;,.])/g, '$1')
			.replace(/[ ]+(\n)/g, '$1')
			.replace(/[^\S\r\n]*—[^\S\r\n]*/g, '—')
			.replace(/^\s+/g, '')
			.replace(/\s+$/g, '')
			.replace(/“\s*‘/g,'{{“ ‘}}')
			.replace(/“\s*’/g,'{{“ ’}}')
			.replace(/’\s*”/g,'{{’ ”}}');
	}
});
	pathoschild.TemplateScript.add({
	name:'Poem format (ppoem)',
	forNamespaces: 'page',
	script: function(editor) {
		editor
			.replace(/[^\S\r\n]*(\d+)[^\S\r\n]*(\n)/g,'{{pline|$1|r}}$2')
			.replace(/([^\n])[^\S\r\n]*(<br\/>)*[^\S\r\n]*(\n|$)/g, '$1$3')
			.replace(/[ ]+/g, ' ')
			.replace(/(\s|^)\"/g, '$1“')
			.replace(/\"/g, '”')
			.replace(/(\s|^|“)\'/g, '$1‘')
			.replace(/\'/g, '’')
			.replace(/([“‘])\s+/g,'$1')
			.replace(/\s+”/g,'”')
			.replace(/\s+([!?:;,.])/g, '$1')
			.replace(/[ ]+(\n)/g, '$1')
			.replace(/[^\S\r\n]*—[^\S\r\n]*/g, '—')
			.replace(/^\s+/g, '')
			.replace(/\s+$/g, '')
			.replace(/“\s*‘/g,'{{“ ‘}}')
			.replace(/“\s*’/g,'{{“ ’}}')
			.replace(/’\s*”/g,'{{’ ”}}')
			.replace(/<br>(\n\n)/g,'$1');
	}
});
	pathoschild.TemplateScript.add({
	name:'Typewriter quotations',
	forNamespaces: 'page',
	script: function(editor) {
		editor
			.replace(/[′‘’`]/g, "'")
			.replace(/[“”″]/g, '"');
	}
});
	pathoschild.TemplateScript.add({
	name:'Clear footer',
	forNamespaces: 'page',
	script: function(editor) {
		editor.forField('#wpFooterTextbox').set('');
	}
});
	pathoschild.TemplateScript.add({
	name:'Clear all',
	forNamespaces: 'page',
	script: function(editor) {
		editor.forField('#wpHeaderTextbox').set('');
		editor.set('');
		editor.forField('#wpFooterTextbox').set('');
	}
});
});
// </nowiki>