Created
December 25, 2010 03:58
-
-
Save xulapp/754667 to your computer and use it in GitHub Desktop.
Google Reader Subscribers Count mod
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== | |
| // @name Google Reader Subscribers Count mod | |
| // @description Show how many subscribers to the feed with google reader. | |
| // @include http:* | |
| // @exclude http://www.google.tld/reader/view/* | |
| // @charset utf-8 | |
| // @compatibility Firefox | |
| // @namespace http://twitter.com/xulapp | |
| // @author xulapp | |
| // @license MIT License | |
| // @version 2010/12/25 13:00 +09:00 | |
| // ==/UserScript== | |
| // @version 2009/11/22 07:26 +09:00 | |
| setTimeout(function() { | |
| const READER_BASE_URI = 'https://www.google.com/reader/view/feed/'; | |
| const CACHE_EXPIRES = 24 * 60 * 60 * 1000; | |
| var feeds = document.evaluate('descendant::link[@rel="alternate" and (@type="application/rss+xml" or @type="application/atom+xml")]', document, null, 7, null); | |
| var len = feeds.snapshotLength; | |
| if (!len) return; | |
| var cache = JSON.parse(GM_getValue('cache', '{}')); | |
| var limit = Date.now() - CACHE_EXPIRES; | |
| for (let [url, [time]] in Iterator(cache)) { | |
| if (time < limit) | |
| delete cache[url]; | |
| } | |
| GM_setValue('cache', JSON.stringify(cache)); | |
| GM_addStyle('' + <><![CDATA[ | |
| #grsc-container { | |
| position: fixed !important; | |
| right: 4px !important; | |
| bottom: 0 !important; | |
| padding: 0 4px !important; | |
| border-radius: 4px 4px 0 0 !important; | |
| -moz-border-radius: 4px 4px 0 0 !important; | |
| background: #99ccff !important; | |
| color: #666666 !important; | |
| font: 8pt normal !important; | |
| z-index: 2147483647 !important; | |
| } | |
| #grsc-container > a { | |
| color: #0000ff !important; | |
| font-weight: bold !important; | |
| } | |
| #grsc-container > a.failed { | |
| color: #ff0000 !important; | |
| } | |
| ]]></>); | |
| var container = document.createElement('div'); | |
| container.id = 'grsc-container'; | |
| for (let i = 0; i < len; i++) { | |
| if (i) | |
| container.appendChild(document.createTextNode(' + ')); | |
| let feed = feeds.snapshotItem(i); | |
| let anchor = document.createElement('a'); | |
| anchor.href = READER_BASE_URI + encodeURIComponent(feed.href); | |
| anchor.title = feed.title; | |
| anchor.textContent = '-' | |
| container.appendChild(anchor); | |
| loadDetails(feed.href, function(data) { | |
| if (data) { | |
| var {subscribers, velocity} = data; | |
| anchor.textContent = subscribers < 0 ? 0 : subscribers; | |
| anchor.title += ' (vel: ' + velocity + ')'; | |
| } else { | |
| anchor.classList.add('failed'); | |
| } | |
| }); | |
| } | |
| container.appendChild(document.createTextNode(' subscriber')); | |
| document.body.appendChild(container); | |
| function loadDetails(url, callback) { | |
| if (url in cache) { | |
| setTimeout(function() callback(cache[url][1]), 0); | |
| return; | |
| } | |
| GM_xmlhttpRequest({ | |
| method: 'GET', | |
| url: 'https://www.google.com/reader/api/0/stream/details?fetchTrends=false&output=json&s=' + encodeURIComponent('feed/' + url), | |
| onload: function onLoad(response) { | |
| if (response.status !== 200) { | |
| callback(); | |
| return; | |
| } | |
| var details = JSON.parse(response.responseText); | |
| var data = { | |
| subscribers: +details.subscribers.replace(/,/g, ''), | |
| velocity: +details.velocity, | |
| }; | |
| cache[url] = [Date.now(), data]; | |
| GM_setValue('cache', JSON.stringify(cache)); | |
| callback(data); | |
| }, | |
| }); | |
| } | |
| }, 0); |
Author
Could be, 10x for the clarification. But still... in my case it should be 0,something, while it is 2.1 Interestingly there is not much information about it online.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it means "Posts per week".