mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2024-11-22 11:40:13 +00:00
put cookie to API, checkbox UI
This commit is contained in:
parent
65f6fe3257
commit
68fae9d6d4
@ -78,6 +78,18 @@ async function getAccess() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// check if cookie is valid
|
||||||
|
async function getCookieState() {
|
||||||
|
|
||||||
|
const path = "api/cookie/";
|
||||||
|
let response = await sendGet(path)
|
||||||
|
console.log("cookie state: " + JSON.stringify(response));
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// send ping to server, return response
|
// send ping to server, return response
|
||||||
async function verifyConnection() {
|
async function verifyConnection() {
|
||||||
|
|
||||||
@ -135,10 +147,9 @@ async function subscribeLink(toSubscribe) {
|
|||||||
|
|
||||||
async function cookieStr(cookieLines) {
|
async function cookieStr(cookieLines) {
|
||||||
|
|
||||||
let cookieString = cookieLines.join("\n");
|
|
||||||
const path = "api/cookie/";
|
const path = "api/cookie/";
|
||||||
let payload = {
|
let payload = {
|
||||||
"cookie": cookieString
|
"cookie": cookieLines.join("\n")
|
||||||
}
|
}
|
||||||
let response = await sendData(path, payload, "PUT");
|
let response = await sendData(path, payload, "PUT");
|
||||||
|
|
||||||
@ -210,7 +221,12 @@ function handleMessage(request, sender, sendResponse) {
|
|||||||
response.then(message => {
|
response.then(message => {
|
||||||
sendResponse(message)
|
sendResponse(message)
|
||||||
})
|
})
|
||||||
} else if (request.cookie) {
|
} else if (request.cookieState) {
|
||||||
|
let response = getCookieState();
|
||||||
|
response.then(message => {
|
||||||
|
sendResponse(message)
|
||||||
|
})
|
||||||
|
} else if (request.sendCookie) {
|
||||||
console.log("backgound: " + JSON.stringify(request));
|
console.log("backgound: " + JSON.stringify(request));
|
||||||
let response = sendCookies();
|
let response = sendCookies();
|
||||||
response.then(message => {
|
response.then(message => {
|
||||||
|
@ -30,9 +30,12 @@
|
|||||||
<button id="save-login">Save</button><span id="status-icon">☐</span>
|
<button id="save-login">Save</button><span id="status-icon">☐</span>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="cookie">
|
<p>Options:</p>
|
||||||
<button id="send-cookies">Send YouTube cookies</button>
|
<div class="options">
|
||||||
|
<input type="checkbox" id="sendCookies" name="sendCookies">
|
||||||
|
<span>Sync YouTube cookies</span><span id="sendCookiesStatus"></span>
|
||||||
</div>
|
</div>
|
||||||
|
<hr>
|
||||||
<div class="icons">
|
<div class="icons">
|
||||||
<div>
|
<div>
|
||||||
<a href="https://www.reddit.com/r/TubeArchivist/" target="_blank">
|
<a href="https://www.reddit.com/r/TubeArchivist/" target="_blank">
|
||||||
|
@ -42,7 +42,7 @@ document.getElementById("status-icon").addEventListener("click", function() {
|
|||||||
|
|
||||||
|
|
||||||
// send cookie
|
// send cookie
|
||||||
document.getElementById("send-cookies").addEventListener("click", function() {
|
document.getElementById("sendCookies").addEventListener("click", function() {
|
||||||
sendCookie();
|
sendCookie();
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -51,14 +51,28 @@ function sendCookie() {
|
|||||||
console.log("popup send cookie");
|
console.log("popup send cookie");
|
||||||
|
|
||||||
function handleResponse(message) {
|
function handleResponse(message) {
|
||||||
console.log("handle cookie response: " + message);
|
console.log("handle cookie response: " + JSON.stringify(message));
|
||||||
|
let cookie_validated = message.cookie_validated;
|
||||||
|
document.getElementById("sendCookiesStatus").innerText = "validated: " + cookie_validated
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleError(error) {
|
function handleError(error) {
|
||||||
console.log(`Error: ${error}`);
|
console.log(`Error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sending = browserType.runtime.sendMessage({"cookie": true});
|
let checked = document.getElementById("sendCookies").checked;
|
||||||
|
let toStore = {
|
||||||
|
"sendCookies": {
|
||||||
|
"checked": checked
|
||||||
|
}
|
||||||
|
};
|
||||||
|
browserType.storage.local.set(toStore, function() {
|
||||||
|
console.log("stored option: " + JSON.stringify(toStore));
|
||||||
|
})
|
||||||
|
if (checked === false) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let sending = browserType.runtime.sendMessage({"sendCookie": true});
|
||||||
sending.then(handleResponse, handleError);
|
sending.then(handleResponse, handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +105,27 @@ function addUrl(access) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setCookieState() {
|
||||||
|
|
||||||
|
function handleResponse(message) {
|
||||||
|
console.log(message);
|
||||||
|
document.getElementById("sendCookies").checked = message.cookie_enabled;
|
||||||
|
if (message.validated_str) {
|
||||||
|
document.getElementById("sendCookiesStatus").innerText = message.validated_str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleError(error) {
|
||||||
|
console.log(`Error: ${error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("set cookie state");
|
||||||
|
let sending = browserType.runtime.sendMessage({"cookieState": true});
|
||||||
|
sending.then(handleResponse, handleError)
|
||||||
|
document.getElementById("sendCookies").checked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// change status icon based on connection status
|
// change status icon based on connection status
|
||||||
function setStatusIcon(connected) {
|
function setStatusIcon(connected) {
|
||||||
|
|
||||||
@ -183,6 +218,16 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
pingBackend();
|
pingBackend();
|
||||||
addUrl(item.access);
|
addUrl(item.access);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setCookiesOptions(result) {
|
||||||
|
if (!result.sendCookies || result.sendCookies.checked === false) {
|
||||||
|
console.log("sync cookies not set");
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log("set options: " + JSON.stringify(result));
|
||||||
|
setCookieState();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function onError(error) {
|
function onError(error) {
|
||||||
console.log(`Error: ${error}`);
|
console.log(`Error: ${error}`);
|
||||||
@ -192,6 +237,10 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
onGot(result)
|
onGot(result)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
browserType.storage.local.get("sendCookies", function(result) {
|
||||||
|
setCookiesOptions(result)
|
||||||
|
})
|
||||||
|
|
||||||
browserType.storage.local.get("youtube", function(result) {
|
browserType.storage.local.get("youtube", function(result) {
|
||||||
if (result.youtube) {
|
if (result.youtube) {
|
||||||
createButtons(result);
|
createButtons(result);
|
||||||
|
@ -43,15 +43,13 @@ hr {
|
|||||||
.login-form input {
|
.login-form input {
|
||||||
margin: 3px 0;
|
margin: 3px 0;
|
||||||
}
|
}
|
||||||
.submit,
|
.submit {
|
||||||
.cookie {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
.submit button,
|
.submit button,
|
||||||
.youtube-page button,
|
.youtube-page button {
|
||||||
.cookie button {
|
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
padding: 5px 13px;
|
padding: 5px 13px;
|
||||||
@ -66,6 +64,13 @@ hr {
|
|||||||
transform: scale(1.05);
|
transform: scale(1.05);
|
||||||
color: #00202f;
|
color: #00202f;
|
||||||
}
|
}
|
||||||
|
.options {
|
||||||
|
display: flex;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
.options span {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
.icons {
|
.icons {
|
||||||
display: flex;
|
display: flex;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
|
Loading…
Reference in New Issue
Block a user