diff --git a/extension/background.js b/extension/background.js index 43a6cd6..5b3d150 100644 --- a/extension/background.js +++ b/extension/background.js @@ -101,8 +101,13 @@ async function verifyConnection() { // send youtube link from injected buttons async function download(url) { + let apiURL = 'api/download/'; + let autostart = await browserType.storage.local.get('autostart'); + if (Object.keys(autostart).length > 0 && autostart.autostart.checked) { + apiURL += '?autostart=true'; + } return await sendData( - 'api/download/', + apiURL, { data: [ { diff --git a/extension/index.html b/extension/index.html index 56226ce..5c43061 100644 --- a/extension/index.html +++ b/extension/index.html @@ -30,8 +30,14 @@

Options:

- - Sync YouTube cookies +
+ + Sync YouTube cookies +
+
+ + Autostart Downloads +

diff --git a/extension/popup.js b/extension/popup.js index a3c60ec..a99911a 100644 --- a/extension/popup.js +++ b/extension/popup.js @@ -73,6 +73,11 @@ document.getElementById('sendCookies').addEventListener('click', function () { sendCookie(); }); +// autostart +document.getElementById('autostart').addEventListener('click', function () { + toggleAutostart(); +}); + function sendCookie() { console.log('popup send cookie'); clearError(); @@ -104,6 +109,18 @@ function sendCookie() { sending.then(handleResponse, handleError); } +function toggleAutostart() { + let checked = document.getElementById('autostart').checked; + let toStore = { + autostart: { + checked: checked, + }, + }; + browserType.storage.local.set(toStore, function () { + console.log('stored option: ' + JSON.stringify(toStore)); + }); +} + // send ping message to TA backend function pingBackend() { clearError(); @@ -190,6 +207,16 @@ document.addEventListener('DOMContentLoaded', async () => { setCookieState(); } + function setAutostartOption(result) { + console.log(result); + if (!result.autostart || result.autostart.checked === false) { + console.log('autostart not set'); + return; + } + console.log('set options: ' + JSON.stringify(result)); + document.getElementById('autostart').checked = true; + } + browserType.storage.local.get('access', function (result) { onGot(result); }); @@ -197,4 +224,8 @@ document.addEventListener('DOMContentLoaded', async () => { browserType.storage.local.get('sendCookies', function (result) { setCookiesOptions(result); }); + + browserType.storage.local.get('autostart', function (result) { + setAutostartOption(result); + }); }); diff --git a/extension/style.css b/extension/style.css index 72dcdac..930a9c2 100644 --- a/extension/style.css +++ b/extension/style.css @@ -63,7 +63,7 @@ hr { color: #00202f; } .options { - display: flex; + display: block; padding-bottom: 10px; } .options span {