Created
August 9, 2011 11:06
-
-
Save nikolat/1133772 to your computer and use it in GitHub Desktop.
userscript for cafetter
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 cafetter brunch | |
// @namespace http://www.hatena.ne.jp/Nikola/ | |
// @description add class for cafetter timeline, enable tweet with no script | |
// @version 1.0.4 | |
// @include http://cafetter.com/* | |
// ==/UserScript== | |
(function(d) { | |
function setClassToTweets(d) { | |
var targets = d.querySelectorAll('.timeline li'); | |
for (var i = 0, l = targets.length; i < l; i++) { | |
setClassToTweet(targets[i]); | |
} | |
} | |
function setClassToTweet(t) { | |
if (/brunched-tweet/.test(t.className)) | |
return; | |
t.className += t.className ? ' ' : ''; | |
t.className += 'brunched-tweet'; | |
t.className += ' u-' + t.querySelector('.status_body .status_word .user_name').textContent; | |
if (/@(\w+)/.test(t.querySelector('.status_word').textContent)) { | |
t.className += ' has-mention'; | |
t.className += ' has-mention-' + RegExp.$1; | |
} | |
if (/#(((?! ).)+)/.test(t.querySelector('.status_word').textContent)) { | |
t.className += ' has-hash'; | |
t.className += ' has-hash-' + RegExp.$1; | |
} | |
} | |
function setTweetButton() { | |
var target = d.getElementById('tweeting_controls'); | |
if (target) { | |
var button = d.createElement('input'); | |
button.type = 'submit'; | |
button.value = 'tweet'; | |
target.appendChild(button); | |
} | |
} | |
setTweetButton(); | |
setClassToTweets(d.body); | |
d.addEventListener('DOMNodeInserted',function(e){ | |
var wait = true; | |
if (wait){ | |
setTimeout(function(){ | |
setClassToTweets(d.body); | |
wait = true; | |
}, 500); | |
wait = false; | |
} | |
},true); | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment