264
edits
No edit summary |
Tag: Undo |
||
| (9 intermediate revisions by the same user not shown) | |||
| Line 263: | Line 263: | ||
$( function(){ | $(function () { | ||
var useCustom = false; | var useCustom = false; | ||
var zoomInSVG = | |||
'<svg width="22" height="22" viewBox="0 0 24 24">' + | |||
' | '<path d="M15.5 14h-.8l-.3-.3a6.5 6.5 0 1 0-.7.7l.3.3v.8L20 21.5 21.5 20z ' + | ||
' | 'M10 14a4 4 0 1 1 0-8 4 4 0 0 1 0 8z ' + | ||
'M11 7H9v2H7v2h2v2h2v-2h2V9h-2z"/>' + | |||
var | '</svg>'; | ||
var | |||
var zoomOutSVG = | |||
'<svg width="22" height="22" viewBox="0 0 24 24">' + | |||
$('#content').prepend('<div id="zoomButtons" style="z-index: 9999;"> | '<path d="M15.5 14h-.8l-.3-.3a6.5 6.5 0 1 0-.7.7l.3.3v.8L20 21.5 21.5 20z ' + | ||
'M7 9h6v2H7z"/>' + | |||
'</svg>'; | |||
var toggleSVG = | |||
'<svg width="22" height="22" viewBox="0 0 24 24">' + | |||
'<path d="M5 4h14v2H5zm4 4h6l-2 12h-2z"/>' + | |||
'</svg>'; | |||
$('#content').prepend( | |||
'<div id="zoomButtons" style="z-index:9999; float:right; display:flex; gap:8px; cursor:pointer;">' + | |||
'<span id="zoomInIcon">' + zoomInSVG + '</span>' + | |||
'<span id="zoomOutIcon">' + zoomOutSVG + '</span>' + | |||
'<span id="toggleButton">' + toggleSVG + '</span>' + | |||
'</div>' | |||
); | |||
var $bodyContent = $('.mw-body-content'); | var $bodyContent = $('.mw-body-content'); | ||
var sizes = [parseFloat($bodyContent.css('font-size'))]; | |||
var sizes = [parseFloat($ | |||
sizes[1] = sizes[0] + 2; | sizes[1] = sizes[0] + 2; | ||
function updateSize() { | function updateSize() { | ||
$bodyContent.css( | $bodyContent.css('font-size', sizes[+useCustom] + 'pt'); | ||
} | } | ||
function toggle() { | function toggle() { | ||
useCustom = !useCustom; | useCustom = !useCustom; | ||
updateSize(); | updateSize(); | ||
} | } | ||
function zoom(dif) { | function zoom(dif) { | ||
sizes[1] += dif; | sizes[1] += dif; | ||
| Line 308: | Line 314: | ||
} | } | ||
} | } | ||
$( '#zoomInIcon' ).on( 'click', function(){ | $('#zoomInIcon').on('click', function () { | ||
zoom(1); | zoom(1); | ||
}); | }); | ||
$( '#zoomOutIcon' ).on( 'click', function(){ | $('#zoomOutIcon').on('click', function () { | ||
zoom(-1); | zoom(-1); | ||
}); | }); | ||
$( '#toggleButton' ).on( 'click', toggle ); | $('#toggleButton').on('click', toggle); | ||
}); | }); | ||
| Line 781: | Line 786: | ||
}); | }); | ||
// ==UserScript== | |||
// @name MediaWiki Smart Single Quotes | |||
// @namespace http://your.local/ | |||
// @version 1.0 | |||
// @description Convert straight single quotes to typographic single quotes on MediaWiki pages (visual only). | |||
// @match https://wiki.ekatrafoundation.org/* | |||
// @grant none | |||
// ==/UserScript== | |||
(function () { | |||
'use strict'; | |||
function convertSingleQuotesText(text) { | |||
if (!text || text.indexOf("'") === -1) return text; | |||
text = text.replace(/([A-Za-z0-9])'([A-Za-z0-9])/g, "$1’$2"); // contractions/possessives | |||
text = text.replace(/( | text = text.replace(/(^|[\s\(\[\{\<\u2014\u2013"“'«])'(?=\S)/g, "$1‘"); // opening quotes | ||
text = text.replace(/'/g, "’"); // remaining closing quotes | |||
text = text.replace(/( | |||
text = text.replace(/'/g, | |||
return text; | return text; | ||
} | } | ||
function walkAndReplace(root) { | function walkAndReplace(root) { | ||
var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false); | if (!root) return; | ||
try { | |||
var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false); | |||
var n; | |||
var blacklist = new Set(["CODE", "PRE", "SCRIPT", "STYLE", "TEXTAREA", "NOSCRIPT", "MATH", "INPUT"]); | |||
while ((n = walker.nextNode())) { | |||
var parent = n.parentNode; | |||
if (!parent) continue; | |||
var anc = parent, skip = false; | |||
while (anc && anc.nodeType === 1) { | |||
if (blacklist.has(anc.nodeName)) { skip = true; break; } | |||
anc = anc.parentNode; | |||
} | |||
if (skip) continue; | |||
var orig = n.nodeValue; | |||
var rep = convertSingleQuotesText(orig); | |||
if (rep !== orig) n.nodeValue = rep; | |||
} | } | ||
} catch (e) { | |||
console.error('smartQuotes error', e); | |||
} | |||
} | |||
function applyOnce() { | |||
var root = document.querySelector('.mw-parser-output') || document.body; | |||
walkAndReplace(root); | |||
} | } | ||
// | // run after window.load, also watch for AJAX content | ||
window.addEventListener('load', function () { | |||
setTimeout(applyOnce, 150); | |||
var obs = new MutationObserver(function (mutations) { | |||
mutations.forEach(function (m) { | |||
m.addedNodes && m.addedNodes.forEach(function (n) { | |||
}); | if (n.nodeType === 1) walkAndReplace(n); | ||
}( | else if (n.nodeType === 3 && n.parentNode) walkAndReplace(n.parentNode); | ||
}); | |||
}); | |||
}); | |||
obs.observe(document.body, { childList: true, subtree: true }); | |||
}, false); | |||
})(); | |||