User:Londonjackbooks/common.js: Difference between revisions
Appearance
Content deleted Content added
try tweak |
hmm |
||
Line 287: | Line 287: | ||
script: function(editor) { |
script: function(editor) { |
||
editor.forField('#wpHeaderTextbox') |
editor.forField('#wpHeaderTextbox') |
||
.append('{{rh||}}{{block center/s}}'); |
.append('{{rh|{{{pagenum}}||{{{pagenum}}}}}{{block center/s}}'); |
||
} }, |
} }, |
||
Revision as of 08:43, 14 June 2018
//<source lang="javascript">
//activate typoscan script of User:Londonjackbooks/common.js/typoscan.js
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Londonjackbooks/common.js/typoscan.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Inductiveload/scan transcludes.js&action=raw&ctype=text/javascript');
/* Script to shade the background and edit boxes to lower contrast and avoid eyestrain by User:Inductiveload */
jQuery( document ).ready( function() {
if (wgAction == "edit" || wgAction=="submit"){
var colourEditInterfaceBackground = function( pageBG, editboxBG, fontColour, linkColour, newLinkColour, extLinkColour){
style = $('<style type="text/css" />').appendTo('head');
style.append(
'#content {background-color:'+ pageBG +' !important;}\
#content {color:'+ fontColour +' !important;}\
a {color:'+ linkColour +' !important;}\
.new {color:'+ newLinkColour +' !important;}\
.extiw {color:'+ extLinkColour +' !important;}\
textarea, input {background-color:'+editboxBG +' !important;}');
};
colourEditInterfaceBackground('#E6D7C3', '#E6D7C3', '#222', '#22F', '#BA0000', '#33F');
}
});
/* alternative colours */
// alternate: colourEditInterfaceBackground('#228', '#228', '#FDD', '#DFD', '#BFB');
// original: colourEditInterfaceBackground('#DDD', '#DDD', '#222', '#22F', '#BA0000', '#33F');
// brown: colourEditInterfaceBackground('#E6D7C3', '#E6D7C3', '#222', '#22F', '#BA0000', '#33F')
/* CharInsert specific - with all these settings disabled, the CharInsert remains below the footer, as LJB wants */
// window.charinsertDontMove = true;
window.charinsertMoveTop = true;
window.editToolsRecall = true;
window.charinsertCustom = {
"User": '| = — <br./> {\{+}} [\[+|]] “+” ‽ Æ æ Œ œ ℩ {\{hws|+|}} {\{hwe|+|}} <section.begin="+"_/> <section.end="+"_/> '
};
// if(window.updateEditTools) window.updateEditTools();
/**
* WikiEditor specific
* Custom buttons ONLY when Prefs set to - Enable enhanced editing toolbar - is selected,
* Enable wizards for... - must not be selected. Show [old]edit toolbar - should be off.
* based upon - https://github.com/he7d3r/mw-gadget-ExtraEditButtons
*/
var iconPathWE = mw.config.get( 'wgExtensionAssetsPath' ) + '/WikiEditor/modules/images/toolbar/';
var iconPathPRP = mw.config.get( 'wgExtensionAssetsPath' ) + '/ProofreadPage/modules/page/images/';
var fileNamespace = mw.config.get( 'wgFormattedNamespaces' )[6];
var customizeToolbar = function() {
$( '#wpTextbox1' )
.wikiEditor( 'removeFromToolbar', { 'section': 'help' } )
.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'xlink' } )
.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'ilink' } )
.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'signature' } )
.wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'format',
'tools': {
'underline': {
'labelMsg': 'wikieditor-toolbar-tool-underline',
'label': 'Underline',
'id': 'underline',
'filters': [ 'body:not(.ns-2, .ns-8, .ns-828)' ],
'type': 'button',
'icon': '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_underline_he.png',
'action': {
'type': 'encapsulate',
'options': {
'pre': "<u>",
'periMsg': 'wikieditor-toolbar-tool-underline-example',
'post': "</u>"
}
}
},
'strikeout': {
'labelMsg': 'wikieditor-toolbar-tool-strikeout',
'label': 'Strike out',
'id': 'strikeout',
'filters': [ 'body:not(.ns-2, .ns-8, .ns-828)' ],
'type': 'button',
'icon': '//upload.wikimedia.org/wikipedia/commons/6/6d/Vector_strikeout.png',
'action': {
'type': 'encapsulate',
'options': {
'pre': "<s>",
'periMsg': 'wikieditor-toolbar-tool-strikeout-example',
'post': "</s>"
}
}
},
'authorlink': {
'labelMsg': 'wikieditor-toolbar-tool-authorlink',
'label': 'Author Link',
'id': 'authorlink',
'filters': [ 'body.ns-subject' ],
'type': 'button',
'icon': '//upload.wikimedia.org/wikipedia/commons/8/83/Button_biocitas.png',
'action': {
'type': 'encapsulate',
'options': {
'pre': "[[Author:",
'periMsg': 'wikieditor-toolbar-tool-authorlink-example',
'post': "|]]"
}
}
},
'emdash': {
'labelMsg': 'wikieditor-toolbar-tool-emdash',
'label': 'em-dash',
'id': 'emdash',
'filters': [ 'body:not(.ns-8, .ns-828)' ],
'type': 'button',
'icon': '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_m-dash.png',
'action': {
'type': 'replace',
'options': {
'peri': '\u2014',
'selectPeri': false
}
}
},
'endash': {
'labelMsg': 'wikieditor-toolbar-tool-endash',
'label': 'en-dash',
'id': 'endash',
'filters': [ 'body:not(.ns-8, .ns-828)' ],
'type': 'button',
'icon': '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_n-dash.png',
'action': {
'type': 'replace',
'options': {
'peri': '\u2013',
'selectPeri': false
}
}
},
'newline': {
'labelMsg': 'wikieditor-toolbar-tool-newline',
'label': 'Break',
'id': 'newline',
'filters': [ 'body:not(.ns-8, .ns-828)' ],
'type': 'button',
'icon': '//upload.wikimedia.org/wikipedia/commons/f/f2/Button-br.png',
'action': {
'type': 'replace',
'options': {
'peri': '<br />',
'selectPeri': false
}
}
},
'reference': {
'labelMsg': 'wikieditor-toolbar-tool-reference',
'label': 'Reflink',
'id': 'reference',
'filters': [ 'body.ns-subject' ],
'type': 'button',
'icon': '//upload.wikimedia.org/wikipedia/commons/7/79/Button_reflink.png',
'action': {
'type': 'encapsulate',
'options': {
'pre': "<ref>",
'post': "</ref>"
}
}
},
'nowiki': {
'labelMsg': 'wikieditor-toolbar-tool-nowiki',
'label': 'NoWiki',
'id': 'nowiki',
'type': 'button',
'icon': iconPathWE + 'insert-nowiki.png',
'offset': [-70, -70],
'action': {
'type': 'encapsulate',
'options': {
'pre': "<nowiki>",
'periMsg': 'wikieditor-toolbar-tool-nowiki-example',
'post': "</nowiki>"
}
}
},
'redirect': {
'labelMsg': 'wikieditor-toolbar-tool-redirect',
'label': 'ReDirect',
'id': 'redirect',
'filters': [ 'body:not(.ns-828, .ns-829)' ],
'type': 'button',
'icon': iconPathWE + 'insert-redirect.png',
'offset': [-70, -142],
'action': {
'type': 'encapsulate',
'options': {
'pre': mw.config.get( 'wgWikiEditorMagicWords' ).redirect + ' [[',
'periMsg': 'wikieditor-toolbar-tool-redirect-example',
'post': "]]",
'ownline': true
}
}
},
'ilink': {
'labelMsg': 'wikieditor-toolbar-tool-ilink',
'label': 'Wiki link',
'id': 'ilink',
'type': 'button',
'icon': iconPathWE + 'insert-ilink.png',
'offset': [2, -1582],
'action': {
'type': 'encapsulate',
'options': {
'pre': "[[",
'periMsg': 'wikieditor-toolbar-tool-ilink-example',
'post': "]]"
}
}
},
}
} )
.wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'insert',
'tools': {
'signature': {
'labelMsg': 'wikieditor-toolbar-tool-signature',
'label': 'Your Signature',
'id': 'signature',
'filters': [ 'body.ns-talk, body.ns-4' ],
'type': 'button',
'icon': iconPathWE + 'insert-signature.png',
'offset': [2, -1872],
'action': {
'type': 'encapsulate',
'options': {
'pre': '— ~~~~'
}
}
}
}
} );
};
/** Check that the required mode and modules are available. Then, customize */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
window.addEventListener('load', function () {
mw.loader.using( [ 'user.options', 'jquery.textSelection' ], RLQ.push(function () {
if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
$.when(
mw.loader.using( ['ext.wikiEditor.toolbar'] ),
$.ready
).then( customizeToolbar );
}
} ));
}, false);
/**
* Add several tools useful when proofreading pages in the Page: namespace.
* @see https://en.wikisource.org/wiki/Wikisource:TemplateScript
*/
mw.loader.load('//en.wikisource.org/w/index.php?title=MediaWiki:TemplateScript/proofreading.js&action=raw&ctype=text/javascript');
//running header lookup
importScript('User:Inductiveload/Running header.js');
}
/**</source>
* 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]]
*/
// <source lang="javascript">
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
// page NS
pathoschild.TemplateScript.add(
[
// RunningHeader
{ name: 'RunningHeader', position: 'cursor',
script: function(editor) {
editor.forField('#wpHeaderTextbox')
.append('{{rh|{{{pagenum}}||{{{pagenum}}}}}{{block center/s}}');
} },
// remove refs from footer
{
name: 'killrefs',
position: 'replace',
script: function(editor) {
editor.forField('#wpFooterTextbox')
.replace(/[ \s\n]{0,2}(<references ?\/>|{{smallrefs}})\n?/g, '');
}
},
// add refs to footer
{
name: 'addrefs',
position: 'cursor',
script: function(editor) {
editor.forField('#wpFooterTextbox')
.append('{{smallrefs}}');
}
},
// replaces references with smallrefs
{
name: 'smallrefs', position: 'replace',
script: function(editor) {
editor.forField('#wpFooterTextbox')
.replace(/(<references\/>)/,'{{smallrefs}}');
}
},
// convert {{runningheader}} to {{center}} in header and footer, and also <center> to {{center}}
{
name: 'rh to c',
position: 'replace',
script: function (editor) {
editor.replace(/<center>(.+?)<\/center>/g, '{{center|$1}}');
editor.forField('#wpHeaderTextbox').replace(/\n?{{(rh|runningheader)\|/g, '{{center');
editor.forField('#wpFooterTextbox').replace(/\n?{{(rh|runningheader)\|/g, '{{center');
}
},
// puts {{right}} into footerbox
{
name: 'endword', position: 'replace',
script: function(editor) {
editor.forField('#wpHeaderTextbox')
.replace(/(<\/div>)/,'{{right|}}$1');
}
},
// wraps anchor+ around selected text
/*{
name: 'anchor+ select',
script: function(editor) {
editor.replaceSelection(function(selected) {
return '{{anchor+|' + selected + '}}';
});
}
}*/
{
name: 'cleanup',
position: 'cursor',
script: function(editor) {
var header = editor.forField('#wpHeaderTextbox');
var footer = editor.forField('#wpFooterTextbox');
var isPageNS = mw.config.get('wgNamespaceNumber') == 104;
var isDictionary = isPageNS && mw.config.get('Dictionary of National');
// various cleanup
editor
// Digitized by Google (kill)
.replace(/Digitized[\s\n]+by[^\n]+\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')
// remove unwanted spaces around punctuation marks
.replace(/ ([);:\?!,])/g, '$1')
// q.v. to q. v.
.replace(/q\.v\./g, 'q. v.')
// fi to fi
.replace(/fi/, 'fi')
// bom to born
.replace(/(-| |\n)([bB])om /g, '$1$2orn ')
// lona to Iona
.replace(/\blona\b/g, 'Iona')
//OCR fixes
// convert i9 to 19, etc.
.replace(/[il]([0-9])/g, '1$1')
// li -> h ... "the", "them", "their", "with", "much", "here" and whe etcetera
.replace(/([tT]li)(e |at |is |an |em|eir)/ig, 'th$2')
.replace(/wlie/g, 'whe')
.replace(/(wlicli|ivhic(li|h)|wliich|wiiich|whicli)/g, 'which')
.replace(/liurcli/g, 'hurch')
.replace(/li(ave|ere|is)/g, 'h$1')
.replace(/witli/g, 'with')
.replace(/mucli /g, 'much ')
.replace(/wliole/g, 'whole')
.replace(/ lias/g, ' has')
// Av -> w
.replace(/Av(ill|ith|ere |here |as |ould|ho|ork|hich|hen)/g, 'w$1')
.replace(/AV(ill|ith|ere |here |as |ould|ho|ork|hich|hen)/g, 'W$1')
// "U" -> "ll" when preceded by a lowercase letter.
.replace(/([a-z])U/g, '$1ll')
// j}3^ -> y
.replace(/(3|j|\})\^/g, 'y')
// -> Rome/Roman
.replace(/(E|K)om(e|an|ish)([ \.\,\n])/g, 'Rom$2$3')
// imder -> under
.replace(/\bimder/g, 'under');
// {{c}} to {{center}}
editor.replace(/{{c\|/g, '{{center|');
header.replace(/{{c\|/g, '{{center|');
footer.replace(/{{c\|/g, '{{center|');
// {{rh}} to {{RunningHeader}}
header.replace(/\n?{{rh\|/gi, '{{RunningHeader|');
// more cleanup
editor
//{{hws}} & {{hwe}} expanded
.replace(/{{hws\|/g, '{{hyphenated word start|')
.replace(/{{hwe\|/g, '{{hyphenated word end|')
// {{di}} expanded
.replace(/{{di\|/g, '{{dropinitial|')
// {{hi}} expanded
.replace(/{{hi\|/g, '{{hanging indent|')
// {{sm}} expanded
.replace(/{{sm\|/g, '{{smaller|')
// {{...}} replaced
// expand diacritical templates
.replace(/{{\.{3}}}/g, '…')
// expand diacritical templates
.replace(/{{(ae|oe|\w[:`'~^-])}}/g, '{{subst'+':$1}}')
//convert {{—}} to —
.replace(/{{—}}/g, '—');
// M<sup>c</sup> to {{Mc}}
editor.replace(/M<sup>c<\/sup>/g, '{{Mc}}');
header.replace(/M<sup>c<\/sup>/g, '{{Mc}}');
// Robert
editor.replace(/(ll|li|E)obert/g, 'Robert');
header.replace(/(ll|li|E)obert/g, 'Robert');
// yet more cleanup
editor
//DNB link conversion
.replace(/\[\[(.{0,40}?) \(DNB00\)\|([^\]]+?)\]\]/g, '{{DNB lkpl|$1|$2}}')
.replace(/\[\[(.{0,40}?) \(DNB01\)\|([^\]]+?)\]\]/g, '{{DNB lkpl|$1|$2|year=01}}')
.replace(/\[\[(.{0,40}?) \(DNB12\)\|([^\]]+?)\]\]/g, '{{DNB lkpl|$1|$2|year=12}}')
//section tag fix
.replace(/<section (begin|end)=(\w[^\/]+)\/>/g, '<section $1="$2"/>');
// merged ... function smaller()
editor
if (isDictionary) {
editor
.replace(/\<small\>(.+?)\<\/small\>/g, '{{smaller block|$1}}')
.replace(/\<p style="font-size:smaller"\>(.+?)\<\/p\>/g, '{{smaller block|$1}}')
.replace(/\{\{smaller\|\[/g, '{{smaller block|[')
} else {
editor.replace(/\<small\>(.+?)\<\/small\>/g, '{{smaller|$1}}')
}
//
//if (isDictionary) {
//editor.replace(/}} ?({{DNB .{2,5}})[ \n]?(\<sect[^\>]+?\>)/g, '}}\n$1$2\n')
//}
// 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.
// not if there's a tag, template, table syntax either side of line break
.replace(/([^>}\n])\n([^<{\|\n])/g, '$1 $2')
// collapse sequences of spaces into a single space
.replace(/ +/g, ' ');
}
}
}
],
{ category:'page', forNamespaces:'page' } // common fields
);
// main NS
pathoschild.TemplateScript.add(
[
// adds subst: #tag for <pages>
{ name: 'Pages', template: '{{#tag:pages||index={{subst:BASEPAGENAME}}.djvu|from=|to=}}', position: 'cursor'},
// adds subst: #tag for <pages> with sections
{ name: 'Pages++', template: '{{#tag:pages||index={{subst:BASEPAGENAME}}.djvu|from=|to=|fromsection={{subst:SUBPAGENAME}}|tosection={{subst:SUBPAGENAME}}}}', position: 'cursor'},
// adds defaultsort for a subpage
{ name: 'defsortsubpage', template: '{{DEFAULTSORT:{{subst:SUBPAGENAME}}}}', position: 'cursor'},
// wikis Chapter -1/+1 to Prev/Next
{
name: 'PrevNext',
position: 'replace',
script: function (editor) {
var oldtitle = mw.config.get('wgTitle');
var prevtitle = parseInt(oldtitle.replace(/^.*\/Chapter (\d+)$/,'$1'))-1;
var headerprevious = '[[../Chapter '+prevtitle+'/]]';
var nexttitle = parseInt(oldtitle.replace(/^.*\/Chapter (\d+)$/,'$1'))+1;
var headernext = '[[../Chapter '+nexttitle+'/]]';
editor.replace(/\| previous \= \n \| next \= /, '| previous \= ' + headerprevious +'\n \| next \= ' + headernext );
}
},
// prev and next populated for subpages
{
name: 'pn [[//]]',
position: 'replace',
script: function (editor) {
var prevnextlink = '[[..//]]';
editor.replace(/\| previous \= \n \| next \= /, '| previous \= ' + prevnextlink +'\n \| next \= ' + prevnextlink );
}
},
// converts header template to DNB00
{
name: 'DNBset',
position: 'replace',
script: function (editor) {
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
},
// converts DNB endash title to a redirect
{
name: 'DNBredirect',
position: 'replace',
editSummary: 'redirect',
script: function (editor) {
editor.replace(/{{header\n \| title\s+?\= ([^–]+?)–([^\n]+?)\n[=\|\w\s\n]*}}/g, '#redirect [[$1-$2]]');
},
enabled: isDNB00
},
// add similar template
{
name: 'similar',
position: 'replace',
editSummary: '{{similar}}',
script: function (editor) {
editor.replace(/\{\{header/g, '{{similar|}}\n{{header');
}
},
// translator to override_translator
{
name: 'override transl',
position: 'replace',
script: function (editor) {
editor.replace(/ translator\w+\=/, ' override_translator = ');
}
},
// rm text quality templates
{
name: 'text quality',
position: 'replace',
script: function (editor) {
editor.replace(/\{\{TextQuality\|\d{2,3}%\}\}/, '');
}
},
// Littell link replacement
{ name: 'Littell', position: 'replace', editSummary: 'convert to {{Littell\'s link}}',
script: function (editor) {
editor.replace(/\[\[Littell\'s Living Age\/Volume (\d{3})\/Issue (\d{4})\/([^\|]+)\|[^\]]+\]\]/g, "{{Littell's link|$3|$1|$2}}");
}
},
// und2ital() converts underlines to italics (PG adaption)
{
name: 'und2ital',
position: 'replace',
script: function (editor) {
editor.replace(/\_/g, '\'\'');
}
}
],
{ category:'main', forNamespaces:0 } // common fields
);
// user talk NS
pathoschild.TemplateScript.add(
[
{ name: 'welcome', template: '{{welcome}} ~~~~', editSummary: 'Welcome!' },
{ name: 'Welcome+test', template: '{{subst:welcomeip}}\n{{test}} ~~~~', editSummary: 'Welcome and test' },
{ name: 'welcomeip', template: '{{subst:welcomeip}} ~~~~', editSummary:'Welcome!' },
{ name: 'headertoggle', template: '{{subst:User:Billinghurst/HeaderToggle}}' }
],
{ category:'usertalk', position:'after', forNamespaces:'user talk' } // common fields
);
// author NS
pathoschild.TemplateScript.add(
[
// authority control
{ name: '^auc', template:'\n{{authority control}}', position: 'after'},
// nop
{ name: 'nop', template:'\n{{nop}}', position: 'after'},
// … conversion
{ name: 'hellip', position: 'replace',
script: function (editor) {
editor.replace(/ (\. ?){3,5}/g, ' … ');
}
},
// subst: PAGENAME
{ name: 'suPG', template:'{{subst:'+'PAGENAME}}', position: 'after'},
// convert CHAPTER to Chapter
{ name: 'chapcase', position: 'replace',
script: function (editor) {
editor.replace(/CHAPTER/g, '{{sc|Chapter}}');
}
}
]
);
});
// end of TemplateScript
//</source>