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 // process and return message if needed
function handleMessage(request, sender, sendResponse) { function handleMessage(request, sender, sendResponse) {
@ -155,6 +193,9 @@ function handleMessage(request, sender, sendResponse) {
response.then(message => { response.then(message => {
sendResponse(message) sendResponse(message)
}) })
} else if (request.cookie) {
console.log("backgound: " + JSON.stringify(request));
let response = sendCookies();
} }
return true; return true;

View File

@ -29,6 +29,10 @@
<div class="submit"> <div class="submit">
<button id="save-login">Save</button><span id="status-icon">&#9744;</span> <button id="save-login">Save</button><span id="status-icon">&#9744;</span>
</div> </div>
<hr>
<div class="cookie">
<button id="send-cookies">Send YouTube cookies</button>
</div>
<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">

View File

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

View File

@ -11,7 +11,9 @@
"default_popup": "index.html" "default_popup": "index.html"
}, },
"permissions": [ "permissions": [
"storage" "storage",
"cookies",
"*://*/*"
], ],
"content_scripts": [ "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 // send ping message to TA backend
function pingBackend() { function pingBackend() {

View File

@ -43,13 +43,15 @@ 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;