Forked from rummelonp/a_smart_dashboard_have_my_id.user.js
Created
July 24, 2010 04:00
-
-
Save azu/488380 to your computer and use it in GitHub Desktop.
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 A smart dashboard have my id | |
// @namespace jp.mitukiii.tumblr | |
// @include http*://www.tumblr.com/dashboard* | |
// ==/UserScript== | |
(function() { | |
var getMyId = document.getElementsByName("t")[0].value; | |
var isPost = function(elem) { | |
return !!elem.id.match(/^post[0-9]+$/i); | |
}; | |
var replaceClassName = function(post) { | |
if (post.className.match(/not_mine/i)) { | |
post.className = post.className.replace(/not_mine/i, 'is_mine'); | |
} else { | |
post.className += ' is_mine'; | |
}; | |
}; | |
var replaceClassNameIfNotesHaveMyId = function(post) { | |
var post_info = post.getElementsByClassName('post_info')[0]; | |
if (post_info.textContent.match(/reblogged you/i)) { | |
return replaceClassName(post); | |
}; | |
var blogs = post.getElementsByClassName('tumblr_blog'); | |
for (var i = 0, len = blogs.length, blog = null; i < len; i += 1) { | |
blog = blogs[i]; | |
if (blog.textContent == getMyId()) { | |
return replaceClassName(post); | |
}; | |
}; | |
}; | |
(function() { | |
var posts = document.getElementsByClassName('post'); | |
for (var i = 0, len = posts.length, post = null; i < len; i += 1) { | |
post = posts[i]; | |
if (isPost(post)) { | |
replaceClassNameIfNotesHaveMyId(post); | |
}; | |
}; | |
})(); | |
document.addEventListener('DOMNodeInserted', function(event) { | |
var elem = event.target; | |
if (isPost(elem)) { | |
replaceClassNameIfNotesHaveMyId(elem); | |
}; | |
}, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment