User:DivermanAU/common.js: Difference between revisions
Jump to navigation
Jump to search
Billinghurst (talk | contribs) neutralising code in .js file |
m Ajraddatz moved page User:Diverman/common.js to User:DivermanAU/common.js without leaving a redirect: Automatically moved page while renaming the user "Diverman" to "DivermanAU" |
(No difference)
|
Revision as of 06:42, 21 March 2015
//<pre>
//To get these to work, required gadget regex turned ON
function rmflinks() {
regexTool('{{rh}}', 'RunningHeader()');
regexTool('clean up','cleanup()');
regexTool('nop','nop()');
regexTool('DefSort Subpage','defsortsubpage()');
//Main namespace loads
if (isMainspace) {
regexTool('pn [[//]]','PrevNext1()');
regexTool('Pages','tag_pages()');
regexTool('Pages++','tag_pages_section()');
}
}
function PrevNext1() {
var prevnextlink = '[[..//]]';
editbox.value = editbox.value.replace(/\| previous \= \n \| next \= /, '| previous \= ' + prevnextlink +'\n \| next \= ' + prevnextlink );
}
//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= '<pages index="Diverman.djvu" from="" to=""></pages>';
editbox.value = editbox.value.substring(0, selStart)
+ pages
+ editbox.value.substring(selEnd);
editbox.focus();
editbox.setSelectionRange(selStart+post.length, selStart+post.length);
}
function tag_pages_section() {
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= '<pages index="Diverman.djvu" from="" to="" fromsection="common.js" tosection="common.js"></pages>';
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:common.js}}'
}
function cleanup() {
var editbox = document.getElementsByName('wpTextbox1')[0];
var headerbox = document.getElementsByName('wpHeaderTextbox')[0];
var footerbox = document.getElementsByName('wpFooterTextbox')[0];
// Digitized by Google (kill)
editbox.value = editbox.value.replace(/Digitized[\s\n]+by[^\n]+\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');
// {{c}} to {{center}}
editbox.value = editbox.value.replace(/{{c\|/g, '{{center|');
headerbox.value = headerbox.value.replace(/{{c\|/g, '{{center|');
footerbox.value = footerbox.value.replace(/{{c\|/g, '{{center|');
// {{rh}} to {{RunningHeader}}
headerbox.value = headerbox.value.replace(/{{rh\|/gi, '{{RunningHeader|');
//{{hws}} & {{hwe}} expanded
editbox.value = editbox.value.replace(/{{hws\|/g, '{{hyphenated word start|');
editbox.value = editbox.value.replace(/{{hwe\|/g, '{{hyphenated word end|');
// expand diacritical templates
editbox.value = editbox.value.replace(/{{((ae|oe|\w[:`'~^-]))}}/g, '{{subst'+':$1}}');
}
//end of cleanup
// nop at bottom of editbox
function nop() {
editbox.value += '\n{{nop}}';
}
function defsortsubpage() {
editbox.value = editbox.value + '{{DEFAULTSORT:{{subst:SUBPAGENAME}}}}'
}
//</pre>