Skip to content

Instantly share code, notes, and snippets.

@saitamanodoruji
Last active December 11, 2015 21:28
Show Gist options
  • Save saitamanodoruji/4662148 to your computer and use it in GitHub Desktop.
Save saitamanodoruji/4662148 to your computer and use it in GitHub Desktop.
delete tumblr on Minibuffer
// ==UserScript==
// @name DeleteCommand
// @namespace http://d.hatena.ne.jp/Constellation/
// @description delete tumblr on Minibuffer
// @include http://www.tumblr.com/dashboard*
// @include http://www.tumblr.com/show*
// @include http://www.tumblr.com/blog*
// @version 0.0.4.4.20140507
// ==/UserScript==
// origin:
// http://userscripts.org/scripts/show/23685
// http://constellation.hatenablog.com/entry/20080405/1207403014
function boot(ev){
if(ev) window.removeEventListener('GM_MinibufferLoaded', boot, false);
sharedObject.Minibuffer.addCommand({
name : 'Tumblr::Delete',
command : function(stdin){
stdin.forEach(function(obj){
var obj = obj.querySelector('div[id^="post_"]') // 2013-08-22
if (obj.className.indexOf('is_mine') != -1){
var data = {
post_id: obj.getAttribute('data-post-id'),
channel_id: obj.getAttribute('data-tumblelog-name'),
form_key: document.getElementById('tumblr_form_key').getAttribute('content')
}
sharedObject.Minibuffer.status('DeleteCommand' + data.post_id, 'Delete...');
var opt = {
method: 'POST',
url: 'http://www.tumblr.com/svc/post/delete',
headers : {
'Content-Type' : 'application/x-www-form-urlencoded',
},
data: JSON.stringify(data),
onload: function(res){
sharedObject.Minibuffer.status('DeleteCommand'+data.post_id, 'Delete... done.', 100);
},
onerror: function(e){
sharedObject.Minibuffer.status('DeleteCommand'+data.post_id, 'Delete... error.', 150);
}
}
GM_xmlhttpRequest(opt);
}
});
return stdin;
},
});
sharedObject.Minibuffer.addShortcutkey({
key: 'D',
description: 'Tumblr::Delete',
command: function(){
var stdin = [];
try{
stdin = sharedObject.Minibuffer.execute('pinned-or-current-node');
} catch (e){}
sharedObject.Minibuffer.execute('Tumblr::Delete', stdin);
sharedObject.Minibuffer.execute('clear-pin');
}
});
}
function log() {if(console) console.log.apply(console, Array.slice(arguments));}
if(sharedObject.Minibuffer){
boot();
} else {
window.addEventListener('GM_MinibufferLoaded', boot, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment