Changeset View
Changeset View
Standalone View
Standalone View
extension/content-script.js
Context not available. | |||||
595 | }); | 595 | }); | ||
---|---|---|---|---|---|
596 | } | 596 | } | ||
597 | }); | 597 | }); | ||
598 | | ||||
599 | if (document.documentElement.tagName.toLowerCase() === "html") { | ||||
600 | // here we replace the document.createElement function with our own so we can detect | ||||
601 | // when an <audio> tag is created that is not added to the DOM which most pages do | ||||
602 | // while a <video> tag typically ends up being displayed to the user, audio is not. | ||||
603 | // HACK We cannot really pass variables from the page's scope to our content-script's scope | ||||
604 | // so we just blatantly insert the <audio> tag in the DOM and pick it up through our regular | ||||
605 | // mechanism. Let's see how this goes :D | ||||
606 | | ||||
607 | executeScript(`function() { | ||||
608 | var oldCreateElement = document.createElement; | ||||
609 | document.createElement = function () { | ||||
610 | var createdTag = oldCreateElement.apply(this, arguments); | ||||
611 | | ||||
612 | var tagName = arguments[0]; | ||||
613 | | ||||
614 | if (typeof tagName === "string") { | ||||
615 | if (tagName.toLowerCase() === "audio" || tagName.toLowerCase() === "video") { | ||||
616 | (document.head || document.documentElement).appendChild(createdTag); | ||||
617 | createdTag.parentNode.removeChild(createdTag); | ||||
618 | } | ||||
619 | } | ||||
620 | | ||||
621 | return createdTag; | ||||
622 | }; | ||||
623 | } | ||||
624 | `); | ||||
625 | | ||||
626 | // We also briefly add items created as new Audio() to the DOM so we can control it | ||||
627 | // similar to the document.createElement hack above | ||||
628 | executeScript(`function() { | ||||
629 | var oldAudio = window.Audio; | ||||
630 | window.Audio = function () { | ||||
631 | var createdAudio = new (Function.prototype.bind.apply(oldAudio, arguments)); | ||||
632 | | ||||
633 | (document.head || document.documentElement).appendChild(createdAudio); | ||||
634 | createdAudio.parentNode.removeChild(createdAudio); | ||||
635 | | ||||
636 | return createdAudio; | ||||
637 | }; | ||||
638 | } | ||||
639 | `); | ||||
640 | } | ||||
598 | } | 641 | } | ||
599 | 642 | | |||
600 | // This adds a shim for the Chrome media sessions API which is currently only supported on Android | 643 | // This adds a shim for the Chrome media sessions API which is currently only supported on Android | ||
Context not available. | |||||
746 | } | 789 | } | ||
747 | } | 790 | } | ||
748 | `); | 791 | `); | ||
749 | | ||||
750 | // here we replace the document.createElement function with our own so we can detect | | |||
751 | // when an <audio> tag is created that is not added to the DOM which most pages do | | |||
752 | // while a <video> tag typically ends up being displayed to the user, audio is not. | | |||
753 | // HACK We cannot really pass variables from the page's scope to our content-script's scope | | |||
754 | // so we just blatantly insert the <audio> tag in the DOM and pick it up through our regular | | |||
755 | // mechanism. Let's see how this goes :D | | |||
756 | | ||||
757 | executeScript(`function() { | | |||
758 | var oldCreateElement = document.createElement; | | |||
759 | document.createElement = function () { | | |||
760 | var createdTag = oldCreateElement.apply(this, arguments); | | |||
761 | | ||||
762 | var tagName = arguments[0]; | | |||
763 | | ||||
764 | if (typeof tagName === "string") { | | |||
765 | if (tagName.toLowerCase() === "audio" || tagName.toLowerCase() === "video") { | | |||
766 | (document.head || document.documentElement).appendChild(createdTag); | | |||
767 | createdTag.parentNode.removeChild(createdTag); | | |||
768 | } | | |||
769 | } | | |||
770 | | ||||
771 | return createdTag; | | |||
772 | }; | | |||
773 | } | | |||
774 | `); | | |||
775 | | ||||
776 | // We also briefly add items created as new Audio() to the DOM so we can control it | | |||
777 | // similar to the document.createElement hack above | | |||
778 | executeScript(`function() { | | |||
779 | var oldAudio = window.Audio; | | |||
780 | window.Audio = function () { | | |||
781 | var createdAudio = new (Function.prototype.bind.apply(oldAudio, arguments)); | | |||
782 | | ||||
783 | (document.head || document.documentElement).appendChild(createdAudio); | | |||
784 | createdAudio.parentNode.removeChild(createdAudio); | | |||
785 | | ||||
786 | return createdAudio; | | |||
787 | }; | | |||
788 | } | | |||
789 | `); | | |||
790 | | ||||
791 | } | 792 | } | ||
792 | } | 793 | } | ||
Context not available. |