Last active
January 10, 2017 23:53
-
-
Save YungSang/7918361 to your computer and use it in GitHub Desktop.
Taberareloo 用パッチ: Tumblr Dashboard で DeleteCommand (SHIFT + D) を追加する。
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" : "Add a keyboard shortcut to delete a post on Tumblr Dashboard" | |
// , "description" : "Add a keyboard shortcut to delete a post on Tumblr Dashboard" | |
// , "include" : ["content"] | |
// , "match" : [ | |
// "*://www.tumblr.com/dashboard*", | |
// "*://www.tumblr.com/likes*", | |
// "*://www.tumblr.com/blog/*", | |
// "*://www.tumblr.com/tagged/*" | |
// ] | |
// , "version" : "2.1.0" | |
// , "downloadURL" : "https://gist.github.com/YungSang/7918361/raw/userscript.tumblr.delete.command.tbrl.js" | |
// } | |
// ==/Taberareloo== | |
(function() { | |
// Fix a bug to navigate posts by J/K on the Queue page | |
if (location.href.match(/\/queue$/)) { | |
$X('id("new_post_label_text")')[0].dispatchEvent(new MouseEvent('click', { | |
bubbles : true, | |
cancelable : true | |
})); | |
var timer = setInterval(function () { | |
var cancel = $X('id("post_form")[@class="active"]//button[text()="Cancel"]')[0]; | |
if (cancel) { | |
clearInterval(timer); | |
cancel.dispatchEvent(new MouseEvent('click', { | |
bubbles : true, | |
cancelable : true | |
})); | |
} | |
}, 100); | |
} | |
function deletePost(post) { | |
return request('https://www.tumblr.com/svc/post/delete', { | |
method : 'POST', | |
headers : { | |
'X-tumblr-form-key' : $X('id("tumblr_form_key")/@content')[0] | |
}, | |
sendContent : { | |
post_id : $X('./div/@data-post-id', post)[0], | |
channel_id : $X('./div/@data-tumblelog-name', post)[0] | |
} | |
}).then(function (res) { | |
var data = JSON.parse(res.responseText); | |
if (data.response.success) { | |
post.parentNode.removeChild(post); | |
} | |
}); | |
} | |
document.body.addEventListener('keydown', function (ev) { | |
var current = UserScripts['Dashboard + Taberareloo'].getCurrentItem(); | |
if (!current) { | |
return; | |
} | |
var _delete = $X('.//div[contains(@class,"post_control delete")]', current)[0]; | |
var key = keyString(ev); | |
if (_delete && (key === 'SHIFT + D')) { | |
if (confirm($X('@data-confirm', _delete)[0])) { | |
deletePost(current); | |
} | |
/* | |
_delete.dispatchEvent(new MouseEvent('click', { | |
bubbles : true, | |
cancelable : true | |
})); | |
*/ | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Re: Twitter / taizooo: リブログコモンズより dev な方々へ業務連絡。chrome 等で動く現代的な DeleteCommand 的なものを求めています。不慮の事故によりキューに300個程postが溜っておりこれを除去したい次第です
https://twitter.com/taizooo/status/410708111721115648