Skip to content

Instantly share code, notes, and snippets.

@taizooo
Forked from Constellation/retweetcommand.user.js
Created November 19, 2009 05:22
Show Gist options
  • Save taizooo/238566 to your computer and use it in GitHub Desktop.
Save taizooo/238566 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name ReTweetCommandX
// @namespace http://d.hatena.ne.jp/Constellation/
// @description ReTweet Command for LDRize (for Official RT)
// @include http://twitter.com/*
// @include https://twitter.com/*
// @include http://search.twitter.com/*
// @include http://pcod.no-ip.org/*
// ==/UserScript==
function boot(ev){
if(ev) window.removeEventListener('GM_MinibufferLoaded', boot, false);
var win = unsafeWindow;
var doc = document;
var Minibuffer = window.Minibuffer;
var $X = Minibuffer.$X;
var D = Minibuffer.D;
var count = 0;
Minibuffer.addCommand({
name : 'Twitter::ReTweetX',
command : function(stdin){
if(stdin.length){
var id = "retweet" + count++;
Minibuffer.status(id, 'ReTweet...');
// locationとpinned-or-current-linkの違いを吸収
var data = (stdin[0].href)? stdin.map(function(node){ return node.href }) : stdin;
with(D()){
parallel(data.map(function(url){
//postid = url.match(/.*\/(\d+)$/)[1];
postid = url.match(/status\/(\d+)/)[1];
rturl = 'http://twitter.com/statuses/retweet/' +postid + '.json';
return xhttp.post(rturl);
})).next(function(){
Minibuffer.status(id, 'Done', 100);
});
}
}
return stdin;
}
});
Minibuffer.addShortcutkey({
key : 'r',
description : 'ReTweet for Official',
command : function(){
try {
var stdin = Minibuffer.execute((/\/\/twitter\.com\/.*?\/(status|statuses)\/\d+/.test(location.href))? 'location' : 'pinned-or-current-link');
}catch(e) {
var stdin = [];
}
Minibuffer.execute('Twitter::ReTweetX|clear-pin',stdin);
}
})
}
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