Usor:PiRSquared17/common.js

E Wikisource

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:PiRSquared17/global.js&action=raw&ctype=text/javascript');
//<pre>
/* Script:  [[m:User:Pathoschild/Scripts/Regex menu framework]]
  * RegexMenuFramework: creates a sidebar menu of user-defined regex tools
  * Documentation: [[m:User:Pathoschild/Scripts/Regex menu framework]]
  * Written by: Pathoschild
  * 
  <source lang="javascript"><nowiki>
*/
// load script
//document.write('<script type="text/javascript" src="'
//  + 'http://meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js' 
//  + '&action=raw&ctype=text/javascript"></script>');
 
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400');
 
// default menu links
function gadget_rmflinks() {
        regexTool('Custom regex','custom()'); // a default tool which performs regex input in a dynamic form
}
/* </nowiki></source> */

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 ==
/* I already have Twinkle imported
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:AzaToth/morebits.js&action=raw&ctype=text/javascript');
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:AzaToth/twinklefluff.js&action=raw&ctype=text/javascript');
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:AzaToth/twinklediff.js&action=raw&ctype=text/javascript');
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:AzaToth/twinkleprotect.js&action=raw&ctype=text/javascript');
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:AzaToth/twinkleunlink.js&action=raw&ctype=text/javascript');
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:AzaToth/twinklebatchdelete.js&action=raw&ctype=text/javascript');
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:AzaToth/twinklebatchprotect.js&action=raw&ctype=text/javascript');
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:AzaToth/twinklebatchundelete.js&action=raw&ctype=text/javascript');
 
// == IMPORT FRIENDLY FROM ENWIKI ==  
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Ioeth/friendlytag.js&action=raw&ctype=text/javascript');
mw.loader.load('https://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("Disputatio_Usoris:"));
   var isPageNS = (-1 !== location.href.indexOf("Pagina:"));
   var isAuthorNS = (-1 !== location.href.indexOf("Scriptor:")); /*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*/ == 
//Pathoschild's regex /*where is this imported?*/
function rmflinks() {
 
// === CALLS FOR USE IN ALL NAMESPACES ===
        regexTool('clean up','cleanup()');
	regexTool('Indent', 'Indent()');
	regexTool('Header', 'RunningHeader()');	
	regexTool('Footer','RunningFooter()');
   	regexTool('nop','nop()'); /* not within the if for pagespace but only functions there */
    	regexTool('s to ſ', 'grab_s()');
    	regexTool('ſ to {{ls}}', 'long_s_replace()');
    	regexTool('ct to ƈt', 'grab_ct()');
    	regexTool('ƈt to {{ct}}', 'ct_replace()');
        regexTool('qz to {{qz}}', 'qz_replace()');
 
// === CALLS FOR USE IN THE PAGESPACE ===
 
    if (isIndianBio) {
        regexTool('IndianBio','IndianBio()');
       } 
    if (isBiography) {
        regexTool('Anchor','anchor()');
        regexTool('internal nslink','nslink()');
        regexTool('djvu pagelink','djvupagelink()');
       }
 
// === CALLS THAT IMPLEMENT ONLY IN THE APPROPRIATE NAMESPACE ===
    if (isMainspace) {
	    regexTool('DefSort Subpage','defsortsubpage()');
    	if (isDNB00) {
        	regexTool('DNBset','DNBset()');
       	} 	
        regexTool('override transl','otranslator()'); /* I don't see any script for this to call */
        regexTool('remove TQ','rmTextQual()');
        regexTool('{{similar}}','similar()');
        regexTool('Ch.prev & next','PrevNext()');
        regexTool('Pages','tag_pages()'); /* I can't tell what this does */
    } else /*why "else" here?*/
 
	if (isPageNS) {	
		regexTool('Header', 'RunningHeader()');	
		regexTool('Footer','RunningFooter()');
   		regexTool('nop','nop()'); /* not within the if for pagespace but only functions there */
    	regexTool('s to ſ', 'grab_s()');
    	regexTool('ſ to {{ls}}', 'long_s_replace()');
    	regexTool('ct to ƈt', 'grab_ct()');
    	regexTool('ƈt to {{ct}}', 'ct_replace()');
        regexTool('qz to {{qz}}', 'qz_replace()');
	}  
 
    if (isUserNS) {
        regexTool('Salve','salve()');
        regexTool('welcomeip & test','weliptest()');
        regexTool('welcomeip','welcomeip()');
        regexTool('toggle in Page:', 'HeaderToggle()');
    } 
 
    if (isAuthorNS) {
        regexTool('Works about', 'works_about()');
    }
 
// === THESE SCRIPTS BELOW APPEAR TO HAVE NO CALLS ===
//trans()
//und2ital()
//chapcase()
//endword() /*this has been replaced with RunningFooter()*/
//smallrefs_rep()
//header_center()	   
}
 
