aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorEliot Partridge <byte@code.horse>2021-12-19 17:57:34 -0600
committerGitHub <noreply@github.com>2021-12-19 18:57:34 -0500
commit0fcaf87b1afcbec16e6dcaba9f007ea63f650601 (patch)
tree9f3b13e14a2cbece82d795a8d93a624a0d497695 /static
parent6df97ccc87f426a994d1db48812910a9c27e75ee (diff)
downloadxesite-0fcaf87b1afcbec16e6dcaba9f007ea63f650601.tar.xz
xesite-0fcaf87b1afcbec16e6dcaba9f007ea63f650601.zip
Improve domain matching for nag warning, add more reddit domains (#420)
Diffstat (limited to 'static')
-rw-r--r--static/js/hnwarn.js23
1 files changed, 10 insertions, 13 deletions
diff --git a/static/js/hnwarn.js b/static/js/hnwarn.js
index b2bfeae..c56bcfe 100644
--- a/static/js/hnwarn.js
+++ b/static/js/hnwarn.js
@@ -2,6 +2,12 @@ import { g, x, r, t } from "./xeact.min.js";
import { div, ahref, br } from "./xeact-html.min.js";
import { mkConversation } from "./conversation.js";
+// list of regexps for potentially problematic referrers to display the nag to
+const FLAGGED_REFERRERS = [
+ /^https?:\/\/((.+)\.)?reddit\.com/i,
+ /^https?:\/\/news\.ycombinator\.com/i,
+];
+
const addNag = () => {
let root = g("refererNotice");
x(root);
@@ -20,19 +26,10 @@ const addNag = () => {
};
r(() => {
- switch (document.referrer) {
- case "https://news.ycombinator.com/":
- addNag();
- break;
- case "https://www.reddit.com/":
- addNag();
- break;
- case "https://old.reddit.com/":
- addNag();
- break;
- case "https://reddit.com/":
+ const ref = document.referrer;
+ if (!ref) return;
+
+ if (FLAGGED_REFERRERS.some(r => r.test(ref))) {
addNag();
- break;
}
});
-