add autostart option

This commit is contained in:
simon 2023-05-10 20:39:40 +07:00
parent 62fa12d218
commit 7ce3835ef3
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
4 changed files with 46 additions and 4 deletions

View File

@ -101,8 +101,13 @@ async function verifyConnection() {
// send youtube link from injected buttons // send youtube link from injected buttons
async function download(url) { 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( return await sendData(
'api/download/', apiURL,
{ {
data: [ data: [
{ {

View File

@ -30,8 +30,14 @@
<hr> <hr>
<p>Options:</p> <p>Options:</p>
<div class="options"> <div class="options">
<input type="checkbox" id="sendCookies" name="sendCookies"> <div>
<span>Sync YouTube cookies</span><span id="sendCookiesStatus"></span> <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> </div>
<hr> <hr>
<div class="icons"> <div class="icons">

View File

@ -73,6 +73,11 @@ document.getElementById('sendCookies').addEventListener('click', function () {
sendCookie(); sendCookie();
}); });
// autostart
document.getElementById('autostart').addEventListener('click', function () {
toggleAutostart();
});
function sendCookie() { function sendCookie() {
console.log('popup send cookie'); console.log('popup send cookie');
clearError(); clearError();
@ -104,6 +109,18 @@ function sendCookie() {
sending.then(handleResponse, handleError); 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 // send ping message to TA backend
function pingBackend() { function pingBackend() {
clearError(); clearError();
@ -190,6 +207,16 @@ document.addEventListener('DOMContentLoaded', async () => {
setCookieState(); 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) { browserType.storage.local.get('access', function (result) {
onGot(result); onGot(result);
}); });
@ -197,4 +224,8 @@ document.addEventListener('DOMContentLoaded', async () => {
browserType.storage.local.get('sendCookies', function (result) { browserType.storage.local.get('sendCookies', function (result) {
setCookiesOptions(result); setCookiesOptions(result);
}); });
browserType.storage.local.get('autostart', function (result) {
setAutostartOption(result);
});
}); });

View File

@ -63,7 +63,7 @@ hr {
color: #00202f; color: #00202f;
} }
.options { .options {
display: flex; display: block;
padding-bottom: 10px; padding-bottom: 10px;
} }
.options span { .options span {