Created
June 21, 2011 05:14
-
-
Save 958/1037288 to your computer and use it in GitHub Desktop.
[keysnail]yatc の短縮 URL を goo.gl に変更する
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
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"})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ついでに plugins.lib.shortenURL で goo.gl に短縮できるようにしたので、
plugins.lib.shortenURL(content.location.href, command.setClipboardText)
とかできる