Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created July 24, 2010 03:49
Show Gist options
  • Save rummelonp/488374 to your computer and use it in GitHub Desktop.
Save rummelonp/488374 to your computer and use it in GitHub Desktop.
TumblrのDashboardで自分からReblogされた/自分のidを含んだpostを折り畳むスクリプト("A smart dashboard is_mine"に依存)
// ==UserScript==
// @name A smart dashboard have my id
// @namespace http://mitukiii.jp/
// @description TumblrのDashboardで自分からReblogされた/自分のidを含んだpostを折り畳むスクリプト
// @include http://www.tumblr.com/*
// @include https://www.tumblr.com/*
// ==/UserScript==
(function() {
var my_id = document.querySelector('#user_channels a')
.href.match(/\/tumblelog\/(.+?)$/i)[1];
var isPost = function(elem) {
return !!elem.id.match(/^post_[0-9]+$/i);
};
var replaceClassName = function(post) {
post.className = post.className.trim();
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.querySelector('.post_info');
if (post_info &&
post_info.textContent.trim().match(/(reblogged you:|あなたから)/i))
{
replaceClassName(post);
return;
}
var blogs = post.getElementsByTagName('a');
for (var i = blogs.length - 1; i >= 0; i -= 1) {
if (blogs[i].textContent === my_id) {
replaceClassName(post);
return;
}
}
};
(function() {
var posts = document.querySelectorAll('.post');
for (var i = posts.length - 1, post = null; i >= 0; 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