Last active
June 21, 2017 17:35
-
-
Save steelydylan/ac3c632e7eb94453032b1c0155110580 to your computer and use it in GitHub Desktop.
Pocket数を取得するためのJavaScript
This file contains 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
async function get_pocket_count(url) { | |
const pocketUrl = encodeURIComponent(`https://widgets.getpocket.com/v1/button?v=1&count=horizontal&url=${url}&src=${url}`); | |
const response = await fetch(`http://query.yahooapis.com/v1/public/yql?q=select * from%20xml%20where%20url%3D%22${pocketUrl}%22&format=xml`) | |
const str = await response.text(); | |
const doc = await new window.DOMParser().parseFromString(str, "text/xml") | |
return doc.querySelector('#cnt').innerHTML; | |
} |
chromeのpopupとの組み合わせ
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
const url = tabs[0].url;
get_pocket_count(url).then((data) => {
document.querySelector('#count').innerHTML = data;
});
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こんな感じで取得できます。
get_pocket_count('https://appleple.github.io/SmartPhoto/').then(data => {console.log(data)});