Changeset View
Changeset View
Standalone View
Standalone View
extension/content-script.js
Show First 20 Lines • Show All 808 Lines • ▼ Show 20 Line(s) | 805 | if (player.pausedBecauseOfDomRemoval === true) { | |||
---|---|---|---|---|---|
809 | player.play(); | 809 | player.play(); | ||
810 | } | 810 | } | ||
811 | }; | 811 | }; | ||
812 | 812 | | |||
813 | player.addEventListener("play", player.registerInDom); | 813 | player.addEventListener("play", player.registerInDom); | ||
814 | player.addEventListener("pause", player.replayAfterRemoval); | 814 | player.addEventListener("pause", player.replayAfterRemoval); | ||
815 | `; | 815 | `; | ||
816 | 816 | | |||
817 | executeScript(`function() { | 817 | const handleCreateElement = ` | ||
818 | var oldCreateElement = Document.prototype.createElement; | 818 | const tagName = arguments[0]; | ||
819 | Document.prototype.createElement = function() { | | |||
820 | var createdTag = oldCreateElement.apply(this, arguments); | | |||
821 | | ||||
822 | var tagName = arguments[0]; | | |||
823 | 819 | | |||
824 | if (typeof tagName === "string") { | 820 | if (typeof tagName === "string") { | ||
825 | if (tagName.toLowerCase() === "audio") { | 821 | if (tagName.toLowerCase() === "audio") { | ||
826 | const player = createdTag; | 822 | const player = createdTag; | ||
827 | ${addPlayerToDomEvadingAutoPlayBlocking} | 823 | ${addPlayerToDomEvadingAutoPlayBlocking} | ||
828 | } else if (tagName.toLowerCase() === "video") { | 824 | } else if (tagName.toLowerCase() === "video") { | ||
829 | (document.head || document.documentElement).appendChild(createdTag); | 825 | (document.head || document.documentElement).appendChild(createdTag); | ||
830 | createdTag.parentNode.removeChild(createdTag); | 826 | createdTag.parentNode.removeChild(createdTag); | ||
831 | } | 827 | } | ||
832 | } | 828 | } | ||
829 | `; | ||||
833 | 830 | | |||
831 | if (IS_FIREFOX) { | ||||
832 | const oldCreateElement = Document.prototype.createElement; | ||||
833 | exportFunction(function() { | ||||
834 | const createdTag = oldCreateElement.apply(this, arguments); | ||||
835 | eval(handleCreateElement); | ||||
836 | return createdTag; | ||||
837 | }, Document.prototype, {defineAs: "createElement"}); | ||||
838 | } else { | ||||
839 | executeScript(` | ||||
840 | function() { | ||||
841 | const oldCreateElement = Document.prototype.createElement; | ||||
842 | Document.prototype.createElement = function() { | ||||
843 | const createdTag = oldCreateElement.apply(this, arguments); | ||||
844 | ${handleCreateElement} | ||||
834 | return createdTag; | 845 | return createdTag; | ||
835 | }; | 846 | }; | ||
836 | } | 847 | } | ||
837 | `); | 848 | `); | ||
849 | } | ||||
838 | 850 | | |||
839 | // We also briefly add items created as new Audio() to the DOM so we can control it | 851 | // We also briefly add items created as new Audio() to the DOM so we can control it | ||
840 | // similar to the document.createElement hack above since we cannot share variables | 852 | // similar to the document.createElement hack above since we cannot share variables | ||
841 | // between the actual website and the background script despite them sharing the same DOM | 853 | // between the actual website and the background script despite them sharing the same DOM | ||
842 | 854 | | |||
843 | if (IS_FIREFOX) { | 855 | if (IS_FIREFOX) { | ||
844 | // Firefox enforces Content-Security-Policy also for scripts injected by the content-script | 856 | // Firefox enforces Content-Security-Policy also for scripts injected by the content-script | ||
845 | // This causes our executeScript calls to fail for pages like Nextcloud | 857 | // This causes our executeScript calls to fail for pages like Nextcloud | ||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |