50 lines
1.7 KiB
JavaScript
50 lines
1.7 KiB
JavaScript
|
|
// immersion.js
|
||
|
|
(function () {
|
||
|
|
// Preload audio
|
||
|
|
const clickIn = new Audio('clickin.wav');
|
||
|
|
const clickOut = new Audio('clickout.wav');
|
||
|
|
|
||
|
|
// Optional: make sure they can play multiple times quickly
|
||
|
|
clickIn.preload = 'auto';
|
||
|
|
clickOut.preload = 'auto';
|
||
|
|
|
||
|
|
document.addEventListener('mousedown', () => {
|
||
|
|
// Reset currentTime so rapid clicks restart the sound
|
||
|
|
clickIn.currentTime = 0;
|
||
|
|
clickIn.play().catch(err => {
|
||
|
|
// Ignore if browser blocks autoplay until user interaction
|
||
|
|
console.warn('Click-in sound not played:', err);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
document.addEventListener('mouseup', () => {
|
||
|
|
clickOut.currentTime = 0;
|
||
|
|
clickOut.play().catch(err => {
|
||
|
|
console.warn('Click-out sound not played:', err);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
windowHooks.push(function (e) {
|
||
|
|
if (e.event === "windowCreate") {
|
||
|
|
const iframe = e.window.iframe;
|
||
|
|
iframe.onload = function () {
|
||
|
|
try {
|
||
|
|
// Access the iframe's global scope
|
||
|
|
iframe.contentWindow.clickIn = clickIn;
|
||
|
|
iframe.contentWindow.clickOut = clickOut;
|
||
|
|
|
||
|
|
// Also attach event listeners inside iframe
|
||
|
|
const doc = iframe.contentDocument;
|
||
|
|
doc.addEventListener('mousedown', () => {
|
||
|
|
clickIn.currentTime = 0;
|
||
|
|
clickIn.play().catch(() => { });
|
||
|
|
});
|
||
|
|
doc.addEventListener('mouseup', () => {
|
||
|
|
clickOut.currentTime = 0;
|
||
|
|
clickOut.play().catch(() => { });
|
||
|
|
});
|
||
|
|
} catch { };
|
||
|
|
};
|
||
|
|
}
|
||
|
|
});
|
||
|
|
})();
|