{"size": 826, "ext": "js", "max_stars_repo_path": "src/background/index.js", "max_stars_repo_name": "allencch/download-selected", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/background/index.js", "max_issues_repo_name": "allencch/download-selected", "max_issues_repo_issues_event_min_datetime": "2020-12-05T15:03:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-08T07:35:32.000Z", "max_forks_repo_path": "src/background/index.js", "max_forks_repo_name": "allencch/download-selected", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 5, "max_forks_count": null, "avg_line_length": 20.1463414634, "max_line_length": 60, "alphanum_fraction": 0.6259079903}
/* global chrome */
var browser = browser || chrome;

const getSelection = (tab) => {
  browser.tabs.executeScript(tab.id, {
    file: 'ui.js'
  });
};

const download = (links, tabId) => {
  const { DSB } = window;
  DSB.recursiveFetch([], links, 0, { tabId });
};

browser.contextMenus.create({
  id: "download-selected",
  title: "Download Selected",
  contexts: ["all"]
});

browser.contextMenus.onClicked.addListener((info, tab) => {
  switch (info.menuItemId) {
    case 'download-selected':
      getSelection(tab);
      break;
  }
});

browser.runtime.onMessage.addListener((message, sender) => {
  switch (message.type) {
    case 'DOWNLOAD': {
      const { links } = message.data;
      download(links, sender.tab.id);
    }
  }
});

browser.browserAction.onClicked.addListener((tab) => {
  getSelection(tab);
});
