User:Ciridae/StraightQuotes.js

// A very basic script that replaces curly quotes with straight quotes (and some other common replacements). Adapted from User:Samwilson/CurlyQuotes.js and now a full clean up script.

var punctuationReplacements = [ { searchFor: /“ */g, replaceWith: '"'},	{ searchFor: / +\n/g, replaceWith: "\n"},	{ searchFor: / *”/g, replaceWith: '"'}, { searchFor: / *’/g, replaceWith: "'"}, { searchFor: /‘ */g, replaceWith: "'"}, { searchFor: / —/g, replaceWith: "—"}, { searchFor: /— /g, replaceWith: "—"}, { searchFor: / j /g, replaceWith: "; "}, { searchFor: / :/g, replaceWith: ":"}, { searchFor: / ;/g, replaceWith: ";"}, { searchFor: / \?/g, replaceWith: "?"}, { searchFor: / !/g, replaceWith: "!"}, { searchFor: /Cesar/g, replaceWith: "Cæsar"}, { searchFor: /Caesar/g, replaceWith: "Cæsar"}, { searchFor: /CESAR/g, replaceWith: "CÆSAR"}, { searchFor: /tlie/g, replaceWith: "the"}, { searchFor: /woidd/g, replaceWith: "would"}, { searchFor: /coidd/g, replaceWith: "could"}, { searchFor: /shoidd/g, replaceWith: "should"}, //ligatures { searchFor: /ﬁ/g, replaceWith: "fi"}, { searchFor: /ﬂ/g, replaceWith: "fl"}, // many works have apostrophes missing from OCR { searchFor: /([a-z]) s\b/g, replaceWith: "$1\'s"}, // it's he's etc { searchFor: /n t\b/g, replaceWith: "n\'t"}, //can't isn't didn't etc { searchFor: /([a-zI]) ll\b/g, replaceWith: "$1\'ll"}, // I'll we'll etc { searchFor: /\bI m\b/g, replaceWith: "I\'m"}, // I'm	{ searchFor: /\b([Yy])ou re\b/g, replaceWith: "$1ou\'re"}, // you're	{ searchFor: /\b([Ww])e re\b/g, replaceWith: "$1e\'re"}, // we're	{ searchFor: /\b([Tt])hey re\b/g, replaceWith: "$1hey\'re"}, // they're	{ searchFor: /([a-zI]) ve\b/g, replaceWith: "$1\'ve"}, // I've we've etc { searchFor: /([a-z])U/g, replaceWith: "$1ll"}, { searchFor: /[il]([0-9])/g, replaceWith: "1$1"}, { searchFor: /(.)(-)( ?)\n(.)/g, replaceWith: "$1$4"}, { searchFor: /(.)( ?)\n([^\n])/g, replaceWith: "$1 $3"} ];

var ciridaeStraightQuotes = function { $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {		'section': 'main',		'group': 'format',		'tools': {			'smile': {				label: 'Page Cleanup', 				type: 'button',				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Oxygen480-actions-tools-check-spelling.svg/22px-Oxygen480-actions-tools-check-spelling.svg.png',				action: {					type: 'callback',					execute: function {						mw.log( 'Cleaning up text.' );						var text = $("#wpTextbox1").val;						punctuationReplacements.forEach(function(replacement) { text = text.replace(replacement.searchFor, replacement.replaceWith); text = text.trim; });						$("#wpTextbox1").val(text);					}				}			}		}	} ); };

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */ if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) { mw.loader.using( 'user.options', function {		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {			var dependencies = [ 'ext.wikiEditor' ];			if ( mw.user.options.get( 'codemirror-syntax-highlight' ) == 1 ) {				dependencies.push( 'ext.CodeMirror.lib' );			}			mw.log( 'Loading User:Ciridae/StraightQuotes.js' );			mw.loader.using( dependencies, $.ready ).then( ciridaeStraightQuotes );		}	} ); }