User:Yodin/common.js

mw.loader.load('//en.wikisource.org/w/index.php?title=User:Samwilson/CurlyQuotes.js&action=raw&ctype=text/javascript');

/** * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor. * @see TemplateScript * @update-token */ mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.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 {	pathoschild.TemplateScript.add({ name:'Prose format', forNamespaces: 'page', script: function(editor) { editor .replace(/'''/g, '%#%#%BOLD%#%#%')        // replace bold tags while formatting the page .replace(/''/g, '%#%#%ITALIC%#%#%')       // replace italic tags while formatting the page .replace(/([^\n])\n([^\n\{])/g, '$1 $2')  // remove all single newlines, unless they begin with a template (i.e. '{') .replace(/[ ]+/g, ' ')                    // remove duplicate spaces .replace(/(\s|^)\"/g, '$1“')              // replace typewriter quotation marks with “ when preceded by a space or the start of the document			.replace(/\"/g, '”')                       // replace remaining typewriter quotation marks with ” .replace(/(\s|^|“)\'/g, '$1‘')            // replace typewriter apostrophes with ‘ when preceded by a space, the start of the document, or “ .replace(/\'/g, '’')                      // replace remaining typewriter apostrophes with ’ .replace(/([“‘])\s+/g,'$1')               // remove whitespace following “ or ‘ .replace(/\s+”/g,'”')                     // remove whitespace before ” .replace(/\s+([!?:;,.])/g, '$1')          // remove whitespace before punctuation .replace(/[ ]+(\n)/g, '$1')               // remove spaces before newlines .replace(/[^\S\r\n]*—[^\S\r\n]*/g, '—')   // remove whitespace both sides of an em dash .replace(/^\s+/g, '')                     // remove leading whitespace at the start of the page .replace(/\s+$/g, '')                     // remove trailing whitespace at the end of the page .replace(/“\s*‘/g,'')              // change “‘ to use template .replace(/“\s*’/g,'')              // change “’ to use template .replace(/’\s*”/g,'')              // change ’” to use template .replace(/(<[^>]*)[“”]([^>]*>)/g, '$1"$2') // restore typewriter quotation marks within html tags			.replace(/(<[^>]*)[“”]([^>]*>)/g, '$1"$2') // run a second time to replace both quotation marks .replace(/%#%#%BOLD%#%#%/g, "'''")        // restore bold tags .replace(/%#%#%ITALIC%#%#%/g, "''");      // restore italic tags } });	pathoschild.TemplateScript.add({ name:'Poem format (ppoem)', forNamespaces: 'page', script: function(editor) { editor .replace(/'''/g, '%#%#%BOLD%#%#%')                             // replace bold tags while formatting the page .replace(/''/g, '%#%#%ITALIC%#%#%')                            // replace italic tags while formatting the page .replace(/[^\S\r\n]*(\d+)[^\S\r\n]*(\n)/g,'$2')  // add pline template .replace(/([^\n])[^\S\r\n]*()*[^\S\r\n]*(\n|$)/g, '$1$3') // remove trailing whitespace and tags from the end of lines .replace(/[ ]+/g, ' ')                                         // remove duplicate spaces .replace(/(\s|^)\"/g, '$1“')                                   // replace typewriter quotation marks with “ when preceded by a space or the start of the document			.replace(/\"/g, '”')                                            // replace remaining typewriter quotation marks with ” .replace(/(\s|^|“)\'/g, '$1‘')                                 // replace typewriter apostrophes with ‘ when preceded by a space, the start of the document, or “ .replace(/\'/g, '’')                                           // replace remaining typewriter apostrophes with ’ .replace(/([“‘])\s+/g,'$1')                                    // remove whitespace following “ or ‘ .replace(/\s+”/g,'”')                                          // remove whitespace before ” .replace(/\s+([!?:;,.])/g, '$1')                               // remove whitespace before punctuation .replace(/[ ]+(\n)/g, '$1')                                    // remove spaces before newlines .replace(/[^\S\r\n]*—[^\S\r\n]*/g, '—')                        // remove whitespace both sides of an em dash .replace(/^\s+/g, '')                                          // remove leading whitespace at the start of the page .replace(/\s+$/g, '')                                          // remove trailing whitespace at the end of the page .replace(/“\s*‘/g,'')                                   // change “‘ to use template .replace(/“\s*’/g,'')                                   // change “’ to use template .replace(/’\s*”/g,'')                                   // change ’” to use template .replace(/ (\n\n)/g,'$1')                                   // remove tags at the end of stanzas .replace(/(<[^>]*)[“”]([^>]*>)/g, '$1"$2')                     // restore typewriter quotation marks within html tags			.replace(/(<[^>]*)[“”]([^>]*>)/g, '$1"$2')                      // run a second time to replace both quotation marks .replace(/%#%#%BOLD%#%#%/g, "'''")                             // restore bold tags .replace(/%#%#%ITALIC%#%#%/g, "''");                           // restore italic tags } });	pathoschild.TemplateScript.add({ name:'Typewriter quotations', forNamespaces: 'page', script: function(editor) { editor .replace(/[′‘’`]/g, "'") .replace(/[“”″]/g, '"');	} });	pathoschild.TemplateScript.add({	name:'Clear footer',	forNamespaces: 'page',	script: function(editor) {		editor.forField('#wpFooterTextbox').set();	} });	pathoschild.TemplateScript.add({	name:'+Translations license',	forNamespaces: 0,	script: function(editor) {		editor.append();	} });	pathoschild.TemplateScript.add({	name:'Clear all',	forNamespaces: 'page',	script: function(editor) {		editor.forField('#wpHeaderTextbox').set();		editor.set();		editor.forField('#wpFooterTextbox').set('');	} }); }); //