Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save azu/488380 to your computer and use it in GitHub Desktop.
Save azu/488380 to your computer and use it in GitHub Desktop.
// ==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