From 68fae9d6d49052f56c9b1b161b2480256a2a490c Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 25 Jun 2022 20:15:19 +0700 Subject: [PATCH] put cookie to API, checkbox UI --- extension/background.js | 22 ++++++++++++++--- extension/index.html | 7 ++++-- extension/popup.js | 55 ++++++++++++++++++++++++++++++++++++++--- extension/style.css | 13 +++++++--- 4 files changed, 85 insertions(+), 12 deletions(-) diff --git a/extension/background.js b/extension/background.js index 9c8d265..6883f66 100644 --- a/extension/background.js +++ b/extension/background.js @@ -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 async function verifyConnection() { @@ -135,10 +147,9 @@ async function subscribeLink(toSubscribe) { async function cookieStr(cookieLines) { - let cookieString = cookieLines.join("\n"); const path = "api/cookie/"; let payload = { - "cookie": cookieString + "cookie": cookieLines.join("\n") } let response = await sendData(path, payload, "PUT"); @@ -210,7 +221,12 @@ function handleMessage(request, sender, sendResponse) { response.then(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)); let response = sendCookies(); response.then(message => { diff --git a/extension/index.html b/extension/index.html index f82d66e..d810d9d 100644 --- a/extension/index.html +++ b/extension/index.html @@ -30,9 +30,12 @@
-