diff --git a/background.js b/background.js index 093d40c..c740217 100644 --- a/background.js +++ b/background.js @@ -195,6 +195,25 @@ function onResponseStarted(details) { downloads.set(details.requestId, request); + // add link with default opts to clipboard + getOptions().then(opts => { + const cmd = generateCommand(details.requestId, opts); + // copy to clipboard - when ready use https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API + browser.tabs.query({active: true}).then(() => { + browser.tabs.executeScript({ + code : 'const cmd = ' + JSON.stringify(cmd) + ';' + + `const input = document.createElement('textarea'); + input.style.position = 'fixed'; + input.style.opacity = 0; + input.value = cmd; + document.body.appendChild(input); + input.select(); + document.execCommand('copy'); + document.body.removeChild(input);` + }); + }); + }); + browser.browserAction.getBadgeText({}).then(txt => { browser.browserAction.setBadgeText({ text: `${+txt + 1}` }); }); diff --git a/manifest.json b/manifest.json index d8abd84..152137a 100644 --- a/manifest.json +++ b/manifest.json @@ -10,7 +10,7 @@ }, "homepage_url": "https://github.com/zaidka/cliget", - "permissions": ["webRequest", "storage", ""], + "permissions": ["webRequest", "storage", "", "activeTab", "clipboardWrite"], "background": { "scripts": ["utils.js", "curl.js", "wget.js", "aria2.js", "background.js"]