From f618973e805f41bc01650ba2fecd7c968702760b Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Mon, 27 Nov 2023 22:07:40 -0800 Subject: [PATCH] Right-click blocker on img tags only --- web/static/js/right-click.js | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/web/static/js/right-click.js b/web/static/js/right-click.js index 7d57c66..4dd33f2 100644 --- a/web/static/js/right-click.js +++ b/web/static/js/right-click.js @@ -1,40 +1,16 @@ // Right-click button handler, to dissuade downloading. document.addEventListener('DOMContentLoaded', () => { - // Whitelist of paths to NOT engage the script on (because it's annoying) - let path = window.location.pathname; - if (path === "/") return; - let pathWhitelist = [ - "/messages", - "/forum/post", - "/f/", - "/settings", - "/photo/certification", - "/notes/me", - "/notes/u/", - "/admin", - "/about", - "/faq", - "/tos", - "/privacy", - "/contact", - ]; - for (let prefix of pathWhitelist) { - if (path.indexOf(prefix) === 0) { - return; - } - } - const $modal = document.querySelector("#rightclick-modal"), $button = $modal.querySelector("button"), cls = 'is-active'; - console.log("register right clicks"); - console.log($modal, $button); - - document.addEventListener('contextmenu', (e) => { - $modal.classList.add(cls); - e.preventDefault(); + (document.querySelectorAll('img, video') || []).forEach(node => { + node.addEventListener('contextmenu', (e) => { + $modal.classList.add(cls); + e.preventDefault(); + }); }); + $button.addEventListener('click', () => { $modal.classList.remove(cls); });