Created
April 19, 2016 13:17
-
-
Save kholis/1dc2bce67867aa3d5bfe68ce2c4b4d26 to your computer and use it in GitHub Desktop.
javascript using tampermonkey or greasemonkey
This file contains 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 Arabic font size fixer | |
// @namespace Arminius99 | |
// @include *.wikipedia.org* | |
// @include *.wiktionary.org* | |
// @include *.aljazeera.net* | |
// @include *reddit.com* | |
// @include *web.whatsapp.com* | |
// @include *.wordpress.com* | |
// @include *.facebook.com* | |
// @description Increases the font size of Arabic text | |
// @grant GM_addStyle | |
// ==/UserScript== | |
// adjust font, font size and font color according to your preferences | |
//GM_addStyle("span[lang~='ar'] {font-family: 'Droid Arabic Naskh'; direction: rtl; font-size: 100% !important; }"); | |
//GM_addStyle("span[lang~='ar'] {font-family: 'Sakkal Majalla'; direction: rtl; font-size: 130% !important; }"); | |
GM_addStyle("span[lang~='ar'] {font-family: 'Traditional Arabic'; direction: rtl; font-size: x-large !important; }"); | |
// code by James Padolsey; http://james.padolsey.com/javascript/find-and-replace-text-with-javascript/ | |
function findAndReplace(searchText, replacement, searchNode) { | |
if (!searchText || typeof replacement === 'undefined') { | |
// Throw error here if you want... | |
return; | |
} | |
var regex = typeof searchText === 'string' ? | |
new RegExp(searchText, 'g') : searchText, | |
childNodes = (searchNode || document.body).childNodes, | |
cnLength = childNodes.length, | |
excludes = 'html'; | |
while (cnLength--) { | |
var currentNode = childNodes[cnLength]; | |
if (currentNode.nodeType === 1 && | |
(excludes + ',').indexOf(currentNode.nodeName.toLowerCase() + ',') === -1) { | |
arguments.callee(searchText, replacement, currentNode); | |
} | |
if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) { | |
continue; | |
} | |
var parent = currentNode.parentNode, | |
frag = (function(){ | |
var html = currentNode.data.replace(regex, replacement), | |
wrap = document.createElement('div'), | |
frag = document.createDocumentFragment(); | |
wrap.innerHTML = html; | |
while (wrap.firstChild) { | |
frag.appendChild(wrap.firstChild); | |
} | |
return frag; | |
})(); | |
parent.insertBefore(frag, currentNode); | |
parent.removeChild(currentNode); | |
} | |
} | |
findAndReplace('([\u0600-\u06FF]+( [\u0600-\u06FF]+)*)', '<span lang="ar">$1</span>'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment