Right-click blocker on img tags only
This commit is contained in:
parent
f23a787d32
commit
f618973e80
|
@ -1,40 +1,16 @@
|
||||||
// Right-click button handler, to dissuade downloading.
|
// Right-click button handler, to dissuade downloading.
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
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"),
|
const $modal = document.querySelector("#rightclick-modal"),
|
||||||
$button = $modal.querySelector("button"),
|
$button = $modal.querySelector("button"),
|
||||||
cls = 'is-active';
|
cls = 'is-active';
|
||||||
|
|
||||||
console.log("register right clicks");
|
(document.querySelectorAll('img, video') || []).forEach(node => {
|
||||||
console.log($modal, $button);
|
node.addEventListener('contextmenu', (e) => {
|
||||||
|
$modal.classList.add(cls);
|
||||||
document.addEventListener('contextmenu', (e) => {
|
e.preventDefault();
|
||||||
$modal.classList.add(cls);
|
});
|
||||||
e.preventDefault();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$button.addEventListener('click', () => {
|
$button.addEventListener('click', () => {
|
||||||
$modal.classList.remove(cls);
|
$modal.classList.remove(cls);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user