Created
September 22, 2014 04:47
-
-
Save sheodox/27cfeff96c7d0a1fa566 to your computer and use it in GitHub Desktop.
Twitter JP tweets in Meiryo font
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
javascript:(function(){ | |
var jpReg = /[\u3000-\u303F]|[\u3040-\u309F]|[\u30A0-\u30FF]|[\uFF00-\uFFEF]|[\u4E00-\u9FAF]|[\u2605-\u2606]|[\u2190-\u2195]|\u203B/g, modes = []; | |
function addMode(modeName) { | |
var title = 'Tweets ['; | |
modes.push(modeName); | |
title += modes.join(', ') + ']'; | |
$('#content-main-heading').text(title); | |
} | |
if (!window.addMode) { | |
window.addMode = addMode; | |
} | |
function filteredNewNodeCallback(root, selector, callback) { | |
var obs, i; | |
if (!root || !selector || !callback) { | |
return; | |
} | |
function filterAndCallback(node) { | |
var matches = [], childMatches; | |
if (node.matches(selector)){ | |
matches.push(node); | |
} | |
childMatches = node.querySelectorAll(selector); | |
if (childMatches.length !== 0) { | |
matches = matches.concat([].slice.call(childMatches)) | |
} | |
matches.map(callback); | |
} | |
obs = new MutationObserver(function(mutations){ | |
mutations.forEach(function(mutation){ | |
for(i = 0; i < mutation.addedNodes.length; i++) { | |
if (mutation.addedNodes[i].nodeType === 1) { | |
filterAndCallback(mutation.addedNodes[i]); | |
} | |
} | |
}) | |
}); | |
obs.observe(root, {childList: true, subtree: true}); | |
} | |
filteredNewNodeCallback($('.stream-container')[0], '.js-stream-item', function(tweet){ | |
var tweetHTML = tweet.innerHTML; | |
if(jpReg.test(tweetHTML)) { | |
tweet.style.fontFamily = 'Meiryo'; | |
} | |
}); | |
window.addMode('jp Meiryo'); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment