Skip to content

Instantly share code, notes, and snippets.

@0mg
Created July 27, 2010 03:46
Show Gist options
  • Select an option

  • Save 0mg/491696 to your computer and use it in GitHub Desktop.

Select an option

Save 0mg/491696 to your computer and use it in GitHub Desktop.
Twitter Prompt (window.open)
// ==UserScript==
// @name Twitter Prompt
// @include http://mobile.twitter.com/+
// @description Tweet via window.prompt
// ==/UserScript==
/* Bookmarklet */
if (false) {
javascript: (function(s, t) {
if (s = prompt('いまどうしてる?', s)) confirm((t = s.slice(0, 140)) +
'\n\n あと\x20' + (140 - s.length) + '\x20字入力可能') ?
open('http://mobile.twitter.com/+', t, 'height=1,width=' + innerWidth) :
arguments.callee(s)
})(encodeURI(decodeURI(location)))
}
/* Main */
(function() {
window.name && twitterPrompt(window.name);
function twitterPrompt(tweet) {
var auth = document.getElementsByName("authenticity_token")[0];
if (!auth) return exit("Twitter は現在利用できません", tweet);
if (!confirm(tweet + "\n\nこの文をツイートします")) return exit();
var xhr = new XMLHttpRequest;
xhr.open("POST", "/", true);
xhr.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (this.readyState < 4) return;
if (this.status === 200) {
this.getAllResponseHeaders() ? exit() :
exit("ログインしてやり直して下さい", tweet);
} else exit([this.status, this.getAllResponseHeaders()], tweet);
};
xhr.send("authenticity_token=" + encodeURIComponent(auth.value) +
"&tweet%5Btext%5D=" + encodeURIComponent(tweet));
};
function exit(msg, tweet) {
if (msg !== void 0 && tweet !== void 0) prompt(Error(msg), tweet);
close();
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment