about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2024-07-02 14:41:12 +0300
committerManeraKai <manerakai@protonmail.com>2024-07-02 14:41:12 +0300
commitffcb0a887376aa6ecbefd69bbb2d074a46555efa (patch)
treec908a527c107470c839b546e609bb0e2ad2dd2fe
parentMerge pull request #941 from aidan-gibson/master (diff)
downloadlibredirect-ffcb0a887376aa6ecbefd69bbb2d074a46555efa.zip
Re-added Nitter https://github.com/libredirect/browser_extension/issues/934
-rw-r--r--src/assets/javascripts/services.js25
-rw-r--r--src/config.json32
2 files changed, 56 insertions, 1 deletions
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js
index 6801d54b..e47b6293 100644
--- a/src/assets/javascripts/services.js
+++ b/src/assets/javascripts/services.js
@@ -431,6 +431,30 @@ function rewrite(url, frontend, randomInstance) {
 		case "skyview":
 			if (url.pathname == '/') return randomInstance
 			return `${randomInstance}?url=${encodeURIComponent(url.href)}`
+		case "nitter": {
+			let search = new URLSearchParams(url.search)
+
+			search.delete("ref_src")
+			search.delete("ref_url")
+			search.delete("s") // type of device that shared the link
+			search.delete("t") // some sort of tracking ID
+
+			search = search.toString()
+			if (search !== "") search = `?${search}`
+
+			if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") {
+				try {
+					const [, id, format, extra] = search.match(/(.*)\?format=(.*)&(.*)/)
+					const query = encodeURIComponent(`${id}.${format}?${extra}`)
+					return `${randomInstance}/pic${url.pathname}${query}`
+				} catch {
+					return `${randomInstance}/pic${url.pathname}${search}`
+				}
+			}
+			if (url.pathname.split("/").includes("tweets")) return `${randomInstance}${url.pathname.replace("/tweets", "")}${search}`
+			if (url.host == "t.co") return `${randomInstance}/t.co${url.pathname}`
+			return `${randomInstance}${url.pathname}${search}#m`
+		}
 		case "priviblur": {
 			if (url.hostname == "www.tumblr.com") return `${randomInstance}${url.pathname}${url.search}`
 			if (url.hostname.startsWith("assets")) return `${randomInstance}/tblr/assets${url.pathname}${url.search}`
@@ -689,6 +713,7 @@ const defaultInstances = {
 	'tekstoLibre': ['https://davilarek.github.io/TekstoLibre'],
 	'skyview': ['https://skyview.social'],
 	'priviblur': ['https://pb.bloat.cat'],
+	'nitter': ['https://nitter.privacydev.net'],
 }
 
 function initDefaults() {
diff --git a/src/config.json b/src/config.json
index 21e468d7..941d891e 100644
--- a/src/config.json
+++ b/src/config.json
@@ -167,6 +167,36 @@
 			"imageType": "png",
 			"url": "https://music.youtube.com"
 		},
+		"twitter": {
+			"frontends": {
+				"nitter": {
+					"name": "Nitter",
+					"embeddable": true,
+					"instanceList": true,
+					"url": "https://github.com/zedeus/nitter",
+					"localhost": true
+				}
+			},
+			"targets": [
+				"^https?:\\/{2}(www\\.|mobile\\.)?twitter\\.com\\/",
+				"^https?:\\/{2}(www\\.|mobile\\.)?x\\.com\\/",
+				"^https?:\\/{2}(pbs\\.|video\\.)twimg\\.com\\/",
+				"^https?:\\/{2}platform\\.x\\.com/embed\\/",
+				"^https?:\\/{2}platform\\.twitter\\.com/embed\\/",
+				"^https?:\\/{2}t\\.co\\/"
+			],
+			"name": "Twitter",
+			"options": {
+				"enabled": false,
+				"redirectType": "main_frame",
+				"unsupportedUrls": "bypass",
+				"frontend": "nitter",
+				"instance": "public"
+			},
+			"imageType": "png",
+			"embeddable": true,
+			"url": "https://twitter.com"
+		},
 		"bluesky": {
 			"frontends": {
 				"skyview": {
@@ -1073,4 +1103,4 @@
 			"url": "https://paste.libredirect.invalid"
 		}
 	}
-}
+}
\ No newline at end of file