Added bypass on reddit option

This commit is contained in:
ManeraKai 2022-02-26 18:28:19 +03:00
parent f4d07c15ac
commit 3246d6fd69
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
4 changed files with 48 additions and 12 deletions

View File

@ -184,21 +184,40 @@ function setProtocol(val) {
console.log("redditProtocol: ", val)
}
function isReddit(url, initiator) {
if (
initiator &&
(
[...redirects.libreddit.normal, ...libredditNormalCustomRedirects].includes(initiator.origin) ||
[...redirects.teddit.normal, ...tedditNormalCustomRedirects].includes(initiator.origin) ||
targets.includes(initiator.host)
)
) return false;
return targets.includes(url.host)
function isReddit(url,) {
}
function redirect(url, type) {
let bypassWatchOnReddit;
const getBypassWatchOnReddit = () => bypassWatchOnReddit;
function setBypassWatchOnReddit(val) {
bypassWatchOnReddit = val;
browser.storage.local.set({ bypassWatchOnReddit })
console.log("bypassWatchOnReddit: ", bypassWatchOnReddit)
}
function redirect(url, type, initiator) {
if (disableReddit) return null;
if (
bypassWatchOnReddit &&
initiator &&
(
[...redirects.libreddit.normal,
...redirects.libreddit.tor,
...libredditNormalCustomRedirects,
...libredditTorCustomRedirects,
...redirects.teddit.normal,
...redirects.teddit.tor,
...tedditNormalCustomRedirects,
...tedditTorCustomRedirects,
].includes(initiator.origin) ||
targets.includes(initiator.host)
)
) return 'BYBASSTAB';
if ((!targets.includes(url.host))) return null;
if (type !== "main_frame" || url.pathname.match(bypassPaths)) return null;
if (frontend == 'old') return `${redirects.desktop}${url.pathname}${url.search}`;
@ -314,11 +333,14 @@ async function init() {
"tedditTorCustomRedirects",
"redditProtocol",
"bypassWatchOnReddit",
], (result) => {
disableReddit = result.disableReddit ?? false;
protocol = result.redditProtocol ?? 'normal';
frontend = result.redditFrontend ?? 'libreddit';
bypassWatchOnReddit = result.bypassWatchOnReddit ?? true;
redirects.teddit = dataJson.teddit;
if (result.redditRedirects) redirects = result.redditRedirects;
@ -359,6 +381,9 @@ export default {
getProtocol,
setProtocol,
getBypassWatchOnReddit,
setBypassWatchOnReddit,
getLibredditNormalRedirectsChecks,
setLibredditNormalRedirectsChecks,
getLibredditTorRedirectsChecks,

View File

@ -60,7 +60,7 @@ browser.webRequest.onBeforeRequest.addListener(
if (mapsHelper.isMaps(url, initiator)) newUrl = mapsHelper.redirect(url);
if (redditHelper.isReddit(url, initiator)) newUrl = redditHelper.redirect(url, details.type);
if (!newUrl) newUrl = redditHelper.redirect(url, details.type, initiator);
if (mediumHelper.isMedium(url, initiator)) newUrl = mediumHelper.redirect(url, details.type);

View File

@ -136,6 +136,11 @@
</select>
</div>
<div class="some-block option-block">
<h4>Bypass Watch On Reddit</h4>
<input id="bypass-watch-on-reddit" type="checkbox" checked />
</div>
<hr>
<div id="libreddit">

View File

@ -61,8 +61,14 @@ function changeProtocolSettings(protocol) {
}
}
let bypassWatchOnRedditElement = document.getElementById("bypass-watch-on-reddit")
bypassWatchOnRedditElement.addEventListener("change",
event => redditHelper.setBypassWatchOnReddit(event.target.checked)
);
redditHelper.init().then(() => {
disableRedditElement.checked = !redditHelper.getDisableReddit();
bypassWatchOnRedditElement.checked = redditHelper.getBypassWatchOnReddit();
let frontend = redditHelper.getFrontend();
redditFrontendElement.value = frontend;