Skip to content

Commit

Permalink
Add support for scoped packages, e.g.
Browse files Browse the repository at this point in the history
@webcomponents/template
  • Loading branch information
micahjon committed May 15, 2019
1 parent f527d54 commit eb4066b
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
const getPackageName = url => url.split('/').filter(Boolean).slice(0, 4).slice(-1);
const getPackageName = url => {
const parts = url.split('/').filter(Boolean);
const [org, name] = parts[1].endsWith('npmjs.com')
? parts.slice(3, 5)
: parts.slice(2, 4);
return org.startsWith('@')
? `${org}/${name}`
: name || org;
};
const getBundlephobiaUrl = name => `https://bundlephobia.com/result?p=${name}&src=bundlephobia-extension`;
const getIframe = () => document.querySelector('iframe');

chrome.tabs.query({
active: true,
currentWindow: true
}, ([currentTab]) => {
const url = currentTab.url;
const packageName = getPackageName(url);
const iframe = getIframe();
}, ([currentTab]) => {
const url = currentTab.url;
const packageName = getPackageName(url);
const iframe = getIframe();

iframe.onload = () => {
document.body.className = "";
iframe.onload = null;
};
iframe.onload = () => {
document.body.className = "";
iframe.onload = null;
};

iframe.src = getBundlephobiaUrl(packageName);
});
iframe.src = getBundlephobiaUrl(packageName);
});

0 comments on commit eb4066b

Please sign in to comment.