mirror of
https://codeberg.org/LibRedirect/libredirect.git
synced 2025-02-09 08:38:40 +01:00
Added Bibliogram settings and theme support #80
This commit is contained in:
parent
5619a96b4a
commit
a1b0d078d7
@ -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();
|
||||
|
@ -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
|
||||
|
||||
bibliogramNormalRedirectsChecks = result.bibliogramNormalRedirectsChecks ?? [...redirects.bibliogram.normal];
|
||||
bibliogramNormalCustomRedirects = result.bibliogramNormalCustomRedirects ?? [];
|
||||
theme = r.theme ?? 'DEFAULT';
|
||||
applyThemeToSites = r.applyThemeToSites ?? false;
|
||||
|
||||
bibliogramTorRedirectsChecks = result.bibliogramTorRedirectsChecks ?? [...redirects.bibliogram.tor];
|
||||
bibliogramTorCustomRedirects = result.bibliogramTorCustomRedirects ?? [];
|
||||
instancesCookies = r.instancesCookies ?? [];
|
||||
|
||||
protocol = result.instagramProtocol ?? "normal";
|
||||
bibliogramNormalRedirectsChecks = r.bibliogramNormalRedirectsChecks ?? [...redirects.bibliogram.normal];
|
||||
bibliogramNormalCustomRedirects = r.bibliogramNormalCustomRedirects ?? [];
|
||||
|
||||
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,
|
||||
|
@ -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);
|
||||
});
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user