Created
December 1, 2011 12:25
-
-
Save xulapp/1416353 to your computer and use it in GitHub Desktop.
Google Reader All Feed Refresh
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
// ==UserScript== | |
// @id google-reader-all-feed-refresh@http://twitter.com/xulapp | |
// @name Google Reader All Feed Refresh | |
// @description すべてのフィードを強制的に更新させます | |
// @include http://www.google.tld/reader/view/* | |
// @include https://www.google.tld/reader/view/* | |
// @charset utf-8 | |
// @run-at document-end | |
// @namespace http://twitter.com/xulapp | |
// @author xulapp | |
// @license MIT License | |
// @version 2011/08/12 22:00 +09:00 | |
// ==/UserScript== | |
(function googleReaderAllFeedRefresh() { | |
var readTag = encodeURIComponent('user/' + unsafeWindow._USER_ID + '/state/com.google/read'); | |
var count = 0; | |
var total = 0; | |
function onListLoad(res) { | |
var {subscriptions} = JSON.parse(res.responseText); | |
total = subscriptions.length; | |
progress.max = total; | |
button.parentNode.replaceChild(progress, button); | |
subscriptions.forEach(request); | |
} | |
function request(feed) { | |
updateCount(1); | |
var req = GM_xmlhttpRequest({ | |
url: '/reader/api/0/stream/contents/feed/' + encodeURIComponent(feed.id.replace(/^[^/]+\//, '')) + '?refresh=true&n=1&xt=' + readTag, | |
onreadystatechange: function({readyState}) { | |
if (readyState < 3 || !req) return; | |
req.abort(); | |
req = null; | |
updateCount(-1); | |
}, | |
}); | |
} | |
function updateCount(diff) { | |
count += diff || 0; | |
progress.value = total - count; | |
progress.title = count + '/' + total; | |
if (!count) | |
onFinish(); | |
} | |
function onFinish() { | |
lhnSubscriptions.classList.remove('sub-tree-refreshing'); | |
progress.parentNode.replaceChild(button, progress); | |
document.getElementById('sub-tree-header').click(); | |
} | |
var lhnSubscriptions = document.getElementById('lhn-subscriptions'); | |
var button = document.createElement('span'); | |
button.style.margin = '0 5px'; | |
button.style.fontWeight = 'bold'; | |
button.style.cursor = 'pointer'; | |
button.className = 'unselectable'; | |
button.textContent = '取得'; | |
button.addEventListener('click', function() { | |
if (count) return; | |
lhnSubscriptions.classList.add('sub-tree-refreshing'); | |
GM_xmlhttpRequest({ | |
url: '/reader/api/0/subscription/list?output=json', | |
onload: onListLoad, | |
}); | |
}, false); | |
var progress = document.createElement('progress'); | |
progress.style.width = '64px'; | |
var subTreeHeader = document.getElementById('sub-tree-header'); | |
subTreeHeader.parentNode.insertBefore(button, subTreeHeader.nextSibling); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment