Last active
May 20, 2020 15:08
-
-
Save danlei/17478a08b53ba9367e83111104bfa002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Enlarge Arabic | |
// @namespace danlei | |
// @author danlei | |
// @version 1.1.5 | |
// @updateURL https://gist.githubusercontent.com/danlei/17478a08b53ba9367e83111104bfa002/raw | |
// @installURL https://gist.githubusercontent.com/danlei/17478a08b53ba9367e83111104bfa002/raw | |
// @include /^https?://.*$/ | |
// @exclude https://twitter.com* | |
// @description Increase Arabic font size relatively (adapted from Arminius99's script) | |
// @grant GM_addStyle | |
// ==/UserScript== | |
// TODO: - what's wrong with twitter? | |
// - test arabic in nested elements | |
GM_addStyle("span[lang~='ar'] {direction: rtl; font-size: 110% !important; }"); | |
// cf. https://stackoverflow.com/a/58166435/271324 | |
function addArabicSpan(textNode) { | |
var div = document.createElement('div'); | |
textNode.parentNode.insertBefore(div, textNode); | |
div.insertAdjacentHTML('afterend', | |
textNode.data.replace(/((?=\s*[\u0600-\u06FF])[\u0600-\u06FF\s]+)/g, | |
"<span lang='ar'>$1</span>")); | |
div.remove(); | |
textNode.remove(); | |
} | |
[...document.querySelectorAll('*')]. | |
map(n => [...n.childNodes]). | |
flat(). | |
filter(n => n.nodeType === 3). | |
map(addArabicSpan); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment