Created
September 3, 2010 13:50
-
-
Save 10sr/563901 to your computer and use it in GitHub Desktop.
関数が外側にある
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ////////////////////////////// | |
| function tweetstatus(aInitialInput) { | |
| var statusbar = document.getElementById("statusbar-display"); | |
| var limit = 140; | |
| prompt.reader({ | |
| message: "tweet:", | |
| initialcount: 0, | |
| initialinput: aInitialInput, | |
| group: "twitter_tweet", | |
| onChange: function (arg) { | |
| var current = arg.textbox.value; | |
| var length = current.length; | |
| var count = limit - length; | |
| var msg = M({ | |
| ja: "\u6B8B\u308A " + count + " \u6587\u5B57", | |
| en: count | |
| }); | |
| if (count < 0) { | |
| msg = M({ | |
| ja: -count + " \u6587\u5B57\u30AA\u30FC\u30D0\u30FC", | |
| en: "Over " + -count + " characters" | |
| }); | |
| } | |
| statusbar.label = msg; | |
| }, | |
| callback: function postTweet(aTweet) { | |
| var password; | |
| var username; | |
| var passwordManager = Cc['@mozilla.org/login-manager;1'].getService(Ci.nsILoginManager); | |
| var logins = passwordManager.findLogins({}, | |
| "http://twitter.com", "https://twitter.com", null);[username, password] = [logins[0].username, logins[0].password]; | |
| var xhr = new XMLHttpRequest; | |
| xhr.open("POST", "http://twitter.com/statuses/update.json", false, username, password); | |
| xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
| xhr.send("status=" + aTweet); | |
| } | |
| }); | |
| } | |
| ext.add("twitter-s-tweet", function () { | |
| tweetstatus(); | |
| }, "tweet"); | |
| ext.add("twitter-s-tweet-this-page", function (ev, arg) { | |
| function shortenURL(aURL) { | |
| var json = Cc['@mozilla.org/dom/json;1'].createInstance(Ci.nsIJSON); | |
| var id = "10sr"; | |
| var key = "R_c51f889a77cb4b4e993ed868f65083f5"; | |
| var xhr = new XMLHttpRequest; | |
| var endPoint = "http://api.j.mp/shorten?" + util.format("version=2.0.1&login=%s&apiKey=%s&longUrl=%s", id, key, encodeURIComponent(aURL)); | |
| xhr.mozBackgroundRequest = true; | |
| xhr.open("GET", endPoint, false); | |
| xhr.send(null); | |
| var response = json.decode(xhr.responseText); | |
| if (response && response.results && response.results[aURL]) { | |
| return response.results[aURL].shortUrl; | |
| } | |
| return aURL; | |
| } | |
| tweetstatus(window.getSelection().toString() + (arg ? "" : "\"" + content.document.title + "\" - ") + shortenURL(window.content.location.href)); | |
| }, "tweet this page"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment