diff --git a/inject.js b/inject.js
index 14563b2..65f0eb1 100644
--- a/inject.js
+++ b/inject.js
@@ -137,6 +137,31 @@ chrome.storage.sync.get(tc.settings, function (storage) {
predefined: true
});
}
+ // Add a listener for messages from the popup.
+ // We use a global flag to ensure the listener is only attached once.
+ if (!window.vscMessageListener) {
+ chrome.runtime.onMessage.addListener(
+ function (request, sender, sendResponse) {
+ // Check if the message is a request to re-scan the page.
+ if (request.action === "rescan_page") {
+ log("Re-scan command received from popup.", 4);
+
+ // Call the main initialization function. It's designed to be safe
+ // to run multiple times and will pick up any new videos.
+ initializeWhenReady(document);
+
+ // Send a response to the popup to confirm completion.
+ sendResponse({ status: "complete" });
+ }
+
+ // Required to allow for asynchronous responses.
+ return true;
+ }
+ );
+
+ // Set the flag to prevent adding the listener again.
+ window.vscMessageListener = true;
+ }
initializeWhenReady(document);
});
diff --git a/manifest.json b/manifest.json
index d4f2f70..06ff858 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"name": "Video Speed Controller",
"short_name": "videospeed",
- "version": "1.4.5",
+ "version": "1.5.1",
"manifest_version": 2,
"description": "Speed up, slow down, advance and rewind HTML5 audio/video with shortcuts",
"homepage_url": "https://github.com/SoPat712/videospeed",
diff --git a/popup.html b/popup.html
index 28354b9..41c5958 100644
--- a/popup.html
+++ b/popup.html
@@ -1,4 +1,4 @@
-
+
Video Speed Controller: Popup
@@ -6,6 +6,8 @@
+
+
diff --git a/popup.js b/popup.js
index 8e15c6b..cfe9e88 100644
--- a/popup.js
+++ b/popup.js
@@ -19,6 +19,31 @@ document.addEventListener("DOMContentLoaded", function () {
toggleEnabled(false, settingsSavedReloadMessage);
});
+ // --- REVISED: "Re-scan" button functionality ---
+ document.querySelector("#refresh").addEventListener("click", function () {
+ setStatusMessage("Re-scanning page...");
+ chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
+ if (tabs[0] && tabs[0].id) {
+ // Send a message to the content script, asking it to re-initialize.
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ { action: "rescan_page" },
+ function (response) {
+ if (chrome.runtime.lastError) {
+ // This error is expected on pages where content scripts cannot run.
+ setStatusMessage("Cannot run on this page.");
+ } else if (response && response.status === "complete") {
+ setStatusMessage("Scan complete. Closing...");
+ setTimeout(() => window.close(), 500); // Close popup on success.
+ } else {
+ setStatusMessage("Scan failed. Please reload the page.");
+ }
+ }
+ );
+ }
+ });
+ });
+
chrome.storage.sync.get({ enabled: true }, function (storage) {
toggleEnabledUI(storage.enabled);
});
@@ -42,9 +67,9 @@ document.addEventListener("DOMContentLoaded", function () {
const suffix = `${enabled ? "" : "_disabled"}.png`;
chrome.browserAction.setIcon({
path: {
- "19": "icons/icon19" + suffix,
- "38": "icons/icon38" + suffix,
- "48": "icons/icon48" + suffix
+ 19: "icons/icon19" + suffix,
+ 38: "icons/icon38" + suffix,
+ 48: "icons/icon48" + suffix
}
});
}