Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Added Skychat support, async for redirect callback #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions 24 src/assets/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function regexArray(service, url, config, options, frontend) {
* @param {string} type
* @returns {undefined|string}
*/
function rewrite(url, originUrl, frontend, randomInstance, type) {
async function rewrite(url, originUrl, frontend, randomInstance, type) {
switch (frontend) {
case "hyperpipe":
for (const key of [...url.searchParams.keys()]) if (key !== "q") url.searchParams.delete(key)
Expand Down Expand Up @@ -490,6 +490,23 @@ function rewrite(url, originUrl, frontend, randomInstance, type) {
case "skyview":
if (url.pathname == "/") return randomInstance
return `${randomInstance}?url=${encodeURIComponent(url.href)}`
case "skychat":
if (url.pathname == "/") return randomInstance
// Can't encode or the / gets escaped, slicing off first slash
const bskyPath = url.pathname.slice(1)
if (bskyPath.includes("/post/")) {
console.log(`Path ${bskyPath} is a post`)
const pathParts = bskyPath.split("/")
var userDid = pathParts[1]
if (!userDid.startsWith("did:plc:")) {
const did = await utils.handleToDid(userDid)
return `${randomInstance}/#thread/${did}/${pathParts[3]}`
} else {
return `${randomInstance}/#thread/${userDid}/${pathParts[3]}`
}
} else {
return `${randomInstance}/#${bskyPath}`
}
case "nitter": {
let search = new URLSearchParams(url.search)

Expand Down Expand Up @@ -640,7 +657,7 @@ function rewrite(url, originUrl, frontend, randomInstance, type) {
* @param {boolean} forceRedirection
* @returns {string | undefined}
*/
function redirect(url, type, originUrl, documentUrl, incognito, forceRedirection) {
async function redirect(url, type, originUrl, documentUrl, incognito, forceRedirection) {
if (type != "main_frame" && type != "sub_frame" && type != "image") return
let randomInstance
let frontend
Expand Down Expand Up @@ -697,7 +714,7 @@ function redirect(url, type, originUrl, documentUrl, incognito, forceRedirection
}
if (!frontend) return

return rewrite(url, originUrl, frontend, randomInstance, type)
return await rewrite(url, originUrl, frontend, randomInstance, type)
}

/**
Expand Down Expand Up @@ -925,6 +942,7 @@ const defaultInstances = {
tuboSoundcloud: ["https://tubo.media"],
tekstoLibre: ["https://davilarek.github.io/TekstoLibre"],
skyview: ["https://skyview.social"],
skychat: ["https://skychat.social"],
priviblur: ["https://pb.bloat.cat"],
nitter: ["https://nitter.privacydev.net"],
pasted: ["https://pasted.drakeerv.com"],
Expand Down
40 changes: 40 additions & 0 deletions 40 src/assets/javascripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,45 @@ function addressToLatLng(address) {
}
}

async function handleToDid(handle) {
console.log("Have to look up DID")
// DNS lookup via Cloudflare first
try {
const dnsResponse = await fetch(`https://cloudflare-dns.com/dns-query?name=_atproto.${handle}&type=TXT`, {
headers: {
"accept": "application/dns-json"
}
}
)
if (dnsResponse.ok) {
const dnsJson = await dnsResponse.json()
if (dnsJson.Status == 0) {
// parse, strip quotes, and strip leading "did="
const userDid = dnsJson.Answer[0].data.replaceAll("\"","").slice(4)
console.log(`DNS lookup returned ${userDid}`)
return userDid
} else {
// If not in TXT records, get via .well-known
const wellKnownResponse = await fetch(
`https://${handle}/.well-known/atproto-did`
)
if (wellKnownResponse.ok) {
const wellKnownText = await wellKnownResponse.text()
console.log(`userDid was ${wellKnownText} via web`)
return wellKnownText.trim()
}
}
} else {
console.log(`Failed: ${dnsResponse.status}: ${dnsResponse}`)
console.log(`Failed: ${wellKnownResponse.status}: ${wellKnownResponse}`)
}
return handle
} catch(e) {
console.log(e.message)
return handle
}
}

function getQuery(url) {
let query = ""
if (url.searchParams.has("q")) query = url.searchParams.get("q")
Expand Down Expand Up @@ -288,6 +327,7 @@ export default {
getPingCache,
ping,
addressToLatLng,
handleToDid,
getQuery,
prefsEncoded,
convertMapCentre,
Expand Down
5 changes: 5 additions & 0 deletions 5 src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@
},
"bluesky": {
"frontends": {
"skychat": {
"name": "Skychat",
"instanceList": true,
"url": "https://github.com/badlogic/skychat"
},
"skyview": {
"name": "Skyview",
"instanceList": true,
Expand Down
2 changes: 1 addition & 1 deletion 2 src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "3.1.0",
"version": "3.2.0",
"manifest_version": 2,
"browser_specific_settings": {
"gecko": {
Expand Down
11 changes: 6 additions & 5 deletions 11 src/pages/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ browser.runtime.onInstalled.addListener(async details => {
// true to redirect, false to bypass
let tabIdRedirects = {}

// true == Always redirect, false == Never redirect, null/undefined == follow options for services
browser.webRequest.onBeforeRequest.addListener(
details => {

async function redirectCallback(details) {
const old_href = details.url
const url = new URL(details.url)
if (new RegExp(/^chrome-extension:\/{2}.*\/instances\/.*.json$/).test(url.href) && details.type == "xmlhttprequest")
Expand Down Expand Up @@ -59,7 +58,7 @@ browser.webRequest.onBeforeRequest.addListener(
return null
}

let newUrl = servicesHelper.redirect(
let newUrl = await servicesHelper.redirect(
url,
details.type,
originUrl,
Expand Down Expand Up @@ -113,7 +112,9 @@ browser.webRequest.onBeforeRequest.addListener(
return { redirectUrl: newUrl }
}
return null
},
}
// true == Always redirect, false == Never redirect, null/undefined == follow options for services
browser.webRequest.onBeforeRequest.addListener(redirectCallback,
{ urls: ["<all_urls>"] },
["blocking"]
)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.