From b5482b652787a7a39e72f4c7c499e33a9b3eabce Mon Sep 17 00:00:00 2001
From: NDevTK <31563761+NDevTK@users.noreply.github.com>
Date: Thu, 19 May 2022 13:33:33 +0100
Subject: [PATCH 1/9] Move popup to iframe
---
src/content.ts | 101 +++++++++++++++++++------------------------------
src/popup.ts | 9 +++++
2 files changed, 47 insertions(+), 63 deletions(-)
diff --git a/src/content.ts b/src/content.ts
index e89bbb2a..32be9609 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -1686,73 +1686,48 @@ function openInfoMenu() {
//hide info button
if (playerButtons.info) playerButtons.info.button.style.display = "none";
- sendRequestToCustomServer('GET', chrome.extension.getURL("popup.html"), function(xmlhttp) {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- const popup = document.createElement("div");
- popup.id = "sponsorBlockPopupContainer";
+
+ const popup = document.createElement("div");
+ popup.id = "sponsorBlockPopupContainer";
+
+ const frame = document.createElement("iframe");
+ frame.width = "410";
+ frame.height = "400";
+ frame.onload = () => frame.contentWindow.postMessage("", "*");
+ frame.src = chrome.extension.getURL("popup.html");
+ popup.appendChild(frame);
+
- let htmlData = xmlhttp.responseText;
- // Hack to replace head data (title, favicon)
- htmlData = htmlData.replace(/
[\S\s]*<\/head>/gi, "");
- // Hack to replace body and html tag with div
- htmlData = htmlData.replace(/ popup.querySelector("#sponsorBlockPopupLogo");
- const settings = popup.querySelector("#sbPopupIconSettings");
- const edit = popup.querySelector("#sbPopupIconEdit");
- const copy = popup.querySelector("#sbPopupIconCopyUserID");
- const check = popup.querySelector("#sbPopupIconCheck");
- const refreshSegments = popup.querySelector("#refreshSegments");
- const heart = popup.querySelector(".sbHeart");
- const close = popup.querySelector("#sbCloseDonate");
- logo.src = chrome.extension.getURL("icons/IconSponsorBlocker256px.png");
- settings.src = chrome.extension.getURL("icons/settings.svg");
- edit.src = chrome.extension.getURL("icons/pencil.svg");
- copy.src = chrome.extension.getURL("icons/clipboard.svg");
- check.src = chrome.extension.getURL("icons/check.svg");
- heart.src = chrome.extension.getURL("icons/heart.svg");
- close.src = chrome.extension.getURL("icons/close.png");
- refreshSegments.src = chrome.extension.getURL("icons/refresh.svg");
-
- parentNode.insertBefore(popup, parentNode.firstChild);
-
- //run the popup init script
- runThePopup(messageListener);
+ const parentNodes = document.querySelectorAll("#secondary");
+ let parentNode = null;
+ for (let i = 0; i < parentNodes.length; i++) {
+ if (parentNodes[i].firstElementChild !== null) {
+ parentNode = parentNodes[i];
}
- });
+ }
+ if (parentNode == null) {
+ //old youtube theme
+ parentNode = document.getElementById("watch7-sidebar-contents");
+ }
+
+ parentNode.insertBefore(popup, parentNode.firstChild);
+
+ //run the popup init script
+ runThePopup(messageListener);
}
function closeInfoMenu() {
diff --git a/src/popup.ts b/src/popup.ts
index 504229fc..ae4a40c8 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -41,10 +41,19 @@ class MessageHandler {
}
}
+let allowPopup = (window === window.top);
+window.onmessage = async e => {
+ if (e.source !== window.parent) return
+ if (e.origin.endsWith('.youtube.com')) return allowPopup = true;
+ await utils.wait(() => Config.config !== null);
+ if (Config.config.supportInvidious && e.origin.includes(Config.config.invidiousInstances)) return allowPopup = true;
+}
//make this a function to allow this to run on the content page
async function runThePopup(messageListener?: MessageListener): Promise {
+ if (window !== window.top) await utils.wait(() => allowPopup === true);
+
const messageHandler = new MessageHandler(messageListener);
utils.localizeHtmlPage();
From afee6815751f0cd2e4c9a554daced584eca2f116 Mon Sep 17 00:00:00 2001
From: NDevTK <31563761+NDevTK@users.noreply.github.com>
Date: Thu, 19 May 2022 18:49:45 +0100
Subject: [PATCH 2/9] Removed runThePopup
---
src/content.ts | 5 -----
src/popup.ts | 7 +------
2 files changed, 1 insertion(+), 11 deletions(-)
diff --git a/src/content.ts b/src/content.ts
index 32be9609..d7caa944 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -5,8 +5,6 @@ import { ContentContainer, Keybind } from "./types";
import Utils from "./utils";
const utils = new Utils();
-import runThePopup from "./popup";
-
import PreviewBar, {PreviewBarSegment} from "./js-components/previewBar";
import SkipNotice from "./render/SkipNotice";
import SkipNoticeComponent from "./components/SkipNoticeComponent";
@@ -1725,9 +1723,6 @@ function openInfoMenu() {
}
parentNode.insertBefore(popup, parentNode.firstChild);
-
- //run the popup init script
- runThePopup(messageListener);
}
function closeInfoMenu() {
diff --git a/src/popup.ts b/src/popup.ts
index ae4a40c8..e97559cc 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -831,9 +831,4 @@ async function runThePopup(messageListener?: MessageListener): Promise {
//end of function
}
-if (chrome.tabs != undefined) {
- //this means it is actually opened in the popup
- runThePopup();
-}
-
-export default runThePopup;
+runThePopup();
From a7956aacf92dadbebb92eb68fbd7ce4603934044 Mon Sep 17 00:00:00 2001
From: NDevTK <31563761+NDevTK@users.noreply.github.com>
Date: Thu, 19 May 2022 22:54:08 +0100
Subject: [PATCH 3/9] Remove unused sendRequestToCustomServer
---
src/content.ts | 19 -------------------
1 file changed, 19 deletions(-)
diff --git a/src/content.ts b/src/content.ts
index d7caa944..e16f71be 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -2083,25 +2083,6 @@ function addCSS() {
}
}
-function sendRequestToCustomServer(type, fullAddress, callback) {
- const xmlhttp = new XMLHttpRequest();
-
- xmlhttp.open(type, fullAddress, true);
-
- if (callback != undefined) {
- xmlhttp.onreadystatechange = function () {
- callback(xmlhttp, false);
- };
-
- xmlhttp.onerror = function() {
- callback(xmlhttp, true);
- };
- }
-
- //submit this request
- xmlhttp.send();
-}
-
/**
* Update the isAdPlaying flag and hide preview bar/controls if ad is playing
*/
From bfadb1373a55125fc8d7876e7f1cae12fdd8604a Mon Sep 17 00:00:00 2001
From: NDevTK <31563761+NDevTK@users.noreply.github.com>
Date: Thu, 19 May 2022 23:17:18 +0100
Subject: [PATCH 4/9] Add comment
---
src/popup.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/popup.ts b/src/popup.ts
index e97559cc..32c4424a 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -43,6 +43,7 @@ class MessageHandler {
let allowPopup = (window === window.top);
+// To prevent clickjacking
window.onmessage = async e => {
if (e.source !== window.parent) return
if (e.origin.endsWith('.youtube.com')) return allowPopup = true;
From 58207585631a32e067741b7ec64fc40f38525e8b Mon Sep 17 00:00:00 2001
From: Ajay
Date: Thu, 2 Jun 2022 16:56:19 -0400
Subject: [PATCH 5/9] Fix close button layout issues
---
public/popup.html | 4 ++++
src/content.ts | 22 +++++-----------------
src/messageTypes.ts | 3 ++-
src/popup.ts | 25 ++++++++++++++++++++++++-
4 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/public/popup.html b/public/popup.html
index b1a241c4..fae41356 100644
--- a/public/popup.html
+++ b/public/popup.html
@@ -11,6 +11,10 @@