全てのサイトでGM_xmlHttpRequestを使うスクリプトその2

またか。(cf. 全てのサイトでGM_xmlHttpRequestを使うスクリプト

// ==UserScript==
// @name           GM_xmlhttpRequest
// @namespace      GM_xmlhttpRequest
// @include        *
// ==/UserScript==

var elem_send = document.createElement("div");
    elem_send.id = "_GM_xmlhttpRequest_send";
    elem_send.style.display = "none";
var elem_receive = document.createElement("div");
    elem_receive.id = "_GM_xmlhttpRequest_receive";
    elem_receive.style.display = "none";

document.body.appendChild(elem_send);
document.body.appendChild(elem_receive);

document.getElementById("_GM_xmlhttpRequest_send").addEventListener("DOMNodeInserted", function (evt) {
	var textarea = evt.target;
	var opt = JSON.parse(textarea.value);
	textarea.parentNode.removeChild(textarea);
	//if (opt.__api__ !== "p@$$w0rd") {
	//	return false;
	//}
	delete opt.__api__;
	var id = opt.__id__;
	["onload", "onerror", opt.__onreadystatechange__ ? "onreadystatechange" : ""].forEach(function (type) {
		if (type) opt[type] = function (req) {
			req.__id__ = id;
			req.__type__ = type;
			var textarea = document.createElement("textarea");
			    textarea.value = JSON.stringify(req);
			document.getElementById("_GM_xmlhttpRequest_receive").appendChild(textarea);
		};
	});
	setTimeout(function () {
		GM_xmlhttpRequest(opt);
	}, 0);
}, false);

location.href = "javascript:(" + function () {
	var count = 0,
	    cache = {};
	window.GM_xmlhttpRequest = function (opt) {
		opt.__onreadystatechange__ = !!opt.__onreadystatechange__;
		cache[opt.__id__ = ++count] = opt;
		var textarea = document.createElement("textarea");
		    textarea.value = JSON.stringify(opt);
		document.getElementById("_GM_xmlhttpRequest_send").appendChild(textarea);
	};
	document.getElementById("_GM_xmlhttpRequest_receive").addEventListener("DOMNodeInserted", function (evt) {
		var textarea = evt.target;
		var req = JSON.parse(textarea.value);
		textarea.parentNode.removeChild(textarea);
		var id = req.__id__,
		    type = req.__type__;
		delete req.__id__;
		delete req.__type__;
		var opt = cache[id];
		opt && opt[type] && opt[type](req);
		if (type === "onload" || type === "onerror") {
			delete cache[id];
		}
	}, false);
} + ")();void 0";

setIntervalでの監視をやめてみた。ちなみに自分はhttp://localhost/で使っております。そういう道具かなと。