You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* Free the VIDEO elements: get rid of overlays, and enable the native controls.
*
* Useful on https://www.instagram.com/ where the stupid overlays prevent
* showing the controls and triggering the context menu, so you dont know how
* long the video will take and can't play the video in full screen mode.
*
* @title Free Viddy
*/
(function freeviddy() {
/* Recursively execute the main logic on the document and its sub-documents. */
function execute(document) {
document.addEventListener('touchmove mousemove', function debouncer(event) {
clearTimeout(debouncer.timeoutId);
debouncer.timeoutId = setTimeout(function () {
let elementsUnderPointer = document.elementsFromPoint(event.clientX, event.clientY);
let overlaysToRemove = [];
for (let i = 0; i < elementsUnderPointer.length; i++) {
if ((elementsUnderPointer[i].tagName.toUpperCase() === 'VIDEO' ||
elementsUnderPointer[i].tagName.toUpperCase() === 'IFRAME') && !elementsUnderPointer[i].xxxJanFreeViddyProcessed) {
let video = elementsUnderPointer[i];
video.controls = true;
video.xxxJanFreeViddyProcessed = true;
if (i === 0) {
} else {
overlaysToRemove = elementsUnderPointer.slice(0, i);
}
break;
}
}
if (overlaysToRemove.length) {
overlaysToRemove.forEach(element => element.remove());
}
}, 50);
});
/* Recurse for frames and iframes. */
try {
Array.from(
document.querySelectorAll('frame, iframe, object[type^="text/html"], object[type^="application/xhtml+xml"]')
).forEach(
elem => execute(elem.contentDocument)
);
} catch (e) {
/* Catch exceptions for out-of-domain access, but do not do anything with them. */
}
}
execute(document);
})();