Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save syoichi/1068899 to your computer and use it in GitHub Desktop.
Save syoichi/1068899 to your computer and use it in GitHub Desktop.
自分のIDやページのURLがDashboardなどから取得できない時でも部分的に動作するように修正した。また、Likeなどのページでも動作するように変更した。
// ==UserScript==
// @id A smart dashboard have my id
// @name A smart dashboard have my id
// @namespace http://mitukiii.jp/
// @author mitukiii
// @version 0.0.3
// @update 2012-02-16T03:26:28.351Z(GMT+09:00)
// @description TumblrのDashboardで自分からReblogされた/自分のidを含んだpostを折り畳むスクリプト
// @include http://www.tumblr.com/dashboard*
// @include http://www.tumblr.com/show/*
// @include http://www.tumblr.com/likes*
// @include http://www.tumblr.com/liked/by/*
// @include http://www.tumblr.com/tagged/*
// @exclude http://www.tumblr.com/dashboard/iframe*
// @run-at document-end
// @priority 0
// @compatibility Firefox 10.0(Scriptish 0.1.7), Chrome 17.0.963.46, Safari 5.1.2(NinjaKit 0.8.5), Opera 11.61 on Windows 7 Home Premium SP1 64bit
// @charset UTF-8
// ==/UserScript==
/*jslint browser: true, maxerr: 50, maxlen: 80, indent: 4*/
// Edition 2012-02-14
(function executeAddStyleAndEventListener(doc) {
'use strict';
var posts, containsMyPageUrlElm, hiddenInput, myPageUrl, myId,
containsMyIdXpathExp, xpathExp, addClassName;
posts = doc.getElementById('posts');
if (!posts) {
return;
}
containsMyPageUrlElm = doc.querySelector(
'#post_controls_avatar, .is_mine .post_avatar:only-child'
);
hiddenInput = doc.querySelector('[name="t"]');
if (containsMyPageUrlElm && hiddenInput) {
myPageUrl = containsMyPageUrlElm.href;
myId = hiddenInput.value;
if (!(myPageUrl && myId)) {
return;
}
containsMyIdXpathExp = [
' or ',
'div[contains(concat(" ", @class, " "), " post_content ")]',
'//*[',
'self::td[contains(concat(" ", @class, " "), " quote_source ")]',
' or ',
'self::p',
']/',
'a[',
'starts-with(@href, "' + myPageUrl + '") and ',
'not(@class) and . = "' + myId,
'"][',
'following-sibling::text()[1][. = ":"] or ',
'(',
'preceding-sibling::text()[1][contains(., " (via ")] and ',
'following-sibling::text()[1][starts-with(., ")")]',
')',
']'
].join('');
} else {
containsMyIdXpathExp = '';
}
doc.head.appendChild(doc.createElement('style')).textContent = [
'.is_mine:not(.new_post),',
'.related_me {',
' opacity: 0.5 !important;',
' max-height: 1em !important;',
' overflow: hidden !important;',
'}',
'.is_mine:not(.new_post) > .post_content,',
'.related_me > .post_content {',
' display: none !important;',
'}'
].join('\n');
xpathExp = [
'descendant-or-self::li[',
'(',
'contains(concat(" ", @class, " "), " not_mine ") and ',
'contains(concat(" ", @class, " "), " is_reblog ") and ',
'(',
'div[contains(concat(" ", @class, " "), " post_info ")]',
'/',
'a[count(../a) = 1]',
containsMyIdXpathExp,
')',
') or ',
'(',
'(',
'div[contains(concat(" ", @class, " "), " post_controls ")]',
'/',
'form[@action = "/delete"]',
') and ',
'(',
'div[contains(concat(" ", @class, " "), " avatar_and_i ")]',
'/',
'*[last()][contains(concat(" ", @class, " "), " post_avatar ")]',
')',
')',
']'
].join('');
addClassName = function addClassName(target) {
var contextNode, containsMyIdPost, containsMyIdPosts,
containsMyIdPostsLen;
contextNode = target.target || target;
if (contextNode.tagName === 'LI') {
containsMyIdPost = doc.evaluate(
xpathExp,
contextNode,
null,
9,
null
).singleNodeValue;
if (!containsMyIdPost) {
return;
}
containsMyIdPost.classList.add('related_me');
} else if (contextNode === posts) {
containsMyIdPosts = doc.evaluate(
xpathExp,
contextNode,
null,
7,
null
);
containsMyIdPostsLen = containsMyIdPosts.snapshotLength;
while (containsMyIdPostsLen) {
containsMyIdPosts.snapshotItem(
containsMyIdPostsLen -= 1
).classList.add(
'related_me'
);
}
}
};
addClassName(posts);
posts.addEventListener('DOMNodeInserted', addClassName);
}(document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment