Benutzer:DeirdreAnne/common.js

aus Wikisource, der freien Quellensammlung

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
/* global $, mw, pathoschild */

importScript('User:Inductiveload/InlinePagenums.js');

importScript('User:Inductiveload/Metadata_form.js');

importScript('User:Inductiveload/Roman numerals.js');
importScript('User:Inductiveload/Running header.js');

importScript('User:Inductiveload/Visibility.js');

// MOST OF THIS IS COPIED STRAIGHT FROM USER:BILLINGHURST/MONOBOOK.JS
popupFixDabs=true; /* No idea what this does */
popupAdminLinks=true; /* I'm guessing this is admin specific */

// == THIS AUTOFILLS SOME OF THE PARAMETERS IN THE AUTHOR HEADER ==
importScript('User:Phe/Author fill.js');

// == THIS SEARCHES FOR WORKS ABOUT THE AUTHOR IN CERTAIN REFERENCES BUT IF THERE AREN'T ANY IT JUST ADDS AN EDIT SUMMARY - IT IS IMPLEMENTED BELOW ==
importScript('User:Phe/Works about.js');

//JSconfig.keys['HotCatEditBoxWidth'] = 80; //sets width of HotCat gadget

// == IMPORT SOME SCRIPTS - MAINLY TWINKLE - FROM ENWIKI ==
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:AzaToth/twinklefluff.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:AzaToth/twinklediff.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:AzaToth/twinkleprotect.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:AzaToth/twinkleunlink.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:AzaToth/twinklebatchdelete.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:AzaToth/twinklebatchprotect.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:AzaToth/twinklebatchundelete.js&action=raw&ctype=text/javascript');

// == IMPORT FRIENDLY FROM ENWIKI ==
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');

// === FRIENDLY SETTINGS ===
if( typeof( FriendlyConfig ) == 'undefined' ) FriendlyConfig = {}; // DO NOT REMOVE THIS LINE - ALL FRIENDLY SETTINGS AFTER THIS
FriendlyConfig.groupByDefault			=	true;
/*FriendlyConfig.insertHeadings			=	true;*/
FriendlyConfig.insertSignature			=	true;
/*FriendlyConfig.insertUsername			=	true;*/
FriendlyConfig.markTaggedPagesAsMinor		=	true;
FriendlyConfig.markTaggedPagesAsPatrolled	=	true;
FriendlyConfig.markTalkbackAsMinor		=	true;
FriendlyConfig.markWelcomesAsMinor		=	false;
FriendlyConfig.maskTemplateInSummary		=	true;
FriendlyConfig.quickWelcomeMode		=	"semiauto";
FriendlyConfig.quickWelcomeTemplate		=	"Welcome";
FriendlyConfig.summaryAd			=	" using [[w:WP:FRIENDLY|Friendly]]";
FriendlyConfig.talkbackHeading			=	"== Talkback ==";
FriendlyConfig.topWelcomes			=	true;
FriendlyConfig.watchTaggedPages		=	false;
FriendlyConfig.watchWelcomes			=	false;
FriendlyConfig.welcomeHeading			=	"== Welcome ==";

FriendlyConfig.customWelcomeList	=	[
		{
			label: '{{Welcome}}: Welcome for account holders',
			value: 'CustomWelcome' },
		{
			label: '{{Welcomeip}}: Welcome for IP addresses',
			value: 'subst:Welcomeip' }
/*,
		{
			label: '{{CustomWelcome}}: Custom welcome template description (now includes parameters!)',
			value: 'CustomWelcome|para=value' }*/
	];

// == GLOBAL PARAMETERS == /*most from User:Billinghurst/monobook.js - those I don't need I'm keeping as models*/
/*set some global parameters for selection */
//preset variables, REMINDER THAT THESE HAVE UNDERSCORE WORD SEPARATORS for location.href
   var isUserNS = (-1 != location.href.indexOf("User_talk:"));
   var isPageNS = (-1 != location.href.indexOf("Page:"));
   var isAuthorNS = (-1 !== location.href.indexOf("Author:")); /*why double ==?*/
   var isAgrippa = (-1 != location.href.indexOf("Page:[\w\_]+Occult_Philosophy")); /*not sure if I'll use this but it's a long project*/
   var isIndianBio = (-1 != location.href.indexOf("Page:The_Indian_Biographical_Dictionary.djvu/"));/*model only*/
   var isIrishBio = (-1 != location.href.indexOf("Page:A_Compendium_of_Irish_Biography"));/*model only*/
   var isBiography = (-1 != location.href.indexOf("Page:[\w\_]+Biography"));
   var isDNB00 = (-1 != location.href.indexOf("DNB00"));
   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):/));

