mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2024-11-22 11:40:13 +00:00
implement basic cookie builder
This commit is contained in:
parent
7007a920c1
commit
9903133e05
@ -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;
|
||||
|
@ -29,6 +29,10 @@
|
||||
<div class="submit">
|
||||
<button id="save-login">Save</button><span id="status-icon">☐</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">
|
||||
|
@ -11,7 +11,11 @@
|
||||
"default_popup": "index.html"
|
||||
},
|
||||
"permissions": [
|
||||
"storage"
|
||||
"storage",
|
||||
"cookies"
|
||||
],
|
||||
"host_permissions": [
|
||||
"*://*/*"
|
||||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
|
@ -11,7 +11,9 @@
|
||||
"default_popup": "index.html"
|
||||
},
|
||||
"permissions": [
|
||||
"storage"
|
||||
"storage",
|
||||
"cookies",
|
||||
"*://*/*"
|
||||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
|
@ -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() {
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user