User:Krenakarore/common.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 */ // $.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function {	/**********	** Register scripts	*********/	pathoschild.TemplateScript.add([ { name: 'fix dashes', script: dashes }, { name: 'cleanup', script: cleanup }, { name: 'both', script: both }, { name: 'ref', script: ref }, { name: 'author', script: author }, { name: 'welcome & test', script: weliptest }, { name: '', script: similar }, { name: 'DNBset', script: DNBset } ]);

/**********	** Define scripts *********/	function dashes(editor) { editor.replace(/--/g, '—'); }	function author(editor) { // creates an author: link from selected text editor.replaceSelection(function(name) {			return +name+;		}); }	function cleanup(editor) { editor // remove trailing whitespace at the end of each line .replace(/ \n/g, '\n') // remove trailing whitespace at the end of input .replace(/\s+$/g, '') // convert double-hyphen to mdash .replace(/--/g, '—') // remove spacing around mdash, but only if it has spaces on both sides // (we don't want to remove the trailing space from "...as follows:— "			.replace(/ +— +/g, '—')			// join words that are hyphenated across a line break			.replace(/-\n/g, '');		// stuff to do only if the page doesn't contain a tag:		if (editor.get.indexOf(" ") === -1) {			editor				// remove single line breaks; preserve multiple.				.replace(/([^>\n])\n([^<\n])/g, '$1 $2')				// collapse sequences of spaces into a single space				.replace(/ +/g, ' ');		}		editor			// remove unwanted spaces around punctuation marks			.replace(/ ([;:\?!,])/g, '$1')			//OCR fixes			// convert i9 to 19, etc.			.replace(/[il]([0-9])/g, '1$1')			// "the", "them", "their", etcetera			.replace(/tlie/g, 'the');	}	function both(editor) {		editor.forField('#wpHeaderTextbox')			.append('\n');	}	function ref(editor) {		editor.forField('#wpFooterTextbox')			.replace(' ','\n');	}	function weliptest(editor) {		editor.forField('#wpHeaderTextbox') .append('-- ' + '\n'); editor.appendEditSummary('welcome & test'); }	function similar(editor) { editor .replace(/\{\{header/g, '\n{{header') .appendEditSummary(''); }	function DNBset(editor) { editor.replace(/\{\{header\n \| title     \=.+\n \| author     \= \n \| translator \= \n \| section    \= \n \| previous   \= \n \| next       \= \n \| notes      \= \n\}\}\n/, ''); } }); //

self.proofreadpage_disable_wheelzoom = false; popupFixDabs=true; popupAdminLinks=true;

if (mw.toolbar) { $('#wpTextbox1').wikiEditor('addToToolbar', {		section: 'main',		group: 'format',		tools: {			'custom-rule': {				label: 'rule',				type: 'button',				icon: '//upload.wikimedia.org/wikipedia/commons/4/41/Button_hr_halfwidth.png',				action: {					type: 'encapsulate',					options: {						pre: ,						post: ,						sampleText: 					}				}			},			'custom-Larger': {				label: 'Larger',				type: 'button',				icon: '//upload.wikimedia.org/wikipedia/commons/2/28/Bouton_noir.png',				action: {					type: 'encapsulate',					options: {						pre: ,						post: ,						sampleText: 					}				}			},			'custom-Sm': {				label: 'Sm ',				type: 'button',				icon: '//upload.wikimedia.org/wikipedia/commons/8/83/Bouton_noir_mini.png',				action: {					type: 'encapsulate',					options: {						pre: ,						post: ,						sampleText: ''					}				}			},			'custom-Centre text': {				label: 'Centre text', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/5/5f/Button_center.png', action: { type: 'encapsulate', options: { pre: '', post: '', sampleText: '' }				}			},			'custom-Author link': { label: 'Author link', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/8/83/Button_biocitas.png', action: { type: 'encapsulate', options: { pre: 'Author:',						post: '', sampleText: '' }				}			},			'custom-Reference': { label: 'Reference', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/c/c4/Button_ref.png', action: { type: 'encapsulate', options: { pre: ' ', sampleText: '' }				}			},			'custom-sc': { label: 'sc ', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/a/a2/SmallcapsButton.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-f/sc': { label: 'f/sc ', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/4/4e/Button_romain.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-hws ': { label: 'hws ', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/4/41/Button_hr_halfwidth.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-hwe': { label: 'hwe ', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/4/41/Button_hr_halfwidth.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-S/n beg': { label: 'S/n beg ', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/c/c0/Knop_onzijdig.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-S/n end': { label: 'S/n end ', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/c/c0/Knop_onzijdig.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-Force s/n': { label: 'Force s/n', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/8/8d/Button_image_annotation.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-section begin': { label: 'section begin', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/thumb/7/71/Progress-0625.svg/20px-Progress-0625.svg.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-br': { label: ' br ', type: 'button', icon: '//upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png', action: { type: 'encapsulate', options: { pre: ' \n', post: '', sampleText: '' }				}			},			'custom-section end': { label: 'section end', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/thumb/8/83/Progress-0750.svg/20px-Progress-0750.svg.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-—': { label: ' — ', type: 'button', icon: '//bits.wikimedia.org/skins-1.5/common/images/button_hr.png', action: { type: 'encapsulate', options: { pre: '—', post: '', sampleText: '' }				}			},			'custom-Poem': { label: 'Poem', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/8/8f/Button_poeme.png', action: { type: 'encapsulate', options: { pre: ' ', post: ' ', sampleText: '' }				}			}		}	}); }

// Auto create page when requesting a non existent Page:*, inefficient since there is // two request per page, see setupNextLink which avoid it in most case. if (mw.config.get('wgCanonicalNamespace') == 'Page') { $(function autoCreatePage {		if (mw.config.get('wgArticleId') === 0 && mw.config.get('wgAction') === 'view') {			url = document.URL.slice((mw.config.get('wgServer') + '/wiki/').length);			url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + url + '&action=edit';			window.location = url;		}	}); }

// when acting on a Page:* setup the next link to edit mode if the next page doesn't exist. if (mw.config.get('wgCanonicalNamespace') == 'Page') { $(function setupNextLink {		ca_next = document.getElementById('ca-next');		if (!ca_next) return;		href = ca_next.firstChild;		if (!href) return;		var r = new RegExp("page(\\d+)");		page = Number(r.exec(proofreadPageViewURL)[1]) + 1;		next_page = mw.config.get('wgPageName').replace(/\d+$/g, page);		var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath')			+ "/api.php?format=xml&action=query&prop=info&titles="			+ encodeURIComponent(next_page);		var request = sajax_init_object;		request.open('GET', url, true);		request.onreadystatechange = function {		if (request.readyState == 4) {			var xml = request.responseXML ;			if (xml === null) return ;			var page = xml.getElementsByTagName( "page" )[0];			if (page.getAttribute("missing") == "")				href.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + encodeURIComponent(next_page) + '&action=edit'; }		};		request.send(null); }); }

/* */