aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-08-27 11:55:51 +0200
committerWojtek Kosior <koszko@koszko.org>2022-08-27 14:21:53 +0200
commita1a8d9cb51ca9bbe14eb40cc1fced326fb38c230 (patch)
treee4e684c32366dbcaf73a87cc7f3c0c34dfe56b13
parent7e0bcba919b0bb27f8131f3a9acc0cc2bd2e5764 (diff)
downloadhydrilla-fixes-bundle-a1a8d9cb51ca9bbe14eb40cc1fced326fb38c230.tar.gz
hydrilla-fixes-bundle-a1a8d9cb51ca9bbe14eb40cc1fced326fb38c230.zip
[Stack Exchange] add new fix to enable registrations
-rw-r--r--src/stackexchange-com-fixes/LICENSES/Apache-2.0.txt (renamed from src/stack-exchange-fix-cookienotice/LICENSES/Apache-2.0.txt)0
-rw-r--r--src/stackexchange-com-fixes/LICENSES/CC0-1.0.txt (renamed from src/stack-exchange-fix-cookienotice/LICENSES/CC0-1.0.txt)0
-rw-r--r--src/stackexchange-com-fixes/index.json (renamed from src/stack-exchange-fix-cookienotice/index.json)45
-rw-r--r--src/stackexchange-com-fixes/login-redirect.js21
-rw-r--r--src/stackexchange-com-fixes/register.js68
-rw-r--r--src/stackexchange-com-fixes/stack_exchange_cookienotice.js (renamed from src/stack-exchange-fix-cookienotice/stack_exchange_cookienotice.js)0
6 files changed, 127 insertions, 7 deletions
diff --git a/src/stack-exchange-fix-cookienotice/LICENSES/Apache-2.0.txt b/src/stackexchange-com-fixes/LICENSES/Apache-2.0.txt
index 137069b..137069b 100644
--- a/src/stack-exchange-fix-cookienotice/LICENSES/Apache-2.0.txt
+++ b/src/stackexchange-com-fixes/LICENSES/Apache-2.0.txt
diff --git a/src/stack-exchange-fix-cookienotice/LICENSES/CC0-1.0.txt b/src/stackexchange-com-fixes/LICENSES/CC0-1.0.txt
index 0e259d4..0e259d4 100644
--- a/src/stack-exchange-fix-cookienotice/LICENSES/CC0-1.0.txt
+++ b/src/stackexchange-com-fixes/LICENSES/CC0-1.0.txt
diff --git a/src/stack-exchange-fix-cookienotice/index.json b/src/stackexchange-com-fixes/index.json
index 095fdec..961dfc8 100644
--- a/src/stack-exchange-fix-cookienotice/index.json
+++ b/src/stackexchange-com-fixes/index.json
@@ -5,21 +5,20 @@
{
"$schema": "https://hydrilla.koszko.org/schemas/package_source-2.schema.json",
- "source_name": "stack-exchange-fix-cookienotice",
+ "source_name": "stackexchange-com-fixes",
"copyright": [
{"file": "report.spdx"},
{"file": "LICENSES/Apache-2.0.txt"},
{"file": "LICENSES/CC0-1.0.txt"}
],
- "upstream_url": "https://git.koszko.org/hydrilla-fixes-bundle/tree/src/stack-exchange-fix-cookienotice",
+ "upstream_url": "https://git.koszko.org/hydrilla-fixes-bundle/tree/src/stackexchange-com-fixes",
"definitions": [{
-
"type": "mapping_and_resource",
"identifier": "stack-exchange-fix-cookienotice",
- "long_name": "StackExchange cookie notice fix",
- "version": [2022, 2, 18],
- "revision": 2,
- "description": "Make cookie notice on StackExchange websites closable without relying on site-served JavaScript.",
+ "long_name": "Stack Exchange cookie notice fix",
+ "version": [2022, 8, 27],
+ "revision": 1,
+ "description": "Make cookie notice on Stack Exchange websites closable without relying on site-served JavaScript.",
"dependencies": [],
"scripts": [{"file": "stack_exchange_cookienotice.js"}],
"payloads": {
@@ -58,6 +57,38 @@
"identifier": "stack-exchange-fix-cookienotice"
}
}
+ }, {
+ "type": "mapping_and_resource",
+ "identifier": "meta-stackexchange-com-fix-login-redirect",
+ "long_name": "Stack Exchange login redirect fix",
+ "uuid": "3f006539-f43f-4f71-998a-6a7ce0ebf4b3",
+ "version": [2022, 8, 27],
+ "revision": 1,
+ "description": "Make automatic redirect on Stack Exchange login page work without relying on site-served JavaScript.",
+ "dependencies": [],
+ "scripts": [{"file": "login-redirect.js"}],
+ "payloads": {
+ "https://meta.stackexchange.com/users/login": {
+ "identifier": "meta-stackexchange-com-fix-login-redirect"
+ }
+ }
+ }, {
+ "type": "mapping_and_resource",
+ "identifier": "meta-stackexchange-com-fix-register",
+ "long_name": "Stack Exchange registration fix",
+ "uuid": "e0a00885-bac6-43e8-a8ea-e013f733c8cf",
+ "version": [2022, 8, 27],
+ "revision": 1,
+ "description": "Enable registration of a Stack Exchange account without relying on site-served JavaScript.",
+ "dependencies": [{"identifier": "stack-exchange-fix-cookienotice"}, {"identifier": "hacktcha"}],
+ "required_mappings": [{"identifier": "meta-stackexchange-com-fix-login-redirect"}, {"identifier": "stack-exchange-fix-cookienotice"}],
+ "scripts": [{"file": "register.js"}],
+ "payloads": {
+ // * https://meta.stackexchange.com/users/signup
+ "https://meta.stackexchange.com/users/signup": {
+ "identifier": "meta-stackexchange-com-fix-register"
+ }
+ }
}],
"reuse_generate_spdx_report": true
}
diff --git a/src/stackexchange-com-fixes/login-redirect.js b/src/stackexchange-com-fixes/login-redirect.js
new file mode 100644
index 0000000..60c4e39
--- /dev/null
+++ b/src/stackexchange-com-fixes/login-redirect.js
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: CC0-1.0
+ *
+ * Fix automatic redirect on Stack Exchange login page.
+ *
+ * Copyright (C) 2022 Wojtek Kosior
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the CC0 1.0 Universal License as published by
+ * the Creative Commons Corporation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * CC0 1.0 Universal License for more details.
+ */
+
+/* Use with https://meta.stackexchange.com/users/login */
+
+const redirect_link = document.querySelector(".manual-redirect a");
+if (redirect_link !== null)
+ window.location.href = redirect_link.href;
diff --git a/src/stackexchange-com-fixes/register.js b/src/stackexchange-com-fixes/register.js
new file mode 100644
index 0000000..b00dba1
--- /dev/null
+++ b/src/stackexchange-com-fixes/register.js
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: CC0-1.0
+ *
+ * Use Hacktcha on Stack Exchange registration page.
+ *
+ * Copyright (C) 2022 Wojtek Kosior
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the CC0 1.0 Universal License as published by
+ * the Creative Commons Corporation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * CC0 1.0 Universal License for more details.
+ */
+
+/* Use with https://meta.stackexchange.com/users/signup */
+
+/* Load captcha-parent.js first. */
+
+(async () => {
+ const captcha_div = document.createElement("div");
+ const submit_but = document.getElementById("submit-button");
+ const token_field = document.createElement("textarea");
+
+ /*
+ * Let's remove <noscript> tag with the original reCAPTCHA iframe and an
+ * unnecessary button.
+ */
+ document.querySelector("#no-captcha-here + *").remove();
+ for (const elem of [...captcha_div.childNodes])
+ elem.remove();
+
+ token_field.name = "g-recaptcha-response";
+ token_field.style.display = "none";
+
+ document.getElementById("no-captcha-here").after(token_field);
+ token_field.after(captcha_div);
+
+ /*
+ * The reCAPTCHA site key is present in 2 places: in a script and in fallback iframe's
+ * URL. Let's use the former as the source for now.
+ */
+ let site_key;
+ const site_key_regex = /['"]sitekey['"]\s*:\s*['"]([a-zA-Z0-9-]+)['"]/;
+
+ for (const script of document.scripts) {
+ match = site_key_regex.exec(script.textContent);
+ if (match !== null)
+ site_key = match[1];
+ }
+
+ if (site_key === null) {
+ console.error("Could not extract site key :(");
+ return;
+ }
+
+ submit_but.setAttribute("disabled", "");
+
+ for await (const token of HCHA.run(captcha_div, site_key)) {
+ if (token === null) {
+ submit_but.setAttribute("disabled", "");
+ } else {
+ token_field.value = token;
+ submit_but.removeAttribute("disabled");
+ }
+ }
+})();
diff --git a/src/stack-exchange-fix-cookienotice/stack_exchange_cookienotice.js b/src/stackexchange-com-fixes/stack_exchange_cookienotice.js
index 37a42ac..37a42ac 100644
--- a/src/stack-exchange-fix-cookienotice/stack_exchange_cookienotice.js
+++ b/src/stackexchange-com-fixes/stack_exchange_cookienotice.js