Skip to content

Instantly share code, notes, and snippets.

@Constellation
Created September 29, 2009 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Constellation/197064 to your computer and use it in GitHub Desktop.
Save Constellation/197064 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Tumblr + Tombloo
// @namespace http://d.hatena.ne.jp/Constellation/
// @description register reblog command by Tombloo on Tumblr page
// @include http://*
// @exclude http://www.tumblr.com/dashboard*
// @exclude http://www.tumblr.com/show*
// @exclude http://www.tumblr.com/iphone*
// ==/UserScript==
function boot(ev){
if(ev) removeEventListener('GM_MinibufferLoaded', arguments.callee, false);
var win = unsafeWindow;
var doc = document;
var tombloo = GM_Tombloo.Tombloo.Service;
var Minibuffer = window.Minibuffer;
var $X = Minibuffer.$X;
var linkext = tombloo.extractors['ReBlog - Tumblr link'];
var pageext = tombloo.extractors['ReBlog - Tumblr'];
// mod extractor
var mod = {
check : function(ctx) tombloo.extractors.ReBlog.getFrameUrl(ctx.document),
extract : function(ctx) tombloo.extractors.ReBlog.extractByPage(ctx, ctx.document)
};
{
let command = {
name : 'Tombloo::ReblogTumblrLink',
command : function(stdin){
stdin.forEach(function(link){
var ctx = update({
document : doc,
window : win,
link : link,
event : {},
target : doc,
title : null,
mouse : null,
menu : null,
}, win.location);
if(linkext.check(ctx)){
tombloo.share(ctx, linkext, false);
Minibuffer.status('Tombloo::ReblogTumblrLink'+link.href, 'Reblog', 100);
}
});
return stdin;
}
}
Minibuffer.addCommand(command);
}
{
let id = 0;
let command = {
name : 'Tombloo::ReblogTumblr',
command : function(){
var ctx = update({
document : doc,
window : win,
event : {},
target : doc,
title : null,
mouse : null,
menu : null,
}, win.location);
// currentDocument 関数の不具合により不可.
/*
if(pageext.check(ctx)){
tombloo.share(ctx, pageext, false);
Minibuffer.status('Tombloo::ReblogTumblrLink'+link, 'Reblog', 100);
}
*/
// 代替法
if(mod.check(ctx)){
tombloo.share(ctx, mod, false);
Minibuffer.status('Tombloo::ReblogTumblrLink'+(id++), 'Reblog', 100);
}
return location.href;
}
}
Minibuffer.addCommand(command);
}
Minibuffer.addShortcutkey(
{
key : 't',
description : 'Reblog Tumblr by Tombloo',
command : function(){
try {
var stdin = Minibuffer.execute('pinned-or-current-link');
}catch(e) {}
if(stdin.length){
Minibuffer.execute('Tombloo::ReblogTumblrLink|clear-pin',stdin);
} else {
Minibuffer.execute('Tombloo::ReblogTumblr');
}
}
}
);
function update(t, s){
for(var p in s)
t[p] = s[p];
return t;
}
}
if(window.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