Skip to content

Instantly share code, notes, and snippets.

@sorah
Created April 15, 2009 09:38
Show Gist options
  • Save sorah/95702 to your computer and use it in GitHub Desktop.
Save sorah/95702 to your computer and use it in GitHub Desktop.
RetweetをNatsuLionとかでやる用のGreasemonkey
// ==UserScript==
// @name muReTweet
// @namespace muretweet
// @description
// @include http://twitter.com/*/statuses/*
// @include http://twitter.com/*/status/*
// ==/UserScript==
function xpath(query) {
var results = document.evaluate(query, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var nodes = new Array();
for(var i=0; i<results.snapshotLength; i++){
nodes.push(results.snapshotItem(i));
}
return nodes;
}
var rtimage = 'url(data:text/html; charset=iso-8859-1;base64,PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9JRVRGLy9EVEQgSFRNTCAyLjAvL0VOIj4KPGh0bWw+PGhlYWQ+Cjx0aXRsZT40MDQgTm90IEZvdW5kPC90aXRsZT4KPC9oZWFkPjxib2R5Pgo8aDE+Tm90IEZvdW5kPC9oMT4KPHA+VGhlIHJlcXVlc3RlZCBVUkwgL3JldHdlZXQucG5nIHdhcyBub3QgZm91bmQgb24gdGhpcyBzZXJ2ZXIuPC9wPgo8aHI+CjxhZGRyZXNzPkFwYWNoZS8yLjIuMiAoRmVkb3JhKSBTZXJ2ZXIgYXQgbG9jYWxob3N0IFBvcnQgODA8L2FkZHJlc3M+CjwvYm9keT48L2h0bWw+Cg==';
//ReTweet用URLの生成//////////////////
///////postの内容を取得
n = xpath("/html/body/div[2]/div[2]/div/div/span/span")[0];
tweet = n.innerHTML.replace(/<.*>(.*)<¥/.*>/,"$1");
///////IDを取得
tid = xpath("/html/body/div[2]/div[2]/div/div/div/div[2]/a")[0].innerHTML;
///////URL組み立て
url = "http://twitter.com/home?status="+encodeURI("RT: "+tweet+"("+location.href+" ) (@"+tid+")");
console.log(url);
//ReTweetボタン設置//////////////////////
///////RTボタン設置先のobject取得
n = xpath("/html/body/div[2]/div[2]/div/div/div[2]")[0];
///////element作成
elm = document.createElement('a');
elm.setAttribute("href",url);
elm.setAttribute("class","");
elm.style.backgroundImage = 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAANkDQtZPoQAAAwBQTFRFw8PD///M//+Z//9m//8z//8A/8z//8zM/8yZ/8xm/8wz/8wA/5n//5nM/5mZ/5lm/5kz/5kA/2b//2bM/2aZ/2Zm/2Yz/2YA/zP//zPM/zOZ/zNm/zMz/zMA/wD//wDM/wCZ/wBm/wAz/wAAzP//zP/MzP+ZzP9mzP8zzP8AzMz/zMzMzMyZzMxmzMwzzMwAzJn/zJnMzJmZzJlmzJkzzJkAzGb/zGbMzGaZzGZmzGYzzGYAzDP/zDPMzDOZzDNmzDMzzDMAzAD/zADMzACZzABmzAAzzAAAmf//mf/Mmf+Zmf9mmf8zmf8Amcz/mczMmcyZmcxmmcwzmcwAmZn/mZnMmZmZmZlmmZkzmZkAmWb/mWbMmWaZmWZmmWYzmWYAmTP/mTPMmTOZmTNmmTMzmTMAmQD/mQDMmQCZmQBmmQAzmQAAZv//Zv/MZv+ZZv9mZv8zZv8AZsz/ZszMZsyZZsxmZswzZswAZpn/ZpnMZpmZZplmZpkzZpkAZmb/ZmbMZmaZZmZmZmYzZmYAZjP/ZjPMZjOZZjNmZjMzZjMAZgD/ZgDMZgCZZgBmZgAzZgAAM///M//MM/+ZM/9mM/8zM/8AM8z/M8zMM8yZM8xmM8wzM8wAM5n/M5nMM5mZM5lmM5kzM5kAM2b/M2bMM2aZM2ZmM2YzM2YAMzP/MzPMMzOZMzNmMzMzMzMAMwD/MwDMMwCZMwBmMwAzMwAAAP//AP/MAP+ZAP9mAP8zAP8AAMz/AMzMAMyZAMxmAMwzAMwAAJn/AJnMAJmZAJlmAJkzAJkAAGb/AGbMAGaZAGZmAGYzAGYAADP/ADPMADOZADNmADMzADMAAAD/AADMAACZAABmAAAz7gAA3QAAuwAAqgAAiAAAdwAAVQAARAAAIgAAEQAAAO4AAN0AALsAAKoAAIgAAHcAAFUAAEQAACIAABEAAADuAADdAAC7AACqAACIAAB3AABVAABEAAAiAAAR////3d3du7u7qqqqiIiId3d3VVVVREREIiIiERERAAAAEHN5TQAAAAlwSFlzAAALEwAACxMBAJqcGAAAACJ0RVh0U29mdHdhcmUAUXVpY2tUaW1lIDcuNiAoTWFjIE9TIFgpAD5Cch0AAAAHdElNRQfZBA8IMCnH4a72AAAAPElEQVR4nGP4igYYgAgIwEwwzQCmGaDiQJosga9Qga9wAahlEIugLAYExYDG/8qA4EMlUeXhpqH4hVQBANZWpJ3KWeV4AAAAAElFTkSuQmCC)'
console.log(elm);
n.appendChild(elm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment