website/web/static/js/right-click.js

28 lines
884 B
JavaScript
Raw Permalink Normal View History

2023-11-28 05:23:31 +00:00
// Right-click button handler, to dissuade downloading.
document.addEventListener('DOMContentLoaded', () => {
const $modal = document.querySelector("#rightclick-modal"),
$button = $modal.querySelector("button"),
cls = 'is-active';
2023-12-22 04:38:18 +00:00
// Disable context menu on all images.
2023-11-28 06:07:40 +00:00
(document.querySelectorAll('img, video') || []).forEach(node => {
node.addEventListener('contextmenu', (e) => {
$modal.classList.add(cls);
e.preventDefault();
});
2023-11-28 05:23:31 +00:00
});
2023-11-28 06:07:40 +00:00
2023-12-22 04:38:18 +00:00
// Make images not draggable.
(document.querySelectorAll('img') || []).forEach(node => {
node.addEventListener('dragstart', (e) => {
e.preventDefault();
return false;
});
node.setAttribute("draggable", "false");
});
2023-11-28 05:23:31 +00:00
$button.addEventListener('click', () => {
$modal.classList.remove(cls);
});
});