Skip to content

Instantly share code, notes, and snippets.

@nikolat
Created August 9, 2011 11:06
Show Gist options
  • Save nikolat/1133772 to your computer and use it in GitHub Desktop.
Save nikolat/1133772 to your computer and use it in GitHub Desktop.
userscript for cafetter
// ==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