aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/assets/javascripts/helpers/general.js4
-rw-r--r--src/assets/javascripts/helpers/instagram.js74
-rw-r--r--src/pages/background/background.js1
-rw-r--r--src/pages/options/general/general.js1
4 files changed, 68 insertions, 12 deletions
diff --git a/src/assets/javascripts/helpers/general.js b/src/assets/javascripts/helpers/general.js
index 15379288..fd14f534 100644
--- a/src/assets/javascripts/helpers/general.js
+++ b/src/assets/javascripts/helpers/general.js
@@ -13,7 +13,7 @@ let theme;
const getTheme = () => theme;
function setTheme(val) {
theme = val
- browser.storage.local.set({ theme });
+ browser.storage.local.set({ theme, instancesCookies: [] });
console.log("theme: ", theme)
}
@@ -60,7 +60,7 @@ async function init() {
if (r.exceptions) exceptions = r.exceptions;
alwaysUsePreferred = r.alwaysUsePreferred ?? false;
- theme = r.them ?? "DEFAULT"
+ theme = r.theme ?? "DEFAULT"
applyThemeToSites = r.applyThemeToSites ?? false;
resolve();
diff --git a/src/assets/javascripts/helpers/instagram.js b/src/assets/javascripts/helpers/instagram.js
index c837bd2c..5dfa4e8f 100644
--- a/src/assets/javascripts/helpers/instagram.js
+++ b/src/assets/javascripts/helpers/instagram.js
@@ -122,7 +122,6 @@ function redirect(url, type) {
if (type !== "main_frame" || url.pathname.match(bypassPaths))
return 'CANCEL'; // Do not redirect /accounts, /embeds.js, or anything other than main_frame
-
let instancesList;
if (protocol == 'normal') instancesList = [...bibliogramNormalRedirectsChecks, ...bibliogramNormalCustomRedirects];
else if (protocol == 'tor') instancesList = [...bibliogramTorRedirectsChecks, ...bibliogramTorCustomRedirects];
@@ -161,6 +160,50 @@ function changeInstance(url) {
return `${randomInstance}${url.pathname}${url.search}`;
}
+function isBibliogram(url) {
+ let protocolHost = `${url.protocol}//${url.host}`;
+ return [
+ ...redirects.bibliogram.normal,
+ ...redirects.bibliogram.tor,
+ ...bibliogramNormalCustomRedirects,
+ ...bibliogramTorCustomRedirects,
+ ].includes(protocolHost);
+}
+
+let instancesCookies;
+let theme;
+let applyThemeToSites;
+function initBibliogramCookies(url) {
+ let protocolHost = `${url.protocol}//${url.host}`;
+ browser.cookies.get({
+ url: protocolHost,
+ name: "settings"
+ }).then(
+ cookie => {
+ if (!cookie || !instancesCookies.includes(protocolHost)) {
+ console.log(`initing cookie for ${protocolHost}`);
+ let request = new XMLHttpRequest();
+ request.open("POST", `${protocolHost}/settings/return?referrer=%2F`);
+
+ if (applyThemeToSites) {
+ let themeValue;
+ if (theme == 'light') themeValue = "classic";
+ if (theme == 'dark') themeValue = "pussthecat.org-v2"
+
+ if (themeValue) {
+ let data = `csrf=x&theme=${themeValue}`;
+ request.send(data);
+ if (!instancesCookies.includes(protocolHost)) instancesCookies.push(protocolHost);
+ browser.storage.local.set({ instancesCookies })
+ }
+ }
+ } else {
+ console.log("cookie url", protocolHost);
+ console.log("instancesCookies", instancesCookies);
+ };
+ })
+
+}
async function init() {
return new Promise((resolve) => {
@@ -171,6 +214,11 @@ async function init() {
"disableInstagram",
"instagramRedirects",
+ "theme",
+ "applyThemeToSites",
+
+ "instancesCookies",
+
"bibliogramNormalRedirectsChecks",
"bibliogramTorRedirectsChecks",
@@ -178,20 +226,25 @@ async function init() {
"bibliogramTorCustomRedirects",
"instagramProtocol"
],
- (result) => {
- disable = result.disableInstagram ?? false;
+ r => {
+ disable = r.disableInstagram ?? false;
redirects.bibliogram = dataJson.bibliogram;
- if (result.instagramRedirects) redirects = result.instagramRedirects
+ if (r.instagramRedirects) redirects = r.instagramRedirects
+
+ theme = r.theme ?? 'DEFAULT';
+ applyThemeToSites = r.applyThemeToSites ?? false;
- bibliogramNormalRedirectsChecks = result.bibliogramNormalRedirectsChecks ?? [...redirects.bibliogram.normal];
- bibliogramNormalCustomRedirects = result.bibliogramNormalCustomRedirects ?? [];
+ instancesCookies = r.instancesCookies ?? [];
- bibliogramTorRedirectsChecks = result.bibliogramTorRedirectsChecks ?? [...redirects.bibliogram.tor];
- bibliogramTorCustomRedirects = result.bibliogramTorCustomRedirects ?? [];
+ bibliogramNormalRedirectsChecks = r.bibliogramNormalRedirectsChecks ?? [...redirects.bibliogram.normal];
+ bibliogramNormalCustomRedirects = r.bibliogramNormalCustomRedirects ?? [];
- protocol = result.instagramProtocol ?? "normal";
+ bibliogramTorRedirectsChecks = r.bibliogramTorRedirectsChecks ?? [...redirects.bibliogram.tor];
+ bibliogramTorCustomRedirects = r.bibliogramTorCustomRedirects ?? [];
+
+ protocol = r.instagramProtocol ?? "normal";
resolve();
}
@@ -211,6 +264,9 @@ export default {
getProtocol,
setProtocol,
+ isBibliogram,
+ initBibliogramCookies,
+
getBibliogramNormalRedirectsChecks,
setBibliogramNormalRedirectsChecks,
getBibliogramTorRedirectsChecks,
diff --git a/src/pages/background/background.js b/src/pages/background/background.js
index 02e575c0..e2f99b23 100644
--- a/src/pages/background/background.js
+++ b/src/pages/background/background.js
@@ -116,6 +116,7 @@ browser.tabs.onUpdated.addListener(
catch (_) { return }
if (youtubeHelper.isPipedorInvidious(url, 'main_frame', 'piped')) youtubeHelper.initPipedLocalStorage(tabId);
if (twitterHelper.isNitter(url, 'main_frame')) newUrl = twitterHelper.initNitterCookies(url);
+ if (instagramHelper.isBibliogram(url)) instagramHelper.initBibliogramCookies(url);
// if (changeInfo.url && youtubeHelper.isPipedorInvidious(url, 'main_frame', 'pipedMaterial')) youtubeHelper.initPipedMaterialLocalStorage(tabId);
// if (changeInfo.url && youtubeHelper.isUrlPipedorInvidious(changeInfo.url, 'invidious')) youtubeHelper.initInvidiousCookies(tabId);
}); \ No newline at end of file
diff --git a/src/pages/options/general/general.js b/src/pages/options/general/general.js
index 22c88143..4f10ab30 100644
--- a/src/pages/options/general/general.js
+++ b/src/pages/options/general/general.js
@@ -80,7 +80,6 @@ generalHelper.init().then(() => {
alwaysUsePreferredElement.checked = generalHelper.getAlwaysUsePreferred();
themeElement.value = generalHelper.getTheme();
applyThemeToSitesElement.checked = generalHelper.getApplyThemeToSites();
- console.log("generalHelper.getAlwaysUsePreferred()");
instanceTypeElement.addEventListener("change",
(event) => {
instanceType = event.target.options[instanceTypeElement.selectedIndex].value