// == SCRIPTS ==
 
//USER TALK namespace
// salve() applies {{salve}}
// weliptest() subst {{welcomeip}} applies {{test}}
// welcomeip() subst {{welcomeip}}
// HeaderToggle() subst: User:Billinghurst/HeaderToggle which tells how to toggle header in Page:
 
function salve() {
	editbox.value = editbox.value + '{{salve}} ~~' + '~~';
        editreason.value = editreason.value + 'Salve!';
}
 
function weliptest() {
	editbox.value = editbox.value + '{{subst:' + 'welcomeip}} ~~' + '~~\n{{test}}';
        editreason.value = editreason.value + 'welcome & test';
}
 
function welcomeip() {
	editbox.value = editbox.value + '{{subst:' + 'welcomeip}} ~~' + '~~';
        editreason.value = editreason.value + 'welcome';
}
 
function HeaderToggle() {
	editbox.value = editbox.value + '{{subst:' + 'User:Billinghurst/HeaderToggle}}';
}
 
 
//MAIN namespace
// DNBset() - replaces {{header}} with {{DNBset}}
// rmTextQual() removes {{TextQuality}}
// trans() replaces translator with override_translator
// und2ital() converts underlines to italics (PG adaption)
// similar() adds {{similar}} above header
// PrevNext() from {{header}} section, wikis Chapter -1/+1 to Prev/Next
// tag_pages() applies <pages> using #tag and  index {{BASEPAGENAME}} fromsection tosection take {{SUBPAGENAME}}
// defsortsubpage()
 
function DNBset() {
	editbox.value = editbox.value.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}}');
}
 
function rmTextQual() {
	editbox.value = editbox.value.replace(/\{\{TextQuality\|\d{2,3}%\}\}/, '');
}
 
function trans() {
	editbox.value = editbox.value.replace(/ translator\w+\=/, ' override_translator = ');
}
 
function und2ital() {
	editbox.value = editbox.value.replace(/\_/g, '\'\'');
}
 
