Last active
March 8, 2016 02:54
-
-
Save dlwr/78f8c72e79f7400ea5a6 to your computer and use it in GitHub Desktop.
endless summer で継ぎ足されたページでlikeするパッチ (forked from https://github.com/taberareloo/patches-for-taberareloo/blob/master/userscripts/userscript.fix.tumblr.like.tbrl.js)
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
// ==Taberareloo== | |
// { | |
// "name" : "Fix Tumblr like actions on AutoPagerizing" | |
// , "description" : "Fix Tumblr like actions on AutoPagerizing" | |
// , "include" : ["content"] | |
// , "match" : [ | |
// "*://www.tumblr.com/dashboard*", | |
// "*://www.tumblr.com/likes*", | |
// "*://www.tumblr.com/blog/*", | |
// "*://www.tumblr.com/tagged/*" | |
// ] | |
// , "version" : "2.0.2" | |
// , "downloadURL" : "https://gist.githubusercontent.com/dlwr/78f8c72e79f7400ea5a6/raw/userscript.fix.tumblr.like.tbrl.js" | |
// } | |
// ==/Taberareloo== | |
(function() { | |
function doAction(action, data) { | |
return request('https://www.tumblr.com/svc/' + action, { | |
sendContent: data | |
}); | |
} | |
function toggleLike(post) { | |
var like = $X('.//div[contains(concat(" ",@class," ")," like ")]', post)[0]; | |
if (like.classList.contains('liked')) { | |
doAction('unlike', { | |
form_key: $X('id("tumblr_form_key")/@content')[0], | |
'data[id]': $X('./div/@data-post-id', post)[0], | |
'data[key]': $X('./div/@data-reblog-key', post)[0] | |
}).then(function() { | |
like.classList.remove('liked'); | |
}); | |
} else { | |
doAction('like', { | |
form_key: $X('id("tumblr_form_key")/@content')[0], | |
'data[id]': $X('./div/@data-post-id', post)[0], | |
'data[key]': $X('./div/@data-reblog-key', post)[0] | |
}).then(function() { | |
like.classList.add('liked'); | |
}); | |
} | |
} | |
document.body.addEventListener('DOMNodeInserted', function(event) { | |
var post = event.target; | |
post && post.classList && post.classList.add('AutoPagerized'); | |
var like = $X('.//div[contains(concat(" ",@class," ")," like ")]', post)[0]; | |
like && like.addEventListener('click', function(ev) { | |
toggleLike(post); | |
}); | |
}); | |
document.body.addEventListener('keydown', function(ev) { | |
var current = UserScripts['Dashboard + Taberareloo'].getCurrentItem(); | |
if (!current || !current.classList.contains('AutoPagerized')) { | |
return; | |
} | |
var key = keyString(ev); | |
if (key === '3') { | |
toggleLike(current); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment