mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 22:17:21 +03:00
Move popup to iframe
This commit is contained in:
101
src/content.ts
101
src/content.ts
@@ -1686,73 +1686,48 @@ function openInfoMenu() {
|
|||||||
//hide info button
|
//hide info button
|
||||||
if (playerButtons.info) playerButtons.info.button.style.display = "none";
|
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");
|
||||||
const popup = document.createElement("div");
|
popup.id = "sponsorBlockPopupContainer";
|
||||||
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;
|
//close button
|
||||||
// Hack to replace head data (title, favicon)
|
const closeButton = document.createElement("button");
|
||||||
htmlData = htmlData.replace(/<head>[\S\s]*<\/head>/gi, "");
|
const closeButtonIcon = document.createElement("img");
|
||||||
// Hack to replace body and html tag with div
|
closeButtonIcon.src = chrome.extension.getURL("icons/close.png");
|
||||||
htmlData = htmlData.replace(/<body/gi, "<div");
|
closeButtonIcon.width = 15;
|
||||||
htmlData = htmlData.replace(/<\/body/gi, "</div");
|
closeButtonIcon.height = 15;
|
||||||
htmlData = htmlData.replace(/<html/gi, "<div");
|
closeButton.appendChild(closeButtonIcon);
|
||||||
htmlData = htmlData.replace(/<\/html/gi, "</div");
|
closeButton.setAttribute("title", chrome.i18n.getMessage("closePopup"));
|
||||||
|
closeButton.classList.add("sbCloseButton");
|
||||||
|
closeButton.addEventListener("click", closeInfoMenu);
|
||||||
|
|
||||||
popup.innerHTML = htmlData;
|
//add the close button
|
||||||
|
popup.prepend(closeButton);
|
||||||
|
|
||||||
//close button
|
const parentNodes = document.querySelectorAll("#secondary");
|
||||||
const closeButton = document.createElement("button");
|
let parentNode = null;
|
||||||
const closeButtonIcon = document.createElement("img");
|
for (let i = 0; i < parentNodes.length; i++) {
|
||||||
closeButtonIcon.src = chrome.extension.getURL("icons/close.png");
|
if (parentNodes[i].firstElementChild !== null) {
|
||||||
closeButtonIcon.width = 15;
|
parentNode = parentNodes[i];
|
||||||
closeButtonIcon.height = 15;
|
|
||||||
closeButton.appendChild(closeButtonIcon);
|
|
||||||
closeButton.setAttribute("title", chrome.i18n.getMessage("closePopup"));
|
|
||||||
closeButton.classList.add("sbCloseButton");
|
|
||||||
closeButton.addEventListener("click", closeInfoMenu);
|
|
||||||
|
|
||||||
//add the close button
|
|
||||||
popup.prepend(closeButton);
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
//make the logo source not 404
|
|
||||||
//query selector must be used since getElementByID doesn't work on a node and this isn't added to the document yet
|
|
||||||
const logo = <HTMLImageElement> popup.querySelector("#sponsorBlockPopupLogo");
|
|
||||||
const settings = <HTMLImageElement> popup.querySelector("#sbPopupIconSettings");
|
|
||||||
const edit = <HTMLImageElement> popup.querySelector("#sbPopupIconEdit");
|
|
||||||
const copy = <HTMLImageElement> popup.querySelector("#sbPopupIconCopyUserID");
|
|
||||||
const check = <HTMLImageElement> popup.querySelector("#sbPopupIconCheck");
|
|
||||||
const refreshSegments = <HTMLImageElement> popup.querySelector("#refreshSegments");
|
|
||||||
const heart = <HTMLImageElement> popup.querySelector(".sbHeart");
|
|
||||||
const close = <HTMLImageElement> 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);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
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() {
|
function closeInfoMenu() {
|
||||||
|
|||||||
@@ -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
|
//make this a function to allow this to run on the content page
|
||||||
async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||||
|
if (window !== window.top) await utils.wait(() => allowPopup === true);
|
||||||
|
|
||||||
const messageHandler = new MessageHandler(messageListener);
|
const messageHandler = new MessageHandler(messageListener);
|
||||||
|
|
||||||
utils.localizeHtmlPage();
|
utils.localizeHtmlPage();
|
||||||
|
|||||||
Reference in New Issue
Block a user