function similar() {
	editbox.value = editbox.value.replace(/\{\{header/g, '{{similar|}}\n{{header');
        editreason.value = editreason.value + '{{similar}}';
}
 
function PrevNext() {
        var newtitle = parseInt(wgTitle.replace(/^.*\/Chapter (\d+)$/,'$1'))-1;
        var headerprevious = '[[../Chapter '+newtitle+'/]]'; 
        var newtitle = parseInt(wgTitle.replace(/^.*\/Chapter (\d+)$/,'$1'))+1;
        var headernext = '[[../Chapter '+newtitle+'/]]';
        editbox.value = editbox.value.replace(/\| previous   \= \n \| next       \= /, '| previous   \= ' + headerprevious +'\n \| next       \= ' + headernext );
}
 
//subst: #tag and some fields
function tag_pages() {
  var selStart = editbox.selectionStart;
  var selEnd = editbox.selectionEnd;
  var pre = editbox.value.substring(selStart, selEnd); 
//  var pages= '{{subst'+':#tag:pages||index="{{subst'+':BASEPAGENAME}}.djvu" from= to= fromsection="{{subst'+':SUBPAGENAME}}" tosection="{{subst'+':SUBPAGENAME}}"}}';
  var pages= '{{subst:#tag:pages||index="{{subst:BASEPAGENAME}}.djvu"|from=|to=|fromsection="{{subst:SUBPAGENAME}}"|tosection="{{subst:SUBPAGENAME}}"}}';
        editbox.value = editbox.value.substring(0, selStart)
                      + pages
                      + editbox.value.substring(selEnd);
        editbox.focus();
        editbox.setSelectionRange(selStart+post.length, selStart+post.length);
}
 
function defsortsubpage() {
        editbox.value = editbox.value + '{{DEFAULTSORT:{{subst:SUBPAGENAME}}}}'
}
 
//ALL NAMESPACE USE
// cleanup() - all sorts of text cleaning from OCR
// chapcase() - Chapter uc to sc
// nop() - nop, though it puts it at the bottom of editbox, so only useful in Page:
 
function cleanup() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
 
        // Digitized by Google (kill)
        editbox.value = editbox.value.replace(/Digitized[\s\n]+by[\s\n]+Google/, '');
 
        // remove trailing spaces at the end of each line
	editbox.value = editbox.value.replace(/ +\n/g, '\n');
 
        // remove trailing whitespace preceding a hard line break
	editbox.value = editbox.value.replace(/ +<br *\/?>/g, '<br />');
 
        // remove trailing whitespace at the end of page text
	editbox.value = editbox.value.replace(/\s+$/g, '');
 
        // remove trailing spaces at the end of refs
	editbox.value = editbox.value.replace(/ +<\/ref>/g, '</ref>');
 
        // remove trailing spaces at the end of template calls
	editbox.value = editbox.value.replace(/ +}}/g, '}}');
 
        // convert double-hyphen to mdash (avoiding breaking HTML comment syntax)
	editbox.value = editbox.value.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).
	editbox.value = editbox.value.replace(/ +— +/g, '—');
 
        // join words that are hyphenated across a line break
        // (but leave "|-" table syntax alone)
	editbox.value = editbox.value.replace(/([^\|])-\n/g, '$1');
 
        // stuff to do only if the page doesn't contain a <poem> tag:
        if (-1 == editbox.value.indexOf("<poem>")) {
                // remove single line breaks; preserve multiple.
                // but not if there's a tag, template or table syntax either side of the line break
                editbox.value = editbox.value.replace(/([^>}\n])\n([^<{\|\n])/g, '$1 $2');
 
                // collapse sequences of spaces into a single space
                editbox.value = editbox.value.replace(/  +/g, ' ');
        }
 
        // remove unwanted spaces around punctuation marks
	editbox.value = editbox.value.replace(/ ([;:\?!,])/g, '$1');
 
 
        //OCR fixes
        // convert i9 to 19, etc.
	editbox.value = editbox.value.replace(/[il]([0-9])/g, '1$1');
 
        // "the", "them", "their", etcetera
        editbox.value = editbox.value.replace(/tlie/g, 'the');
 
        // "U" -> "ll" when preceded by a lowercase letter.
        editbox.value = editbox.value.replace(/([a-z])U/g, '$1ll');
}
 
// convert uc to sc
function chapcase() {
	editbox.value = editbox.value.replace(/CHAPTER/g, '{{sc|Chapter}}');
}
 
// nop at bottom of editbox
function nop() {
	editbox.value += '\n{{nop}}';
}
 
 
//SPECIFIC TO Page: namespace
// IndianBio() - cleanup for Page:The Indian Biographical Dictionary.djv
// anchor() - applies {{anchor+}}
 
// RunningHeader() - puts {{RunningHeader}} in to headerbox
// endword() - puts {{right}} into footerbox
// smallrefs_rep() - puts {{smallrefs}} into footerbox
 
