Skip to content

Commit

Permalink
Added Redirect Only In Incognito #858
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeraKai committed Nov 24, 2023
1 parent 928d5f9 commit 5e51ebd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/assets/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ async function redirectAsync(url, type, initiator, forceRedirection) {
* @param {boolean} forceRedirection
* @returns {string | undefined}
*/
function redirect(url, type, initiator, forceRedirection) {
function redirect(url, type, initiator, forceRedirection, incognito) {
if (type != "main_frame" && type != "sub_frame" && type != "image") return
let randomInstance
let frontend
if (!forceRedirection && options.redirectOnlyInIncognito == true && !incognito) return
for (const service in config.services) {
if (!forceRedirection && !options[service].enabled) continue

Expand Down Expand Up @@ -762,9 +763,10 @@ function initDefaults() {
url: [],
regex: [],
}
options['theme'] = "detect"
options['popupServices'] = ["youtube", "twitter", "tiktok", "imgur", "reddit", "quora", "translate", "maps"]
options['fetchInstances'] = 'github'
options.theme = "detect"
options.popupServices = ["youtube", "twitter", "tiktok", "imgur", "reddit", "quora", "translate", "maps"]
options.fetchInstances = 'github'
options.redirectOnlyInIncognito = false

options = { ...options, ...defaultInstances }

Expand Down
2 changes: 1 addition & 1 deletion src/pages/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ browser.webRequest.onBeforeRequest.addListener(
return null
}
if (tabIdRedirects[details.tabId] == false) return null
let newUrl = servicesHelper.redirect(url, details.type, initiator, tabIdRedirects[details.tabId], details.tabId)
let newUrl = servicesHelper.redirect(url, details.type, initiator, tabIdRedirects[details.tabId], details.incognito)

if (details.frameAncestors && details.frameAncestors.length > 0 && servicesHelper.isException(new URL(details.frameAncestors[0].url))) newUrl = null

Expand Down
7 changes: 6 additions & 1 deletion src/pages/options/widgets/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ importSettingsElement.addEventListener("change", () => {
}
})


const exportSettingsSync = document.getElementById("export-settings-sync")
const importSettingsSync = document.getElementById("import-settings-sync")
const importSettingsSyncText = document.getElementById("import_settings_sync_text")
Expand Down Expand Up @@ -105,6 +104,11 @@ fetchInstancesElement.addEventListener('change', event => {
location.reload()
})

const redirectOnlyInIncognitoElement = document.getElementById('redirectOnlyInIncognito')
redirectOnlyInIncognitoElement.addEventListener('change', event => {
setOption('redirectOnlyInIncognito', 'checkbox', event)
})

let themeElement = document.getElementById("theme")
themeElement.addEventListener("change", event => {
setOption("theme", "select", event)
Expand Down Expand Up @@ -132,6 +136,7 @@ for (const service in config.services) {
let options = await utils.getOptions()
themeElement.value = options.theme
fetchInstancesElement.value = options.fetchInstances
redirectOnlyInIncognitoElement.target.checked = options.redirectOnlyInIncognito
for (const service in config.services) document.getElementById(service).checked = options.popupServices.includes(service)

instanceTypeElement.addEventListener("change", event => {
Expand Down
14 changes: 9 additions & 5 deletions src/pages/options/widgets/general.pug
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ section(class="block-option" id="general_page")
option(value="codeberg") Codeberg
option(value="disable" data-localise="__MSG_disable__") Disable

div(class="block block-option")
label(for='redirectOnlyInIncognito' data-localise="__MSG_redirectOnlyInIncognito__") Redirect Only in Incognito
input(id='redirectOnlyInIncognito' type="checkbox")

div(class="block block-option")
label(data-localise="__MSG_excludeFromRedirecting__") Excluded from redirecting

Expand Down Expand Up @@ -44,23 +48,23 @@ section(class="block-option" id="general_page")
| 
x(data-localise="__MSG_importSettings__") Import Settings
input(id="import-settings" type="file" style="display: none")

|  

a(class="button button-inline" id="export-settings")
svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor")
path(d="M10.09 15.59L11.5 17l5-5-5-5-1.41 1.41L12.67 11H3v2h9.67l-2.58 2.59zM19 3H5c-1.11 0-2 .9-2 2v4h2V5h14v14H5v-4H3v4c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z")
| 
x(data-localise="__MSG_exportSettings__") Export Settings

|  

button(class="button button-inline" id="export-settings-sync")
svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor")
path(d="M10.09 15.59L11.5 17l5-5-5-5-1.41 1.41L12.67 11H3v2h9.67l-2.58 2.59zM19 3H5c-1.11 0-2 .9-2 2v4h2V5h14v14H5v-4H3v4c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z")
| 
x() Export Settings to Sync

|  

button(class="button button-inline" id="import-settings-sync")
Expand All @@ -70,7 +74,7 @@ section(class="block-option" id="general_page")
x(id="import_settings_sync_text") Import Settings from Sync

|  

button(class="button button-inline" id="reset-settings")
svg(xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor")
path(d="M12,5V2L8,6l4,4V7c3.31,0,6,2.69,6,6c0,2.97-2.17,5.43-5,5.91v2.02c3.95-0.49,7-3.85,7-7.93C20,8.58,16.42,5,12,5z")
Expand Down

0 comments on commit 5e51ebd

Please sign in to comment.