implement basic cookie builder

This commit is contained in:
simon 2022-06-20 17:35:57 +07:00
parent 7007a920c1
commit 9903133e05
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
6 changed files with 79 additions and 4 deletions

View File

@ -133,6 +133,44 @@ async function subscribeLink(toSubscribe) {
}
function buildCookieLine(cookie) {
return [
cookie.domain,
cookie.hostOnly.toString().toUpperCase(),
cookie.path,
cookie.httpOnly.toString().toUpperCase(),
cookie.expirationDate,
cookie.name,
cookie.value,
].join("\t");
}
async function sendCookies() {
console.log("function sendCookies");
let cookieStores = await browserType.cookies.getAllCookieStores();
var cookieLines = [
"# Netscape HTTP Cookie File\n",
"# https://curl.haxx.se/rfc/cookie_spec.html\n",
"# This is a generated file! Do not edit.\n\n"
];
for (let i = 0; i < cookieStores.length; i++) {
const cookieStore = cookieStores[i];
var allCookiesStore = await browserType.cookies.getAll({
domain: ".youtube.com",
storeId: cookieStore["id"]
});
for (let j = 0; j < allCookiesStore.length; j++) {
const cookie = allCookiesStore[j];
cookieLines.push(buildCookieLine(cookie));
}
}
console.log(cookieLines.join("\n"));
}
// process and return message if needed
function handleMessage(request, sender, sendResponse) {
@ -155,6 +193,9 @@ function handleMessage(request, sender, sendResponse) {
response.then(message => {
sendResponse(message)
})
} else if (request.cookie) {
console.log("backgound: " + JSON.stringify(request));
let response = sendCookies();
}
return true;

View File

@ -29,6 +29,10 @@
<div class="submit">
<button id="save-login">Save</button><span id="status-icon">&#9744;</span>
</div>
<hr>
<div class="cookie">
<button id="send-cookies">Send YouTube cookies</button>
</div>
<div class="icons">
<div>
<a href="https://www.reddit.com/r/TubeArchivist/" target="_blank">

View File

@ -11,7 +11,11 @@
"default_popup": "index.html"
},
"permissions": [
"storage"
"storage",
"cookies"
],
"host_permissions": [
"*://*/*"
],
"content_scripts": [
{

View File

@ -11,7 +11,9 @@
"default_popup": "index.html"
},
"permissions": [
"storage"
"storage",
"cookies",
"*://*/*"
],
"content_scripts": [
{

View File

@ -41,6 +41,28 @@ document.getElementById("status-icon").addEventListener("click", function() {
})
// send cookie
document.getElementById("send-cookies").addEventListener("click", function() {
sendCookie();
})
function sendCookie() {
console.log("popup send cookie");
function handleResponse(message) {
console.log("handle cookie response: " + message);
}
function handleError(error) {
console.log(`Error: ${error}`);
}
let sending = browserType.runtime.sendMessage({"cookie": true});
sending.then(handleResponse, handleError);
}
// send ping message to TA backend
function pingBackend() {

View File

@ -43,13 +43,15 @@ hr {
.login-form input {
margin: 3px 0;
}
.submit {
.submit,
.cookie {
display: flex;
align-items: center;
justify-content: center;
}
.submit button,
.youtube-page button {
.youtube-page button,
.cookie button {
margin: 10px;
border-radius: 0;
padding: 5px 13px;