/* Page:The Indian Biographical Dictionary.djvu tools */
function IndianBio() {
        var headerbox = document.getElementsByName('wpHeaderTextbox')[0];
	headerbox.value = headerbox.value + '{{center|INDIAN BIOGRAPHICAL DICTIONARY, 1915.}}\n\n{{sc|}}';
        cleanup();
	editbox.value = editbox.value.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
        editbox.value = editbox.value.replace(/VU/g, 'VII')
          .replace(/(\w)U(\w)/, '$1ll$2');
}
 
/* Page:A Compendium of Irish Biography tools */
function anchor() {
  var selStart = editbox.selectionStart;
  var selEnd = editbox.selectionEnd;
  var pre = editbox.value.substring(selStart, selEnd); 
  var anch = '{{anchor+|'+pre+'}}';
        editbox.value = editbox.value.substring(0, selStart)
                      + anch
                      + editbox.value.substring(selEnd);
        editbox.focus();
        editbox.setSelectionRange(selStart+post.length, selStart+post.length);
}
 
//adds template 'DJVU page link'
function djvupagelink() {
  var selStart = editbox.selectionStart;
  var selEnd = editbox.selectionEnd;
  var pre = editbox.value.substring(selStart, selEnd);
    if (isIrishBio) {var work = 24;} 
        else {var work = '';}
    var DJVU = '{{DJVU page link|'+pre+'|'+work+'}}';
        editbox.value = editbox.value.substring(0, selStart)
                      + DJVU
                      + editbox.value.substring(selEnd);
        editbox.focus();
        editbox.setSelectionRange(selStart+post.length, selStart+post.length);
}
 
 
//set to internal namespace link, set specifically for subpage xref
function nslink() {
  var selStart = editbox.selectionStart;
  var selEnd = editbox.selectionEnd;
  var pre = editbox.value.substring(selStart, selEnd); 
  var nslink = '{{namespace link|'+pre+'|'+pre+'|..}}';
        editbox.value = editbox.value.substring(0, selStart)
                      + nslink
                      + editbox.value.substring(selEnd);
        editbox.focus();
        editbox.setSelectionRange(selStart+post.length, selStart+post.length);
}
 
//PAGE NAMESPACE  headerbox or footerbox
function RunningHeader() {
        var headerbox = document.getElementsByName('wpHeaderTextbox')[0];
	headerbox.value = headerbox.value + '{{RunningHeader|||}}';
}
 
//*Footerbox app; for archaic books where the first word on the next page is placed at bottom
function RunningFooter() {
        var footerbox = document.getElementsByName('wpFooterTextbox')[0];
        footerbox.value = footerbox.value.replace(/(\<\/div>)/, '{{RunningHeader|||}}$1');
}
 
//Indent
function Indent() {
        var headerbox = document.getElementsByName('wpHeaderTextbox')[0];
		headerbox.value = headerbox.value.replace(/(\<div class\=\"pagetext\">)/g, '<div class="pagetext" style="text-indent:1em;">');
}
 
function smallrefs_rep() {
        var footerbox = document.getElementsByName('wpFooterTextbox')[0];
        footerbox.value = footerbox.value.replace(/(\<references\/\>)/,'{{smallrefs}}');
}
 
function header_center() {
        var headerbox = document.getElementsByName('wpHeaderTextbox')[0];
	headerbox.value = headerbox.value + '{{center|}}';
}
 
function grab_s() {
    editbox.value = editbox.value.replace(/s(?![\Wf])/g, 'ſ');
}
function long_s_replace() {
    editbox.value = editbox.value.replace(/ſ/g, '{{ls}}');
}
function grab_ct() {
    editbox.value = editbox.value.replace(/ct/g, 'ƈt');
}
function ct_replace() {
    editbox.value = editbox.value.replace(/ƈt/g, '{{ct}}');
}
 
// == CUSTOM TABS ==
// === Adds a tab for soft redirects below "move" ===
 /* Soft redirect */
    /* See [[WS:SCRIPTS]]; adds "soft redirect" tab in Firefox. */
       document.write('<script type="text/javascript"'
       + 'src="http://en.wikisource.org/w/index.php?title=User:Bookofjude/softredirect.js'
       + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 
// === 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');
//</pre>