website/web/static/js/right-click.js
2023-12-21 20:38:18 -08:00

28 lines
884 B
JavaScript

// Right-click button handler, to dissuade downloading.
document.addEventListener('DOMContentLoaded', () => {
const $modal = document.querySelector("#rightclick-modal"),
$button = $modal.querySelector("button"),
cls = 'is-active';
// Disable context menu on all images.
(document.querySelectorAll('img, video') || []).forEach(node => {
node.addEventListener('contextmenu', (e) => {
$modal.classList.add(cls);
e.preventDefault();
});
});
// Make images not draggable.
(document.querySelectorAll('img') || []).forEach(node => {
node.addEventListener('dragstart', (e) => {
e.preventDefault();
return false;
});
node.setAttribute("draggable", "false");
});
$button.addEventListener('click', () => {
$modal.classList.remove(cls);
});
});