Skip to content

Instantly share code, notes, and snippets.

@958
Created June 21, 2011 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 958/1037288 to your computer and use it in GitHub Desktop.
Save 958/1037288 to your computer and use it in GitHub Desktop.
[keysnail]yatc の短縮 URL を goo.gl に変更する
plugins.lib = _.extend(plugins.lib, {
shortenURL: function (longURL, callback) {
let url = 'https://www.googleapis.com/urlshortener/v1/url';
let xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
let url = JSON.parse(xhr.responseText).id;
callback(url);
}
};
xhr.send(JSON.stringify({ longUrl: longURL }));
}
});
hook.addToHook('PluginLoaded', function() {
if (!plugins.twitterClient) return;
plugins.twitterClient.tweetWithTitleAndURL = function(ev, arg)
plugins.lib.shortenURL(content.location.href, function(url)
plugins.twitterClient.tweet((arg ? "" : '"' + content.document.title + '" - ') + url)
);
// function を直接渡している為 エクステを再登録する必要がある
ext.add("twitter-client-tweet-this-page", plugins.twitterClient.tweetWithTitleAndURL,
M({ja: 'このページのタイトルと URL を使ってつぶやく',
en: "Tweet with the title and URL of this page"}));
});
@958
Copy link
Author

958 commented Jun 21, 2011

ついでに plugins.lib.shortenURL で goo.gl に短縮できるようにしたので、
plugins.lib.shortenURL(content.location.href, command.setClipboardText)
とかできる

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