about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2023-03-07 17:25:43 +0300
committerManeraKai <manerakai@protonmail.com>2023-03-07 17:25:48 +0300
commit9a7c2ce3cbd0b80c241180daa8c55eff6e8ecc42 (patch)
tree0772bf85cb22fb06c47e4b21dd884262ecf496ac /src
parentFixed bug in RedirectType in settings (diff)
downloadlibredirect-9a7c2ce3cbd0b80c241180daa8c55eff6e8ecc42.zip
Supported Stackexchange https://github.com/libredirect/libredirect/issues/636
Diffstat (limited to 'src')
-rw-r--r--src/assets/javascripts/services.js14
-rw-r--r--src/config.json3
2 files changed, 12 insertions, 5 deletions
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js
index 3481273c..bedc3549 100644
--- a/src/assets/javascripts/services.js
+++ b/src/assets/javascripts/services.js
@@ -459,10 +459,16 @@ function redirect(url, type, initiator, forceRedirection) {
 		}
 		case "anonymousOverflow": {
 			if (!url.pathname.startsWith('/questions') && url.pathname != '/') return
-			const threadID = /\/(\d+)\/?$/.exec(url.pathname)
-			if (threadID) return `${randomInstance}/questions/${threadID[1]}${url.search}`
-			return `${randomInstance}${url.pathname}${url.search}`
-
+			if (url.hostname == "stackoverflow.com") {
+				const threadID = /\/(\d+)\/?$/.exec(url.pathname)
+				if (threadID) return `${randomInstance}/questions/${threadID[1]}${url.search}`
+				return `${randomInstance}${url.pathname}${url.search}`
+			}
+			const regex = url.href.match(/https?:\/{2}(?:([a-zA-Z0-9-]+)\.)?stackexchange\.com\//)
+			if (regex && regex.length > 1) {
+				const subdomain = regex[1]
+				return `${randomInstance}/exchange/${subdomain}${url.pathname}${url.search}`
+			}
 		}
 		case "biblioReads": {
 			if (!url.pathname.startsWith('/book/show/') && url.pathname != '/') return
diff --git a/src/config.json b/src/config.json
index 107a78ed..3bd300a8 100644
--- a/src/config.json
+++ b/src/config.json
@@ -562,7 +562,8 @@
 				}
 			},
 			"targets": [
-				"^https?:\\/{2}stackoverflow\\.com\\/"
+				"^https?:\\/{2}?stackoverflow\\.com\\/",
+				"^https?:\\/{2}([a-zA-Z0-9-]+\\.)?stackexchange\\.com\\/"
 			],
 			"name": "Stack Overflow",
 			"options": {