User:Ryuch/common.js

mw.loader.load('//en.wikipedia.org/w/index.php?title=User:AzaToth/morebits.js&action=raw&ctype=text/javascript'); mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Ioeth/friendlytag.js&action=raw&ctype=text/javascript'); mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Ioeth/friendlytalkback.js&action=raw&ctype=text/javascript');

// wiktionary Popup mw.loader.load('//en.wikinews.org/w/index.php?title=MediaWiki:Gadget-dictionaryLookupHover.js&action=raw&ctype=text/javascript');

// set some global parameters for selection var isIndianBio = (-1 != location.href.indexOf("Page:The_Indian_Biographical_Dictionary.djvu/")); var isIrishBio = (-1 != location.href.indexOf("Page:A_Compendium_of_Irish_Biography")); var isCollins = (-1 != location.href.indexOf("Page:An_account_of_the_English_colony")); var isDNB00 = (-1 != location.href.indexOf("DNB00")); var isCopyright = (-1 != location.href.indexOf("Page:Copyright_Act")); var isMainspace = (-1 == location.href.search(/title=(Talk|User|User_talk|Wikisource|Wikisource_talk|File|File_talk|Mediawiki|Mediawiki_talk|Template|Template_talk|Help|Help_talk|Category|Category_talk|Portal|Portal_talk|Author|Author_talk|Page|Page_talk|Index):/));

