Jump to content

User:M-le-mot-dit/common.js

From Wikisource
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]]
 */
// <nowiki>
/* CharInsert specific */
// window.charinsertDontMove = true;
window.charinsertMoveTop = true;
// window.editToolsRecall = true;

window.charinsertCustom = {
	"User": ' – — · • ′ ″  Ç Á É ĺ Ó Ú á í ó ú ō  <br./> &nbsp; {{Dhr}} {{Em}} {{Fqm}}'
};

$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add([
		
			// Spaces
			{
			name: 'Spaces',
			position: 'cursor',
			script: function(editor) {
				editor.replace(/ +$/mg, '')
				.replace(/ +<br *\/?>/g, '<br />')
				.replace(/(<ref>|\() +/g, '$1')
				.replace(/ +(<\/ref>|\))/g, '$1')
				.replace(/ ([?!;:,])/g, '$1')
				.replace(/ *— */g, '—')
				.replace(/[-¬] *(\n)([^ \|\n]+)[ \n]/g, '$2$1')
				.replace(/([;:]+)—/g, '{{Nowrap|$1—}}')
				.replace(/  +/g, ' ');
			}
			},

			// straight quotes
			{
			name: 'Quotes',
			position: 'cursor',
			script: function(editor) {
				editor.replace(/[«“] */g, '\"')
				.replace(/ *[»”]/g, '\"')
				.replace(/[‘] */g, '\'')
				.replace(/[`’]/g, '\'')
				.replace(/&quot;/g, '\"')
				.replace(/^(["']) /mg, '$1')
				.replace(/ (["']) *$/mg, '$1');
			}
			},

			// replace _ or -- by —
			{
			name: 'Bars',
			position: 'cursor',
			script: function(editor) {
				editor.replace(/ *___ */g, '{{Bar|3}}')
				.replace(/ *(__|——) */g, '{{Bar|2}}')
				.replace(/ *(_|--) */g, '—')
				.replace(/^——$/gm, '----');
			}
			},

			// Ellipses
			{
			name: 'Ellipses',
			position: 'cursor',
			script: function(editor) {
				editor.replace(/( *)([\.?!]*) *\. *\. *\./g, '$1$2…');
			}
			},

			// Acute accents
/*			{
			name: 'Accents',
			position: 'cursor',
			script: function(editor) {
				editor.replace(/\*a/g, 'á')
				.replace(/\*i/g, 'í')
				.replace(/\*o/g, 'ó')
				.replace(/\*u/g, 'ú')
				.replace(/\*A/g, 'Á')
				.replace(/\*E/g, 'É')
				.replace(/\*I/g, 'ĺ')
				.replace(/\*O/g, 'Ó')
				.replace(/\*U/g, 'Ú');
			}
			}, */

			// Special chars
/*			{
			name: 'Math',
			position: 'cursor',
			script: function(editor) {
				editor.replace(/\*-/g, '−')
				.replace(/\*x/g, '×')
				.replace(/\*\//g, '÷')
				.replace(/\*'/g, '′')
				.replace(/\*"/g, '″')
				.replace(/\*\./g, '·');
			}
			}, */

			// No wrap
/*			{
			name: 'Nowrap',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return '{{Nowrap|' + selected + '}}';
				});
			}
			}, */

			// Sic
			{
			name: 'Sic',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return '{{SIC|' + selected + '|' + selected + '|nodash}}';
				});
			}
			},

			// Convert to lower case
			{
			name: 'To lower',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return selected.toLowerCase();
				});
			}
			},

			// Convert to upper case
			{
			name: 'To upper',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return selected.toUpperCase();
				});
			}
			},

			// Underline
			{
			name: 'Underline',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return '{{Underline|' + selected + '}}';
				});
			}
			},

			// Right
			{
			name: 'Right',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return '{{Right|' + selected + '|2em}}';
				});
			}
			},

			// Cite
			{
			name: 'Cite',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return '{{Block center|{{Fs90|' + selected + '}}}}';
				});
			}
			},

			// Rule
			{
			name: 'Rule (5em)',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return selected + '\n{{Rule|5em|margin_tb=1em}}\n';
				});
			}
			},

			// Inclose with p tag - paragraph break
			{
			name: 'Paragraph break',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					return selected + '\n{{Parabr}}';
				});
			}
			},

			// Author
			{
			name: 'Author',
			position: 'cursor',
			script: function(editor) {
				editor.replaceSelection(function(selected) {
					selected = selected.trim();
					return '[[Author:' + selected + '|' + selected + ']]';
				});
			}
			},

			// add refs to footer
			{
			name: 'Footer—Smallrefs',
			position: 'cursor',
			script: function(editor) {
				editor.forField('#wpFooterTextbox')
				.append('{{Smallrefs}}');
			}
			},

			// add ref block to footer
			{
			name: 'Footer—Ref block',
			position: 'cursor',
			script: function(editor) {
				editor.forField('#wpFooterTextbox')
				.append('{{Block center|{{Smallrefs}}}}');
			}
			},

			// add smaller center to footer
			{
			name: 'Footer—Center',
			position: 'after',
			script: function(editor) {
				editor.forField('#wpFooterTextbox')
				.append('{{Center|{{Smaller|{{subst:#expr: {{subst:SUBPAGENAME}} - 0}}}}}}');
			}
			},

			// add Category to footer
			{
			name: 'Footer—Not trans.',
			position: 'after',
			editSummary: 'Category',
			script: function(editor) {
				editor.forField('#wpFooterTextbox')
				.append('[[Category:Not transcluded]]');
			}
			},

			// Main namespace, smallrefs
			{
			name: 'Main—Refs',
			template: '\n\n{{Smallrefs|rule=yes}}',
			position: 'after',
			forNamespaces: 0
			},

			// Join paragraph
			{
			name: 'Join',
			position: 'cursor',
			script: function(editor) {
			 	editor.replaceSelection(function(selected) {
			 		selected = selected.replace(/ *(\r\n|\n|\r)/gm, ' ');
			 		return selected;
			 	});
			}
			},

			// End of page: nop, peh, upe
			{
			name: 'End of page',
			position: 'cursor',
			script: function(editor) {
				editor.replace(/-[ \n]*$/, '{{peh}}')
				.replace(/—[ \n]*$/, '—{{upe}}')
				.replace(/\+[ \n]*$/, '{{upe}}')
				.replace(/([^}])[ \n]*$/, '$1\n{{Nop}}');
			}
			},
			
			// Form paragraphs
			{
			name: 'Parag.',
			position: 'cursor',
			script: function(editor) {
				editor.replace(/([^>}\n]) *\n([^<{\|\n])/g, '$1 $2')
				.replace(/ *([-—]) */g, '$1')
				.replace(/ {2,}/g, ' ')
				.replace(/[ \n]*$/, '');
			}
			},

	]);
});
// </nowiki>

// Pop-up options
window.popupFixRedirs = true;
window.popupFixDabs = true;

importScript('User:M-le-mot-dit/SpecialChars.js');

importScript('User:M-le-mot-dit/Shortcuts.js');