Skip to content

Commit

Permalink
add autostart option
Browse files Browse the repository at this point in the history
  • Loading branch information
bbilly1 committed May 10, 2023
1 parent 62fa12d commit 7ce3835
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
7 changes: 6 additions & 1 deletion extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
10 changes: 8 additions & 2 deletions extension/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@
<hr>
<p>Options:</p>
<div class="options">
<input type="checkbox" id="sendCookies" name="sendCookies">
<span>Sync YouTube cookies</span><span id="sendCookiesStatus"></span>
<div>
<input type="checkbox" id="sendCookies" name="sendCookies">
<span>Sync YouTube cookies</span><span id="sendCookiesStatus"></span>
</div>
<div>
<input type="checkbox" id="autostart" name="autostart">
<span>Autostart Downloads</span>
</div>
</div>
<hr>
<div class="icons">
Expand Down
31 changes: 31 additions & 0 deletions extension/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -190,11 +207,25 @@ 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);
});

browserType.storage.local.get('sendCookies', function (result) {
setCookiesOptions(result);
});

browserType.storage.local.get('autostart', function (result) {
setAutostartOption(result);
});
});
2 changes: 1 addition & 1 deletion extension/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ hr {
color: #00202f;
}
.options {
display: flex;
display: block;
padding-bottom: 10px;
}
.options span {
Expand Down

0 comments on commit 7ce3835

Please sign in to comment.