diff --git a/background.js b/background.js index 93473d422..90ca2f678 100644 --- a/background.js +++ b/background.js @@ -322,5 +322,45 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { break } }); -/*-----# UNINSTALL URL-----------------------------------*/ +/*-------------------------------------------------------------- +# UNINSTALL URL +--------------------------------------------------------------*/ chrome.runtime.setUninstallURL('https://improvedtube.com/uninstalled'); +/*-------------------------------------------------------------- +# WINDOWED MODE +--------------------------------------------------------------*/ +chrome.commands.onCommand.addListener(async (command) => { + if (command === "toggle_windowed_mode") { + const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); + + if (!tab || !tab.url.includes("youtube.com/watch")) return; + + const videoId = new URL(tab.url).searchParams.get("v"); + + chrome.scripting.executeScript({ + target: { tabId: tab.id }, + func: (videoId) => { + const existing = document.getElementById("yt-windowed-mode"); + if (existing) { + // Already in windowed mode, so go back to normal + location.href = `https://www.youtube.com/watch?v=${videoId}`; + return; + } + + // Clear and show embedded player + document.body.innerHTML = ` +
+ +
+ `; + document.title = "Windowed Mode"; + }, + args: [videoId], + }); + } + }); \ No newline at end of file diff --git a/manifest.json b/manifest.json index 7080c728c..c912890ab 100644 --- a/manifest.json +++ b/manifest.json @@ -66,8 +66,19 @@ ], "permissions": [ "contextMenus", - "storage" + "storage", + "tabs", + "scripting" ], + "commands": { + "toggle_windowed_mode": { + "suggested_key": { + "default": "Ctrl+Shift+E", + "mac": "Command+Shift+E" + }, + "description": "Toggle windowed mode" + } + }, "web_accessible_resources": [ { "resources": [