From 137620159e4b9b893cfd16eaf8a99801a004087d Mon Sep 17 00:00:00 2001 From: drry Date: Tue, 21 Apr 2009 22:13:29 +0000 Subject: * [31869]. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/branches/2.0@32721 d0d07461-0603-4401-acd4-de1884942a52 --- twitter.js | 64 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/twitter.js b/twitter.js index b2aab4f..a27393b 100644 --- a/twitter.js +++ b/twitter.js @@ -7,13 +7,13 @@ // // Commands: // :twitter some thing text -// post "some thing text" to twitter. +// post "some thing text" to Twitter. // :twitter! someone // show someone's statuses. // :twitter!? someword // show search result of 'someword' from "http://search.twitter.com/". // :twitter!@ -// show replies. +// show mentions. // :twitter!+ someone // fav someone's last status.. // :twitter!- someone @@ -24,12 +24,12 @@ var evalFunc = window.eval; try { var sandbox = new Components.utils.Sandbox(window); - if (Components.utils.evalInSandbox("true", sandbox) === true) { - evalFunc = function(text) { + if (Components.utils.evalInSandbox("true", sandbox) === true){ + evalFunc = function(text){ return Components.utils.evalInSandbox(text, sandbox); - } + }; } - } catch(e) { liberator.log('warning: twitter.js is working with unsafe sandbox.'); } + } catch (e){ liberator.log("warning: twitter.js is working with unsafe sandbox."); } function sprintf(format){ var i = 1, re = /%s/, result = "" + format; @@ -54,33 +54,30 @@ } function sayTwitter(username, password, stat){ var xhr = new XMLHttpRequest(); - xhr.open("POST", "http://twitter.com/statuses/update.json", false, username, password); + xhr.open("POST", "https://twitter.com/statuses/update.json", false, username, password); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("status=" + encodeURIComponent(stat) + "&source=Vimperator"); liberator.echo("[Twitter] Your post " + '"' + stat + '" (' + stat.length + " characters) was sent. " ); } function favTwitter(username, password, user){ var xhr = new XMLHttpRequest(); - xhr.open("POST", "http://twitter.com/statuses/user_timeline/" + user + ".json?count=1", false, username, password); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.open("GET", "https://twitter.com/statuses/user_timeline/" + user + ".json?count=1", false, username, password); xhr.send(null); - xhr.open("POST", "http://twitter.com/favourings/create/" + window.eval(xhr.responseText)[0].id, false, username, password); + xhr.open("POST", "https://twitter.com/favourings/create/" + window.eval(xhr.responseText)[0].id + ".json", false, username, password); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(null); } function unfavTwitter(username, password, user){ var xhr = new XMLHttpRequest(); - xhr.open("POST", "http://twitter.com/statuses/user_timeline/" + user + ".json?count=1", false, username, password); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.open("GET", "https://twitter.com/statuses/user_timeline/" + user + ".json?count=1", false, username, password); xhr.send(null); - xhr.open("POST", "http://twitter.com/favourings/destroy/" + window.eval(xhr.responseText)[0].id, false, username, password); + xhr.open("DELETE", "https://twitter.com/favourings/destroy/" + window.eval(xhr.responseText)[0].id + ".json", false, username, password); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(null); } - function showTwitterReply(username, password){ + function showTwitterMentions(username, password){ var xhr = new XMLHttpRequest(); - xhr.open("POST", "http://twitter.com/statuses/replies.json", false, username, password); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.open("GET", "https://twitter.com/statuses/mentions.json", false, username, password); xhr.send(null); var statuses = evalFunc(xhr.responseText); @@ -88,7 +85,7 @@ span.twitter.entry-content a { text-decoration: none; } img.twitter.photo { border; 0px; width: 16px; height: 16px; vertical-align: baseline; } ]]>.toSource() - .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + + .replace(/(?:\r\n|[\r\n])[ \t]*/g, " ") + statuses.map(function(status) <> {status.user.name}‬ .toSource() - .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + + .replace(/(?:\r\n|[\r\n])[ \t]*/g, " ") + sprintf(': %s‬', status.text)) .join("
"); @@ -106,12 +103,11 @@ } function showFollowersStatus(username, password, target){ var xhr = new XMLHttpRequest(); - var endPoint = target ? "http://twitter.com/statuses/user_timeline/" + target + ".json" - : "http://twitter.com/statuses/friends_timeline.json"; - xhr.open("POST", endPoint, false, username, password); + var endPoint = target ? "https://twitter.com/statuses/user_timeline/" + target + ".json" + : "https://twitter.com/statuses/friends_timeline.json"; + xhr.open("GET", endPoint, false, username, password); // for debug - //xhr.open("POST", "http://twitter.com/statuses/user_timeline/otsune.json", false, username, password); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + //xhr.open("GET", "https://twitter.com/statuses/user_timeline/otsune.json", false, username, password); xhr.send(null); var statuses = evalFunc(xhr.responseText) || []; @@ -119,7 +115,7 @@ span.twitter.entry-content a { text-decoration: none; } img.twitter.photo { border; 0px; width: 16px; height: 16px; vertical-align: baseline; margin: 1px; } ]]>.toSource() - .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + + .replace(/(?:\r\n|[\r\n])[ \t]*/g, " ") + statuses.map(function(status) <> {status.user.name}‬ : {status.text} .toSource() - .replace(/(?:\r?\n|\r)[ \t]*/g, " ")) + .replace(/(?:\r\n|[\r\n])[ \t]*/g, " ")) .join("
"); //liberator.log(html); @@ -139,13 +135,13 @@ var xhr = new XMLHttpRequest(); xhr.open("GET", "http://search.twitter.com/search.json?q=" + encodeURIComponent(word), false); xhr.send(null); - var results = (evalFunc("("+xhr.responseText+")") || {'results':[]}).results; + var results = (evalFunc("("+xhr.responseText+")") || {"results":[]}).results; var html = .toSource() - .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + + .replace(/(?:\r\n|[\r\n])[ \t]*/g, " ") + results.map(function(result) <> {result.from_user}‬ : {result.text} .toSource() - .replace(/(?:\r?\n|\r)[ \t]*/g, " ")) + .replace(/(?:\r\n|[\r\n])[ \t]*/g, " ")) .join("
"); //liberator.log(html); @@ -180,19 +176,19 @@ .replace(/%TITLE%/g, liberator.modules.buffer.title); if (special && arg.match(/^\?\s*(.*)/)) - showTwitterSearchResult(RegExp.$1) + showTwitterSearchResult(RegExp.$1); else if (special && arg.match(/^\+\s*(.*)/)) - favTwitter(username, password, RegExp.$1) + favTwitter(username, password, RegExp.$1); else - if (special && arg.match(/^\-\s*(.*)/)) - unfavTwitter(username, password, RegExp.$1) + if (special && arg.match(/^-\s*(.*)/)) + unfavTwitter(username, password, RegExp.$1); else if (special && arg.match(/^@/)) - showTwitterReply(username, password) + showTwitterMentions(username, password); else if (special || arg.length == 0) - showFollowersStatus(username, password, arg) + showFollowersStatus(username, password, arg); else sayTwitter(username, password, arg); },{ -- cgit v1.2.3