├── icons
└── 128x128.png
├── store
├── 1280x800.png
├── 440x280.png
└── 640x400.png
├── manifest.json
├── readme.md
├── license
└── index.js
/icons/128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukeed/npm-downloads-extension/HEAD/icons/128x128.png
--------------------------------------------------------------------------------
/store/1280x800.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukeed/npm-downloads-extension/HEAD/store/1280x800.png
--------------------------------------------------------------------------------
/store/440x280.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukeed/npm-downloads-extension/HEAD/store/440x280.png
--------------------------------------------------------------------------------
/store/640x400.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukeed/npm-downloads-extension/HEAD/store/640x400.png
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "NPM Downloads",
3 | "version": "1.0.0",
4 | "manifest_version": 2,
5 | "description": "Display download counts alongside NPM author pages",
6 | "homepage_url": "https://github.com/lukeed/npm-downloads-extension",
7 | "icons": {
8 | "128": "icons/128x128.png"
9 | },
10 | "permissions": [
11 | "https://www.npmjs.com/~*"
12 | ],
13 | "content_scripts": [
14 | {
15 | "matches": [
16 | "https://www.npmjs.com/~*"
17 | ],
18 | "js": [
19 | "index.js"
20 | ]
21 | }
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # NPM Downloads Extension
2 |
3 | > Chrome extension that displays download counts alongside NPM author pages
4 |
5 | When viewing any author page, this performs efficient API lookup(s) and then injects the formatted download counts next to each package name.
6 |
7 |
8 | ## Install
9 |
10 | Install it from the [Chrome Web Store](https://chrome.google.com/webstore/detail/npm-downloads/gkopjiobbmgaolpocbjnjilaamleimbd) or [manually](http://superuser.com/a/247654/6877).
11 |
12 | _Firefox and Safari versions TBD._
13 |
14 |
15 | ## Screenshots
16 |
17 | 
18 |
19 |

20 |
21 |
22 | ## License
23 |
24 | MIT © [Luke Edwards](https://lukeed.com)
25 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) Luke Edwards (https://lukeed.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | if (location.pathname.indexOf('~') === -1) return;
3 | const tc = 'textContent';
4 | const sel = 'ul.collaborated-packages li';
5 | const API = 'https://api.npmjs.org/downloads/point/last-month';
6 | const getCount = q => q && fetch(`${API}/${q}`).then(res => res.json());
7 | const getLinks = () => [].slice.call(document.querySelectorAll(`${sel} a:not(.num)`));
8 | const drawHTML = (el, num) => el.lastElementChild.insertAdjacentHTML('afterend', ` - (${num.toLocaleString()})`);
9 | function main() {
10 | const els = getLinks();
11 | const all = els.map(e => e[tc]);
12 | const query = all.filter(s => s.indexOf('@') === -1).join(',');
13 | const scopes = all.filter(s => s.indexOf('@') !== -1).map(q => getCount(q).then(o => ({[q]:o})));
14 | return Promise.all(scopes.concat(getCount(query))).then(arr => Object.assign.apply(null, arr)).then(obj => {
15 | els.forEach(el => (el.className += ' num') && drawHTML(el.parentNode, obj[el[tc]].downloads));
16 | });
17 | }
18 | setTimeout(main,1);
19 | const css = document.createElement('style');
20 | css.innerHTML = `${sel}>em{font-size:82.5%;line-height:1;opacity:0.75;vertical-align:baseline;}`;
21 | document.head.appendChild(css);
22 | const btn = document.querySelector('a.fetch-more-packages');
23 | if (btn !== void 0) {
24 | var timer, txt=btn[tc];
25 | btn.addEventListener('click', () => btn[tc]==='loading...' ? (timer=setInterval(() => (btn[tc]===txt) && (main(),clearInterval(timer)), 100)) : main());
26 | }
27 | }());
28 |
--------------------------------------------------------------------------------