// == SIDEBAR SCRIPTS /*I prefer the cleanness of a portlet like en:User:Jsimlo/shortcuts, I wonder if that's possible*/ ==
/**
 * 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() {
	// === CALLS FOR USE IN ALL NAMESPACES ===
	pathoschild.TemplateScript.add([
		{
			name: 'clean up',
			script: cleanup
		}
	]);
	
	// === CALLS FOR USE IN THE PAGESPACE ===
	if(isPageNS) {
		pathoschild.TemplateScript.add([
			{
				name: 'Indent',
				script: function(editor) {
					editor.forField('#wpHeaderTextbox')
						.replace(/(<div class="pagetext">)/g, '<div class="pagetext" style="text-indent:1em;">');
				}
			},
			{
				name: 'IndianBio',
				enabled: isIndianBio,
				script: function(editor) {
					// Page:The Indian Biographical Dictionary.djvu tools
					// cleanup for Page:The Indian Biographical Dictionary.djv
					
					editor.forField('#wpHeaderTextbox')
						.append('{{center|INDIAN BIOGRAPHICAL DICTIONARY, 1915.}}\n\n{{sc|}}');
					
					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');
				}
			},
			{
				name: 'Anchor',
				enabled: isBiography,
				script: function(editor) {
					// applies {{anchor+}}
					// Page:A Compendium of Irish Biography tools
					editor.replaceSelection(function(pre) {
						return '{{anchor+|'+pre+'}}';
					});
				}
			},
			{
				name: 'internal nslink',
				enabled: isBiography,
				script: function(editor) {
					//set to internal namespace link, set specifically for subpage xref
					editor.replaceSelection(function(pre) {
						return '{{namespace link|'+pre+'|'+pre+'|..}}';
					});
				}
			},
			{
				name: 'djvu pagelink',
				enabled: isBiography,
				script: function(editor) {
					//adds template 'DJVU page link'
					editor.replaceSelection(function(pre) {
						var work = isIrishBio ? 24 : '';
						return '{{DJVU page link|'+pre+'|'+work+'}}';
					});
				}
			},
			{
				name: 'Header',
				script: function(editor) {
					// PAGE NAMESPACE  headerbox or footerbox	
					// puts {{RunningHeader}} in to headerbox
					editor.forField('#wpHeaderTextbox')
						.append('{{RunningHeader|||}}');
				}
			},
			{
				name: 'Footer',
				script: function(editor) {
					//*Footerbox app; for archaic books where the first word on the next page is placed at bottom
					editor.forField('#wpFooterTextbox')
						.replace(/(<\/div>)/, '{{RunningHeader|||}}$1');
				}
			},
			{
				name: 'nop',
				script: function(editor) {
					// nop, though it puts it at the bottom of editbox, so only useful in Page:
					editor.append('\n{{nop}}');
				}
			},
			{
				name: 's to ſ',
				script: function(editor) {
					editor.replace(/s(?![\Wf])/g, 'ſ');
				}
			},
			{
				name: 'ſ to {{ls}}',
				script: function(editor) {
					editor.replace(/ſ/g, '{{ls}}');
				}
			},
			{
				name: 'ct to ƈt',
				script: function(editor) {
					editor.replace(/ct/g, 'ƈt');
				}
			},
			{
				name: 'ƈt to {{ct}}',
				script: function(editor) {
					editor.replace(/ƈt/g, '{{ct}}');
				}
			}
		]);
	}
	
	// === CALLS FOR USE IN THE MAIN NAMESPACE ===
	if(isMainspace) {
		pathoschild.TemplateScript.add([
			{
				name: 'DefSort Subpage',
				script: function(editor) {
					editor.append('{{DEFAULTSORT:common.js}}');
				}
			},
			{
				name: 'DNBset',
				script: function(editor) {
					// replaces {{header}} with {{DNBset}}
					editor.replace(/\{\{header[^\}]+\}\}\n/, '{{subst:DNBset\n |article= \n |previous= \n |next= \n |volume = \n |contributor = \n |wikipedia = \n |extra_notes= \n |from= \n |to= \n |section= \n}}');
				},
				enabled: isDNB00
			},
			//{
			//	name: 'override transl',
			//	script: otranslator // I don't see any script for this to call
			//},
			{
				name: 'remove TQ',
				script: function(editor) {
					// removes {{TextQuality}}
					editor.replace(/\{\{TextQuality\|\d{2,3}%\}\}/, '');
				}
			},
			{
				name: '{{similar}}',
				script: function(editor) {
					// adds {{similar}} above header
					editor
						.replace(/\{\{header/g, '{{similar|}}\n{{header')
						.appendEditSummary('{{similar}}');
				}
			},
			{
				name: 'Ch.prev & next',
				script: function(editor) {
					// from {{header}} section, wikis Chapter -1/+1 to Prev/Next
					var newtitle = parseInt(mw.config.get('wgTitle').replace(/^.*\/Chapter (\d+)$/,'$1'))-1;
					var headerprevious = '[[../Chapter '+newtitle+'/]]';
					var newtitle = parseInt(mw.config.get('wgTitle').replace(/^.*\/Chapter (\d+)$/,'$1'))+1;
					var headernext = '[[../Chapter '+newtitle+'/]]';
					editor.replace(/\| previous   \= \n \| next       \= /, '| previous   \= ' + headerprevious +'\n \| next       \= ' + headernext);
				}
			},
			{
				name: 'Pages',
				script: function(editor) {
					// subst: #tag and some fields
					// applies <pages> using #tag and  index {{BASEPAGENAME}} fromsection tosection take {{SUBPAGENAME}}
					editor.replaceSelection('{{subst:#tag:pages||index="{{subst:BASEPAGENAME}}.djvu"|from=|to=|fromsection="{{subst:SUBPAGENAME}}"|tosection="{{subst:SUBPAGENAME}}"}}');
				}
			}
		]);
	}
	
	// === CALLS FOR USE IN THE USER NAMESPACE ===
	if(isUserNS) {
		pathoschild.TemplateScript.add([
			{
				name: 'welcome',
				script: function(editor) {
					// applies {{welcome}}
					editor
						.append('{{welcome}} ~~' + '~~')
						.appendEditSummary('welcome');
				}
			},
			{
				name: 'welcomeip & test',
				script: function(editor) {
					// subst {{welcomeip}} applies {{test}}
					editor
						.append('{{subst:' + 'welcomeip}} ~~' + '~~\n{{test}}')
						.appendEditSummary('welcome & test');
				}
			},
			{
				name: 'welcomeip',
				script: function(editor) {
					// subst {{welcomeip}}
					editor
						.append('{{subst:' + 'welcomeip}} ~~' + '~~')
						.appendEditSummary('welcome');
				}
			},
			{
				name: 'toggle in Page:',
				script: function(editor) {
					//subst: User:Billinghurst/HeaderToggle which tells how to toggle header in Page:
					editor.append('{{subst:' + 'User:Billinghurst/HeaderToggle}}');
				}
			}
		]);
	}
});

// == SCRIPTS ==
//ALL NAMESPACE USE
function cleanup(editor) {
	// all sorts of text cleaning from OCR
	editor
		// Digitized by Google (kill)
		.replace(/Digitized[\s\n]+by[\s\n]+Google/, '')
		
		// remove trailing spaces at the end of each line
		.replace(/ +\n/g, '\n')
		
		// remove trailing whitespace preceding a hard line break
		.replace(/ +<br *\/?>/g, '<br />')
		
		// remove trailing whitespace at the end of page text
		.replace(/\s+$/g, '')
		
		// remove trailing spaces at the end of refs
		.replace(/ +<\/ref>/g, '</ref>')
		
		// remove trailing spaces at the end of template calls
		.replace(/ +}}/g, '}}')
		
		// convert double-hyphen to mdash (avoiding breaking HTML comment syntax)
		.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:— ",
		// bearing in mind that the space will already be gone if at end of line).
		.replace(/ +— +/g, '—')
		
		// join words that are hyphenated across a line break
		// (but leave "|-" table syntax alone)
		.replace(/([^\|])-\n/g, '$1');
	
	// stuff to do only if the page doesn't contain a <poem> tag:
	if (editor.get().indexOf("<poem>") != -1) {
		editor
			// remove single line breaks; preserve multiple.
			// but not if there's a tag, template or table syntax either side of the line break
			.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')
		
		// "U" -> "ll" when preceded by a lowercase letter.
		.replace(/([a-z])U/g, '$1ll');
}

// == CUSTOM TABS ==
// === Adds a tab for soft redirects below "move" ===
 /* Soft redirect */
    /* See [[WS:SCRIPTS]]; adds "soft redirect" tab in Firefox. */
       mw.loader.load('//en.wikisource.org/w/index.php?title=User:Bookofjude/softredirect.js&action=raw&ctype=text/javascript');

// === TWINKLE TABS ===
 /* Twinkle and Friendly add several tabs under a "TW" dropdown, they are controlled by imported scripts */

// == CUSTOM BUTTONS ==
/*Import from subpage*/
importScript('User:Doug/custombuttons.js');