/** * 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([ // all pages { name: 'Rh', script: RunningHeader }, { name: 'clean up', script: cleanup }, { name: 'nop', script: nop }, { name: 'DefSort Subpage', script: defsortsubpage }, { name: 'Join lines', script: joinlines }, // An account of the English colony { name: 'Float poem', script: floatpoem, enabled: isCollins }, { name: 'Collins cleanup', script: Collins_cleanup, enabled: isCollins }, // Copyright Act { name: 'Ch74 left', script: copyheadch74, enabled: isCopyright }, { name: '4and5 left', script: copyhead45, enabled: isCopyright }, // DNB00 { name: 'DNBset', script: DNBset, enabled: isDNB00 }, // Indian Biographical Dictionary { name: 'IndianBio', script: IndianBio, enabled: isIndianBio }, // A Compendium of Irish Biography { name: 'Anchor', script: anchor, enabled: isIrishBio }, { name: 'internal nslink', script: nslink, enabled: isIrishBio }, { name: 'djvu pagelink', script: djvupagelink, enabled: isIrishBio }, // main namespaces { name: 'override transl', script: trans, enabled: isMainspace }, { name: 'remove TQ', script: rmTextQual, enabled: isMainspace }, { name: '', script: similar, enabled: isMainspace }, { name: 'Ch.prev & next', script: PrevNext, enabled: isMainspace }, { name: 'Pages', script: tag_pages, enabled: isMainspace }, // user namespace { name: 'welcome', script: welcome, forNamespaces: 'user talk' }, { name: 'welcomeip & test', script: weliptest, forNamespaces: 'user talk' }, { name: 'welcomeip', script: welcomeip, forNamespaces: 'user talk' }, { name: 'toggle in Page:', script: HeaderToggle, forNamespaces: 'user talk' } ]);	//USER TALK namespace	// welcome applies 	// weliptest subst applies 	// welcomeip subst 	// HeaderToggle subst: User:Billinghurst/HeaderToggle which tells how to toggle header in Page:	function welcome(editor) {		editor			.append(' ~')			.appendEditSummary('welcome');	}	function weliptest(editor) {		editor			.append(' ~\n')			.appendEditSummary('welcome & test');	}	function welcomeip(editor) {		editor			.append(' ~')			.appendEditSummary('welcome');	}	function HeaderToggle(editor) {		editor.append();	}	//MAIN namespace	// DNBset - replaces  with 	// rmTextQual removes 	// trans replaces translator with override_translator	// similar adds  above header	// PrevNext from  section, wikis Chapter -1/+1 to Prev/Next	// tag_pages applies using #tag and  index  fromsection tosection take 	// defsortsubpage	function DNBset(editor) {		editor.replace(/\{\{header[^\}]+\}\}\n/, ); }	function rmTextQual(editor) { editor.replace(/\{\{TextQuality\|\d{2,3}%\}\}/, ''); }	function trans(editor) { editor.replace(/ translator\w+\=/, ' override_translator = '); }	function similar(editor) { editor .replace(/\{\{header/g, '\n{{header') .appendEditSummary(''); }	function PrevNext(editor) { var newtitle = parseInt(mw.config.get('wgTitle').replace(/^.*\/Chapter (\d+)$/,'$1'))-1; var headerprevious = '../Chapter '+newtitle+' /'; var headernext = '../Chapter '+newtitle+' /'; editor.replace(/\| previous  \= \n \| next       \= /, '| previous   \= ' + headerprevious +'\n \| next       \= ' + headernext); }	//subst: #tag and some fields function tag_pages(editor) { var pages = ''; editor.replaceSelection(pages); }	function defsortsubpage(editor) { editor.append(''); }	function joinlines(editor){ editor .replace(/[\.!?"] \n([A-Z])/g, "\.\n\n$1")			.replace(/- \n/g, )			.replace(/ \n/g, ' ')			.setEditSummary('hypen del')			.clickDiff;	}	//ALL NAMESPACE USE	// cleanup - all sorts of text cleaning from OCR	// floatpoem - float center, adds tag, and makes smaller	// nop - nop, though it puts it at the bottom of editbox, so only useful in Page:	function cleanup(editor) {		editor			// Digitized by Google (kill)			.replace(/Digitized[\s\n]+by[\s\n]+Google/, )			// 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, '$1—$2')			// 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("\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') // "U" -> "ll" when preceded by a lowercase letter. .replace(/([a-z])U/g, '$1ll'); }	// Takes poetic text, makes it float center, adds tag, and makes font-size:smaller function floatpoem(editor) { editor.replaceSelection(function(pre) {			return '';		}); }	// nop at bottom of editbox function nop(editor) { editor.append('\n'); }	//SPECIFIC TO Page: namespace // IndianBio - cleanup for Page:The Indian Biographical Dictionary.djv // anchor - applies // RunningHeader - puts in to headerbox // endword - puts into footerbox // smallrefs_rep - puts into footerbox /* Page:The Indian Biographical Dictionary.djvu tools */ function IndianBio(editor) { editor.forField('#wpHeaderTextbox').append('INDIAN BIOGRAPHICAL DICTIONARY, 1915.\n\n'); cleanup(editor); editor .replace(/([\n\s])([bmsd]\.)/g, '$1\'\'$2\'\'') .replace (/([\n\s])(Address|Clubs?|educ|Publications|Recreations)\:/g, '$1\'\'$2\'\':') .replace (/CLE\.?/g, 'C.I.E.') // VU -> VII; followed by U in the middle of a word -> ll			.replace(/VU/g, 'VII') .replace(/(\w)U(\w)/, '$1ll$2'); }	/* Page:A Compendium of Irish Biography tools */ function anchor(editor) { editor.replaceSelection(function(pre) {			return '';		}); }	//adds template 'DJVU page link' function djvupagelink(editor) { editor.replaceSelection(function(pre) {			var work = isIrishBio ? 24 : ;			return ;		}); }	//set to internal namespace link, set specifically for subpage xref function nslink(editor) { editor.replaceSelection(function(pre) {			return '';		}); }	//PAGE NAMESPACE headerbox or footerbox function RunningHeader(editor) { editor.forField('#wpHeaderTextbox').append(''); }	//*Footerbox app; for archaic books where the first word on the next page is placed at bottom function endword(editor) { editor.forField('#wpFooterTextbox').replace(/(<\/div>)/,'$1'); }	function smallrefs_rep(editor) { editor.forField('#wpFooterTextbox').replace(/()/,''); }	//merge cleanup function Collins_cleanup(editor) { RunningHeader(editor); endword(editor); smallrefs_rep(editor); }	function copyhead45(editor) { editor.forField('#wpHeaderTextbox').append(""); editor.forField('#wpFooterTextbox').replace(/(<\/div>)/,'$1'); }	function copyheadch74(editor) { editor.forField('#wpHeaderTextbox').append(""); editor.forField('#wpFooterTextbox').replace(/(<\/div>)/,'$1'); }	}); //

if (mw.toolbar) { $('#wpTextbox1').wikiEditor('addToToolbar', {		section: 'main',		group: 'format',		tools: {			'custom-spm': {				label: 'spm',				type: 'button',				icon: ,				action: {					type: 'encapsulate',					options: {						pre: '{{float center|',						post: ,						sampleText: 					}				}			},			'custom-Wikipedia link': {				label: 'Wikipedia link',				type: 'button',				icon: '//upload.wikimedia.org/wikipedia/commons/7/7f/Button_link_to_Wikipedia.png',				action: {					type: 'encapsulate',					options: {						pre: 'w:',						post: ,						sampleText: 					}				}			},			'custom-Larger': {				label: 'Larger',				type: 'button',				icon: '//upload.wikimedia.org/wikipedia/commons/5/56/Button_big.png',				action: {					type: 'encapsulate',					options: {						pre: ,						post: ,						sampleText: 					}				}			},			'custom-Sm': {				label: 'Sm ',				type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: '', post: '', sampleText: '' }				}			},			'custom-f/s': { label: 'f/s ', type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: '', 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/7/79/Button_reflink.png', action: { type: 'encapsulate', options: { pre: ' ', sampleText: '' }				}			},			'custom-sc': { label: 'sc ', type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-hws': { label: 'hws ', type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-hwe': { label: 'hwe ', type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-br': { label: 'br ', type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: ' ',						post: '', sampleText: '' }				}			},			'custom-section begin': { label: 'section begin', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/0/06/Tag_green.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-section end': { label: 'section end', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/d/dd/Tag_red.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-pg': { label: 'pg ', type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-bk': { label: 'bk ', type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: '\'\,						post: '\'\, sampleText: '' }				}			},			'custom-A/L': { label: 'A/L ', type: 'button', icon: '', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},			'custom-Force s/n': { label: 'Force s/n', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/c/cf/Left.png', action: { type: 'encapsulate', options: { pre: '', sampleText: '' }				}			},		}	});

if (isIrishBio) { $('#wpTextbox1').wikiEditor('addToToolbar', {			section: 'main',			group: 'format',			tools: {				'custom-IBr': {					label: 'IBr ',					type: 'button',					icon: ,					action: {						type: 'encapsulate',						options: {							pre: ,							sampleText: ''						}					}				}			}		}); }

if (isCopyright) { $('#wpTextbox1').wikiEditor('addToToolbar', {			section: 'main',			group: 'format',			tools: {				'custom-DIV1': {					label: 'DIV1 ',					type: 'button',					icon: ,					action: {						type: 'encapsulate',						options: {							pre: ' ',							post: ' ',							sampleText: 						}					}				},				'custom-DIV2': {					label: 'DIV2 ',					type: 'button',					icon: '',					action: {						type: 'encapsulate',						options: {							pre: ' (', post: ' ', sampleText: '' }					}				}			}		});	} } //

//