Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeraKai committed Mar 23, 2024
2 parents 715fc11 + 1e53685 commit 8d73647
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 78 deletions.
56 changes: 56 additions & 0 deletions src/assets/images/ifunny-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions src/assets/images/knowyourmeme-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions src/assets/images/tenor-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 66 additions & 57 deletions src/assets/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,68 +62,21 @@ async function redirectAsync(url, type, initiator, forceRedirection) {
}

/**
* @param {URL} url
* @param {string} type
* @param {URL} initiator
* @param {boolean} forceRedirection
* @returns {string | undefined}
* @param url
* @param frontend
* @param randomInstance
* @returns {undefined|string}
*/
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

frontend = options[service].frontend


if (config.services[service].frontends[frontend].desktopApp && type != "main_frame" && options[service].redirectType != "main_frame")
frontend = options[service].embedFrontend


if (!regexArray(service, url, config, frontend)) {
frontend = null
continue
}

if (
config.services[service].embeddable &&
type != options[service].redirectType && options[service].redirectType != "both"
) {
if (options[service].unsupportedUrls == 'block') return 'CANCEL'
return
}

let instanceList = options[frontend]
if (instanceList === undefined) break
if (instanceList.length === 0) return null

if (
initiator
&&
instanceList.includes(initiator.origin)
) {
if (type != "main_frame") return null
else return "BYPASSTAB"
}

randomInstance = utils.getRandomInstance(instanceList)
if (config.services[service].frontends[frontend].localhost && options[service].instance == "localhost") {
randomInstance = `http://${frontend}.localhost:8080`
}
break
}
if (!frontend) return

function rewrite(url, frontend, randomInstance) {
if (!frontend || !randomInstance) return
switch (frontend) {
case "hyperpipe": {
return `${randomInstance}${url.pathname}${url.search}`.replace(/\/search\?q=.*/, searchQuery => searchQuery.replace("?q=", "/"))
}
case "searx":
case "searxng":
case "searxng": {
return `${randomInstance}/${url.search}`
}
case "whoogle": {
return `${randomInstance}/search${url.search}`
}
Expand All @@ -149,7 +102,6 @@ function redirect(url, type, initiator, forceRedirection, incognito) {
case "freetubePwa": {
return 'freetube://' + url.href
}

case "poketube": {
if (url.pathname.startsWith('/channel')) {
const reg = /\/channel\/(.*)\/?$/.exec(url.pathname)
Expand Down Expand Up @@ -415,7 +367,7 @@ function redirect(url, type, initiator, forceRedirection, incognito) {
if (url.hostname.endsWith('bandcamp.com')) {
const regex = /^(.*)\.bandcamp\.com/.exec(url.hostname)
const artist = regex[1]
if (url.pathname == '/') {
if (url.pathname == '/' || url.pathname == '/music') {
return `${randomInstance}/artist.php?name=${artist}`
} else {
const regex = /^\/(.*)\/(.*)/.exec(url.pathname)
Expand Down Expand Up @@ -557,6 +509,60 @@ function redirect(url, type, initiator, forceRedirection, incognito) {
}
}

/**
* @param {URL} url
* @param {string} type
* @param {URL} initiator
* @param {boolean} forceRedirection
* @returns {string | undefined}
*/
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

frontend = options[service].frontend

if (config.services[service].frontends[frontend].desktopApp && type != "main_frame" && options[service].redirectType != "main_frame")
frontend = options[service].embedFrontend

if (!regexArray(service, url, config, frontend)) {
frontend = null
continue
}

if (
config.services[service].embeddable
&&
type != options[service].redirectType && options[service].redirectType != "both"
) {
if (options[service].unsupportedUrls == 'block') return 'CANCEL'
return
}

let instanceList = options[frontend]
if (instanceList === undefined) break
if (instanceList.length === 0) return null

if (initiator && instanceList.includes(initiator.origin)) {
if (type != "main_frame") return null
else return "BYPASSTAB"
}

randomInstance = utils.getRandomInstance(instanceList)
if (config.services[service].frontends[frontend].localhost && options[service].instance == "localhost") {
randomInstance = `http://${frontend}.localhost:8080`
}
break
}
if (!frontend) return

return rewrite(url, frontend, randomInstance)
}

/**
* @param {URL} url
* @param {*} returnFrontend
Expand Down Expand Up @@ -711,6 +717,9 @@ const defaultInstances = {
'biblioReads': ['https://biblioreads.ml'],
'wikiless': ['https://wikiless.org'],
'suds': ['https://sd.vern.cc'],
'unfunny': ['https://uf.vern.cc'],
'soprano': ['https://sp.vern.cc'],
'meme': ['https://mm.vern.cc'],
'waybackClassic': ['https://wayback-classic.net'],
'gothub': ['https://gh.odyssey346.dev'],
'mikuInvidious': ['https://mikuinv.resrv.org'],
Expand Down
Loading

0 comments on commit 8d73647

Please sign in to comment.