Skip to content

Instantly share code, notes, and snippets.

@ww24
Created June 17, 2012 02:55
Show Gist options
  • Save ww24/2943252 to your computer and use it in GitHub Desktop.
Save ww24/2943252 to your computer and use it in GitHub Desktop.
Gmailの一番上にあるメールの件名を任意のサーバーへ送る
javascript:(function(){var e=document.getElementById("canvas_frame").contentWindow.document.getElementsByClassName("BltHke nH oy8Mbf"),t;for(var i=0,l=e.length;i<l;i++){t=e[i];if(t.style.display!=="none")break}var s=t.getElementsByTagName("table")[1].getElementsByTagName("tr")[0].getElementsByTagName("td")[5].getElementsByTagName("span")[0].innerText;var x=/*@cc_on!@*/true?new XMLHttpRequest():new XDomainRequest();x.timeout=3000;x.ontimeout=function(){alert("timeout")};x.onerror=function(){alert("error")};x.onload=function(){alert(decodeURIComponent(x.responseText))};x.open("POST",prompt("Subject:"+s+"を送信するサーバを指定してください","http://echo.ww24.jp"),false);x.setRequestHeader("Content-Type","application\/x-www-form-urlencoded;charset=UTF-8");x.send("subject="+encodeURIComponent(s))})()
var http = require("http");
http.createServer(function (req, res) {
res.writeHead("200", {
"Access-Control-Allow-Origin": "*"
});
req.on("data", function (chunk) {
res.write(chunk);
});
req.once("end", function () {
res.end();
});
}).listen(80);
// get subject
var d = document.getElementById("canvas_frame").contentWindow.document,
elem = d.getElementsByClassName("BltHke nH oy8Mbf"),
target;
for (var i = 0, l = elem.length; i < l; i++) {
target = elem[i];
if (target.style.display !== "none")
break;
}
var subject = target.getElementsByTagName("table")[1].getElementsByTagName("tr")[0].getElementsByTagName("td")[5].getElementsByTagName("span")[0].innerText;
// XHR
var ajax = function (method, url, data, callback) {
var xhr = /*@cc_on!@*/true ? new XMLHttpRequest() : new XDomainRequest();
xhr.timeout = 3000;
xhr.ontimeout = function () {
alert("timeout");
};
xhr.onerror = function () {
alert("error");
};
xhr.onload = function () {
callback(xhr.responseText);
};
xhr.open(method, url, false);
if (method === "POST")
xhr.setRequestHeader("Content-Type", "application\/x-www-form-urlencoded; charset=UTF-8");
xhr.send(data);
};
// request
url = prompt("Subject:" + subject + "を送信するサーバを指定してください", "http://echo.ww24.jp");
ajax("POST", url, "subject=" + encodeURIComponent(subject), function (data) {
alert(decodeURIComponent(data));
});
@ww24
Copy link
Author

ww24 commented Jun 17, 2012

テスト用の http://echo.ww24.jp ではserver.jsが動いています。

@ww24
Copy link
Author

ww24 commented Jun 23, 2012

SOPを学ぶためのテストコード①

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment