freeviddy.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Free the VIDEO elements: get rid of overlays, and enable the native controls.
  3. *
  4. * Useful on https://www.instagram.com/ where the stupid overlays prevent
  5. * showing the controls and triggering the context menu, so you don’t know how
  6. * long the video will take and can't play the video in full screen mode.
  7. *
  8. * @title Free Viddy
  9. */
  10. (function freeviddy() {
  11. /* Recursively execute the main logic on the document and its sub-documents. */
  12. function execute(document) {
  13. document.addEventListener('touchmove mousemove', function debouncer(event) {
  14. clearTimeout(debouncer.timeoutId);
  15. debouncer.timeoutId = setTimeout(function () {
  16. let elementsUnderPointer = document.elementsFromPoint(event.clientX, event.clientY);
  17. let overlaysToRemove = [];
  18. for (let i = 0; i < elementsUnderPointer.length; i++) {
  19. if ((elementsUnderPointer[i].tagName.toUpperCase() === 'VIDEO' ||
  20. elementsUnderPointer[i].tagName.toUpperCase() === 'IFRAME') && !elementsUnderPointer[i].xxxJanFreeViddyProcessed) {
  21. let video = elementsUnderPointer[i];
  22. video.controls = true;
  23. video.xxxJanFreeViddyProcessed = true;
  24. if (i === 0) {
  25. } else {
  26. overlaysToRemove = elementsUnderPointer.slice(0, i);
  27. }
  28. break;
  29. }
  30. }
  31. if (overlaysToRemove.length) {
  32. overlaysToRemove.forEach(element => element.remove());
  33. }
  34. }, 50);
  35. });
  36. /* Recurse for frames and iframes. */
  37. try {
  38. Array.from(
  39. document.querySelectorAll('frame, iframe, object[type^="text/html"], object[type^="application/xhtml+xml"]')
  40. ).forEach(
  41. elem => execute(elem.contentDocument)
  42. );
  43. } catch (e) {
  44. /* Catch exceptions for out-of-domain access, but do not do anything with them. */
  45. }
  46. }
  47. execute(document);
  48. })();