Created
November 22, 2016 04:22
-
-
Save kholis/7a1ca54f78c6a6543d8d601b3234a1d3 to your computer and use it in GitHub Desktop.
Arabic font fixer (TamperMonkey)
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 *.wordpress.com* | |
// @include *.blogspot.co* | |
// @include *.facebook.com* | |
// @include *.twitter.com* | |
// @include *.google.co* | |
// @include *.youtube.co* | |
// @include *mail.google.co* | |
// @include *muslim.or.id* | |
// @include *bisa.id* | |
// @include *kelaskita.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: 110% !important; }"); | |
//GM_addStyle("span[lang~='ar'] {font-family: 'Sakkal Majalla'; direction: rtl; font-size: 130% !important; }"); | |
// Traditional Arabic | |
// Simplified Arabic | |
// Lateef | |
//GM_addStyle("span[lang~='ar'] {font-family: 'Lateef'; 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
I am sorry but this is horrible, it did not work, it worsens aljazeera.net, and google translator the same, it seems that the the goal was not to make it bigger, but lower making it even more difficult to read.