Skip to content

Commit

Permalink
Update worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kerivin authored Nov 22, 2024
1 parent 6644fc0 commit ffabc5e
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,32 @@ async function onInlineQuery (inlineQuery) {
const json = await response.json();
console.log("JSON: ", JSON.stringify(json));

const url = new URL(inlineQuery.query)
var url = new URL(inlineQuery.query)
console.log("Hostname: ", url.hostname)

var title = "Embed Link"

json.every(function(entry) {
const regex = new RegExp(entry.source, "gi")
if (regex.test(url.hostname)) {
console.log("Regex detected: ", entry.source)
const validTarget = entry.target.find(urlExists)
console.log("Valid target URL: ", validTarget)
if (validTarget !== undefined) {
//url.hostname.replace(regex, validTarget)
url.hostname = validTarget
console.log("New hostname: ", url.hostname)
title = entry.name
return false
}
if (!regex.test(url.hostname)) {
return true
}
return true
console.log("Regex detected: ", entry.source)

const keepSearching = entry.target.every(function(target) {
const checkURL = new URL(url.toString())
checkURL.hostname = target
if (!urlExists(checkURL.toString())) {
return true
}

url = checkURL
title = entry.name
console.log("Valid target URL: ", validTarget)
return false
})

return keepSearching
})

console.log("Fixed URL: ", url)
Expand Down

0 comments on commit ffabc5e

Please sign in to comment.