parent
7599568965
commit
3d579dc163
|
@ -199,18 +199,26 @@ function isNitter(url, type) {
|
|||
|
||||
let theme;
|
||||
let applyThemeToSites;
|
||||
function initNitterCookies(url) {
|
||||
let protocolHost = `${url.protocol}//${url.host}`;
|
||||
function initNitterCookies() {
|
||||
let themeValue;
|
||||
if (theme == 'light') themeValue = 'Twitter';
|
||||
if (theme == 'dark') themeValue = 'Twitter Dark';
|
||||
|
||||
if (applyThemeToSites && themeValue != 'DEFAULT')
|
||||
browser.cookies.set({
|
||||
url: protocolHost,
|
||||
name: "theme",
|
||||
value: themeValue
|
||||
})
|
||||
if (applyThemeToSites && themeValue != 'DEFAULT') {
|
||||
let allInstances = [...redirects.nitter.normal, ...redirects.nitter.tor, ...nitterNormalCustomRedirects, ...nitterTorCustomRedirects]
|
||||
let checkedInstances = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects, ...nitterTorRedirectsChecks, ...nitterTorCustomRedirects]
|
||||
for (const item of allInstances)
|
||||
if (!checkedInstances.includes(item))
|
||||
browser.cookies.remove({
|
||||
url: instanceUrl,
|
||||
name: "theme",
|
||||
})
|
||||
for (const instanceUrl of checkedInstances)
|
||||
browser.cookies.set({
|
||||
url: instanceUrl,
|
||||
name: "theme",
|
||||
value: themeValue
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function init() {
|
||||
|
@ -259,6 +267,8 @@ async function init() {
|
|||
nitterTorRedirectsChecks = r.nitterTorRedirectsChecks ?? [...redirects.nitter.tor];
|
||||
nitterTorCustomRedirects = r.nitterTorCustomRedirects ?? [];
|
||||
|
||||
initNitterCookies();
|
||||
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -21,31 +21,7 @@ browser.storage.local.get(
|
|||
"OnlyEmbeddedVideo",
|
||||
"theme",
|
||||
"invidiousVideoQuality",
|
||||
], (result) => {
|
||||
let prefs = getCookie();
|
||||
let oldPrefs = { ...prefs };
|
||||
|
||||
if (result.invidiousAlwaysProxy !== undefined && prefs.local !== result.invidiousAlwaysProxy)
|
||||
prefs.local = result.invidiousAlwaysProxy;
|
||||
|
||||
if (result.invidiousVideoQuality !== undefined && prefs.quality !== result.invidiousVideoQuality)
|
||||
prefs.quality = result.invidiousVideoQuality;
|
||||
|
||||
if (result.theme !== undefined && prefs.dark_mode !== result.theme)
|
||||
prefs.dark_mode = result.theme;
|
||||
|
||||
if (result.youtubeVolume !== undefined && prefs.volume !== result.youtubeVolume)
|
||||
prefs.volume = result.youtubeVolume;
|
||||
|
||||
if (result.invidiousPlayerStyle !== undefined && prefs.player_style !== result.invidiousPlayerStyle)
|
||||
prefs.player_style = result.invidiousPlayerStyle;
|
||||
|
||||
if (result.invidiousSubtitles !== undefined && prefs.subtitles === result.invidiousSubtitles)
|
||||
prefs.subtitles = result.invidiousSubtitles;
|
||||
|
||||
if (result.youtubeAutoplay !== undefined && prefs.autoplay !== result.youtubeAutoplay)
|
||||
prefs.autoplay = result.youtubeAutoplay;
|
||||
|
||||
if (prefs != oldPrefs) document.cookie = `PREFS=${encodeURIComponent(JSON.stringify(prefs))}`;
|
||||
],
|
||||
r => {
|
||||
}
|
||||
)
|
||||
|
|
|
@ -537,87 +537,6 @@ function isPipedorInvidious(url, type, frontend) {
|
|||
].includes(protocolHost);
|
||||
}
|
||||
|
||||
let applyThemeToSites;
|
||||
function addUrlParams(url) {
|
||||
let protocolHost = `${url.protocol}//${url.host}`;
|
||||
let isChanged = false;
|
||||
console.log("Adding URL Params", protocolHost);
|
||||
console.log("searchParams", url.searchParams);
|
||||
let oldParams = { ...url.searchParams };
|
||||
if (
|
||||
[
|
||||
...redirects.invidious.normal,
|
||||
...redirects.invidious.tor,
|
||||
...invidiousNormalCustomRedirects,
|
||||
...invidiousTorCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) {
|
||||
|
||||
if (applyThemeToSites && !url.searchParams.has("dark_mode") && theme != 'DEFAULT') {
|
||||
if (theme == 'dark') url.searchParams.append("dark_mode", true);
|
||||
else if (theme == 'light') url.searchParams.append("dark_mode", false);
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (!url.searchParams.has("volume") && volume != "--") {
|
||||
url.searchParams.append("volume", volume);
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (!url.searchParams.has("autoplay") && autoplay != "DEFAULT") {
|
||||
url.searchParams.append("autoplay", autoplay);
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (!url.searchParams.has("local") && invidiousAlwaysProxy != "DEFAULT") {
|
||||
url.searchParams.append("local", invidiousAlwaysProxy);
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (!url.searchParams.has("quality") && invidiousVideoQuality != "DEFAULT") {
|
||||
url.searchParams.append("quality", invidiousVideoQuality);
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (!url.searchParams.has("player_style") && invidiousPlayerStyle != "DEFAULT") {
|
||||
url.searchParams.append("player_style", invidiousPlayerStyle);
|
||||
isChanged = true;
|
||||
};
|
||||
|
||||
if (!url.searchParams.has("subtitles") && invidiousSubtitles.trim() != '') {
|
||||
url.searchParams.append("subtitles", invidiousSubtitles);
|
||||
isChanged = true;
|
||||
}
|
||||
}
|
||||
else if (
|
||||
[
|
||||
...redirects.piped.normal,
|
||||
...redirects.piped.tor,
|
||||
...pipedNormalCustomRedirects,
|
||||
...pipedTorCustomRedirects,
|
||||
].includes(protocolHost)
|
||||
) {
|
||||
|
||||
if (!url.searchParams.has("theme") && theme != "DEFAULT") {
|
||||
url.searchParams.append("theme", theme);
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (!url.searchParams.has("volume") && volume != "--") {
|
||||
url.searchParams.append("volume", volume / 100);
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (!url.searchParams.has("playerAutoPlay") && autoplay != "DEFAULT") {
|
||||
url.searchParams.append("playerAutoPlay", autoplay);
|
||||
isChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isChanged) return url.href;
|
||||
else return;
|
||||
}
|
||||
|
||||
function initPipedLocalStorage(tabId) {
|
||||
browser.tabs.executeScript(
|
||||
tabId,
|
||||
|
@ -638,14 +557,46 @@ function initPipedMaterialLocalStorage(tabId) {
|
|||
);
|
||||
}
|
||||
|
||||
function initInvidiousCookies(tabId) {
|
||||
browser.tabs.executeScript(
|
||||
tabId,
|
||||
{
|
||||
file: "/assets/javascripts/helpers/youtube/invidious-preferences.js",
|
||||
runAt: "document_start"
|
||||
}
|
||||
);
|
||||
let applyThemeToSites;
|
||||
function initInvidiousCookies() {
|
||||
console.log("initInvidiousCookies");
|
||||
|
||||
let prefs = {};
|
||||
if (invidiousAlwaysProxy != "DEFAULT") prefs.local = invidiousAlwaysProxy == 'true';
|
||||
if (invidiousVideoQuality != "DEFAULT") prefs.quality = invidiousVideoQuality;
|
||||
if (applyThemeToSites && theme != "DEFAULT") prefs.dark_mode = theme;
|
||||
if (volume != "--") prefs.volume = parseInt(volume);
|
||||
if (invidiousPlayerStyle != "DEFAULT") prefs.player_style = invidiousPlayerStyle;
|
||||
if (invidiousSubtitles != "DEFAULT") prefs.subtitles = invidiousSubtitles;
|
||||
if (autoplay != "DEFAULT") prefs.autoplay = autoplay == 'true';
|
||||
|
||||
let allInstances = [
|
||||
...redirects.invidious.normal,
|
||||
...redirects.invidious.tor,
|
||||
...invidiousNormalCustomRedirects,
|
||||
...invidiousTorCustomRedirects,
|
||||
]
|
||||
|
||||
let checkedInstances = [
|
||||
...invidiousNormalRedirectsChecks,
|
||||
...invidiousNormalCustomRedirects,
|
||||
...invidiousTorRedirectsChecks,
|
||||
...invidiousTorCustomRedirects,
|
||||
];
|
||||
|
||||
for (const item of allInstances)
|
||||
if (!checkedInstances.includes(item))
|
||||
browser.cookies.remove({
|
||||
url: item,
|
||||
name: "PREFS",
|
||||
})
|
||||
|
||||
for (const instanceUrl of checkedInstances)
|
||||
browser.cookies.set({
|
||||
url: instanceUrl,
|
||||
name: "PREFS",
|
||||
value: encodeURIComponent(JSON.stringify(prefs))
|
||||
})
|
||||
}
|
||||
|
||||
async function init() {
|
||||
|
@ -741,6 +692,8 @@ async function init() {
|
|||
|
||||
if (r.youtubeEmbedExceptions) exceptions = r.youtubeEmbedExceptions;
|
||||
|
||||
initInvidiousCookies();
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
@ -769,7 +722,6 @@ export default {
|
|||
changeInstance,
|
||||
|
||||
isPipedorInvidious,
|
||||
addUrlParams,
|
||||
|
||||
getDisable,
|
||||
setDisable,
|
||||
|
|
|
@ -52,7 +52,7 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
var newUrl;
|
||||
|
||||
if (!newUrl) newUrl = youtubeHelper.redirect(url, details, initiator)
|
||||
if (youtubeHelper.isPipedorInvidious(newUrl ?? url, details.type, 'invidious')) newUrl = youtubeHelper.addUrlParams(newUrl ?? url);
|
||||
// if (youtubeHelper.isPipedorInvidious(newUrl ?? url, details.type, 'invidious')) newUrl = youtubeHelper.addUrlParams(newUrl ?? url);
|
||||
if (youtubeMusicHelper.isYoutubeMusic(url, initiator)) newUrl = youtubeMusicHelper.redirect(url, details.type)
|
||||
|
||||
if (!newUrl) newUrl = twitterHelper.redirect(url, initiator);
|
||||
|
@ -162,7 +162,7 @@ browser.tabs.onUpdated.addListener(
|
|||
try { url = new URL(changeInfo.url); }
|
||||
catch (_) { return }
|
||||
if (youtubeHelper.isPipedorInvidious(url, 'main_frame', 'piped')) youtubeHelper.initPipedLocalStorage(tabId);
|
||||
if (twitterHelper.isNitter(url, 'main_frame')) twitterHelper.initNitterCookies(url);
|
||||
// if (twitterHelper.isNitter(url, 'main_frame')) twitterHelper.initNitterCookies();
|
||||
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);
|
||||
|
|
|
@ -97,7 +97,7 @@
|
|||
</div>
|
||||
|
||||
<div class="some-block option-block">
|
||||
<h4>Frontend: <span style="color:red;">This isn't a truly privacy frontend</span></h4>
|
||||
<h4>Frontend: <span style="color:red;">This isn't a fully private frontend</span></h4>
|
||||
<select id="maps-frontend">
|
||||
<option value="pixivMoe">pixiv萌え</option>
|
||||
</select>
|
||||
|
|
|
@ -21,7 +21,7 @@ function changeFrontendsSettings(frontend) {
|
|||
tedditDivElement.style.display = 'block';
|
||||
}
|
||||
else if (frontend == 'old') {
|
||||
frontendElement.innerHTML = `Frontend: <span style="color:red;">This isn't a truly privacy frontend</span>`;
|
||||
frontendElement.innerHTML = `Frontend: <span style="color:red;">This isn't a fully private frontend</span>`;
|
||||
libredditDivElement.style.display = 'none';
|
||||
tedditDivElement.style.display = 'none';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue