Skip to content

Instantly share code, notes, and snippets.

@lackneets
Created February 9, 2016 09:43
Show Gist options
  • Save lackneets/fa92cac4e3e5f125f211 to your computer and use it in GitHub Desktop.
Save lackneets/fa92cac4e3e5f125f211 to your computer and use it in GitHub Desktop.
Chinese Friendly (No more 14px chinese font)
javascript: (function(){
"use strict";
var regexCJ = /[\u4e00-\u9fa5]+|[\u0800-\u4e00]+/;
function getTextContainerNodes(){
var nodes = Array.from(document.body.getElementsByTagName("*"));
var leafNodes = nodes.filter(function(elem) {
return elem.hasChildNodes() && Array.from(elem.childNodes).filter(function(node){
return node.nodeType === 3;
}).length > 0
});
return leafNodes;
}
getTextContainerNodes().forEach(function(node){
var size = parseInt(window.getComputedStyle(node).fontSize);
window.test = node;
if(size == 14 && node.innerText.match(regexCJ)){
node.style.fontSize = '13px';
node.style.lineHeight = '2em';
}
});
})();
(function(){
"use strict";
var regexCJ = /[\u4e00-\u9fa5]+|[\u0800-\u4e00]+/;
function getTextContainerNodes(){
var nodes = Array.from(document.body.getElementsByTagName("*"));
var leafNodes = nodes.filter(function(elem) {
return elem.hasChildNodes() && Array.from(elem.childNodes).filter(function(node){
return node.nodeType === 3;
}).length > 0
});
return leafNodes;
}
getTextContainerNodes().forEach(function(node){
var size = parseInt(window.getComputedStyle(node).fontSize);
window.test = node;
if(size == 14 && node.innerText.match(regexCJ)){
node.style.fontSize = '13px';
node.style.lineHeight = '2em';
}
});
})();
@lackneets
Copy link
Author

Before

image

After

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment