mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-21 09:58:45 -04:00
add feature in popup to force search for videos, on websites that it doesn't show up on
This commit is contained in:
25
inject.js
25
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);
|
||||
});
|
||||
|
||||
|
@@ -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",
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Video Speed Controller: Popup</title>
|
||||
@@ -6,6 +6,8 @@
|
||||
<script src="popup.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<button id="refresh">Re-scan Page for Videos</button>
|
||||
<hr />
|
||||
<button id="enable" class="hide">Enable</button>
|
||||
<button id="disable">Disable</button>
|
||||
<span id="status" class="hide"></span>
|
||||
|
31
popup.js
31
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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user