GM_xmlhttpRequest 使い方

http://userscripts.org/scripts/review/23685

// ==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*
// @version        0.0.3
// ==/UserScript==

if(!window.Minibuffer) return;

window.Minibuffer.addCommand({
  name : 'Tumblr::Delete',
  command : function(stdin){
  stdin.forEach(function(obj){
    if (obj.className.indexOf('is_mine') != -1){
      var params = [];
      var id = obj.id.match(/post(\d*)/)[1];
      var form = document.getElementById('delete_post_'+id);
      Array.forEach(form.getElementsByTagName('input'),function({name:n,value:v}){
        if (n!='redirect_to') params.push(n+'='+v);
      });
      params = params.join('&');
      window.Minibuffer.status('DeleteCommand'+id, 'Delete...');

      var opt = {
        method: 'POST',
        url: 'http://www.tumblr.com/delete',
        headers : {
        'Content-Type' : 'application/x-www-form-urlencoded',
        'Referer' : 'http://www.tumblr.com'
          },
        data: params,
        onload: function(res){
        window.Minibuffer.status('DeleteCommand'+id, 'Delete... done.', 100);
        },
        onerror: function(e){
        window.Minibuffer.status('DeleteCommand'+id, 'Delete... error.', 150);
        }
      }
      GM_xmlhttpRequest(opt);
    }
  });
  return stdin;
  },
});

window.Minibuffer.addShortcutkey({
  key: 'D',
  description: 'Tumblr::Delete',
  command: function(){
    var stdin = [];
    try{
    stdin = window.Minibuffer.execute('pinned-or-current-node');
    } catch (e){}
    window.Minibuffer.execute('Tumblr::Delete', stdin);
    window.Minibuffer.execute('clear-pin');
  }
});

function log() {if(console) console.log.apply(console, Array.slice(arguments));}

//自分はGM_xmlhttpRequest内に直接書くのが嫌なのでいつもopt作ってから投げてます。 //optの中身の諸情報についてはGM_xmlhttpRequestの説明を探してください。

http://d.hatena.ne.jp/Constellation/20080405/1207403014

//onload内にはRequestが帰ってきてからの処理が書いてあります。 //逆に言えばここの中身が実行されるのは、POSTが成功し、終了したときです。 //引数のresはGM_xmlhttpRequestのresponseオブジェクトです。 //POSTの場合なのでこの場合はあまり使いませんが。

http://d.hatena.ne.jp/Constellation/20080405/1207403014


http://userscripts.org/scripts/review/23488

// ==UserScript==
// @name          Tumblr Shuffle Anywhere
// @namespace     http://cxx.tumblr.com/
// @include       http://*.tumblr.com/
// @include       http://*.tumblr.com/page/*
// @version       0.1
// ==/UserScript==

if (window.location.hostname == 'www.tumblr.com')
	return;
if (document.evaluate(
	'//p[@class="shuffle"]',
	document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null
).singleNodeValue)
{
	return;
}

var style = [
	'position: fixed',
	'top: 3px',
	'left: 3px',
	'color: #fff',
	'background-color: #000'
].join(';');

var postsPerPage = document.evaluate(
	'//div[contains(concat(" ",@class," ")," post ")]',
	document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
).snapshotLength;

GM_xmlhttpRequest( {
	method: 'GET',
	url: 'http://' + window.location.host + '/api/read?num=1',
	onload: function(res) {
		var doc = (new DOMParser()).parseFromString(
			res.responseText, 'application/xml');
		var total = doc.evaluate(
			'//posts/@total', doc, null, XPathResult.NUMBER_TYPE, null
		).numberValue;
		var pages = Math.ceil(total / postsPerPage);
		var pageNum = Math.ceil(Math.random() * pages);
		var uri = 'http://' + window.location.host + '/page/' + pageNum;
		var shuffleElem = document.createElement('p');
		shuffleElem.className = 'shuffle';
		shuffleElem.innerHTML =
			'<a href="' + uri + '" style="' + style + '">Shuffle</a>';
		document.body.appendChild(shuffleElem);
	}
} );