mirror of
https://wiilab.wiimart.org/wiimart/wiimart-extension
synced 2025-09-02 19:41:00 +02:00
music works across????
This commit is contained in:
parent
3801d12e24
commit
d33ae05a22
@ -1,4 +1,7 @@
|
|||||||
const _injectedWiiShopSoundUrls = window._wiiShopSoundUrls_ || [];
|
const _injectedWiiShopSoundUrls = window._wiiShopSoundUrls_ || [];
|
||||||
|
const _injectedWiiShopBgmUrl = window._wiiShopBgmUrl_ || '';
|
||||||
|
const _bgmInitiallyEnabled = window._wiiShopBgmInitiallyEnabled_ === true;
|
||||||
|
const _bgmAlreadyPlaying = window._bgmAlreadyPlaying || false;
|
||||||
|
|
||||||
var ecsUrl = "";
|
var ecsUrl = "";
|
||||||
var iasUrl = "";
|
var iasUrl = "";
|
||||||
@ -322,22 +325,20 @@ class wiiShop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class wiiSound {
|
class wiiSound {
|
||||||
// === THIS IS THE CRUCIAL CHANGE ===
|
|
||||||
// Use a static property to store the sound URLs, accessible by all instances
|
|
||||||
static audioUrls = _injectedWiiShopSoundUrls;
|
static audioUrls = _injectedWiiShopSoundUrls;
|
||||||
|
static currentBgmAudio = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
trace("wiiSound initialized"); // Use the trace function
|
trace("wiiSound initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
playSE(snd) {
|
playSE(snd) {
|
||||||
const soundIndex = parseInt(snd, 10);
|
const soundIndex = parseInt(snd, 10);
|
||||||
// Access the URLs via the static property
|
|
||||||
if (isNaN(soundIndex) || soundIndex < 1 || soundIndex >= wiiSound.audioUrls.length) {
|
if (isNaN(soundIndex) || soundIndex < 1 || soundIndex >= wiiSound.audioUrls.length) {
|
||||||
console.warn("Invalid sound index for wiiSound.playSE:", snd);
|
console.warn("Invalid sound index for wiiSound.playSE:", snd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access the URLs via the static property
|
|
||||||
const audioUrl = wiiSound.audioUrls[soundIndex];
|
const audioUrl = wiiSound.audioUrls[soundIndex];
|
||||||
if (!audioUrl) {
|
if (!audioUrl) {
|
||||||
console.warn("No audio URL found for sound index:", soundIndex);
|
console.warn("No audio URL found for sound index:", soundIndex);
|
||||||
@ -345,17 +346,60 @@ class wiiSound {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const audio = new Audio(audioUrl);
|
const audio = new Audio(audioUrl);
|
||||||
audio.style.display = 'none'; // Keep it hidden
|
audio.style.display = 'none';
|
||||||
audio.play()
|
audio.play()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Wii Shop Sound played:', soundIndex, audioUrl);
|
console.log('Wii Shop Sound played:', soundIndex, audioUrl);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error playing Wii Shop Sound:', soundIndex, audioUrl, error);
|
console.error('Error playing Wii Shop Sound:', soundIndex, audioUrl, error);
|
||||||
// Common error: Autoplay policy blocked.
|
|
||||||
// Consider a fallback, like playing on user interaction.
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playBGM() {
|
||||||
|
if (window._bgmAlreadyPlaying === true) {
|
||||||
|
return "nah mate, i aint playin for ya, im already playin";
|
||||||
|
} else {
|
||||||
|
window._bgmAlreadyPlaying = true;
|
||||||
|
if (wiiSound.currentBgmAudio && !wiiSound.currentBgmAudio.paused) {
|
||||||
|
wiiSound.currentBgmAudio.pause();
|
||||||
|
wiiSound.currentBgmAudio.currentTime = 0;
|
||||||
|
console.log('Stopped previous BGM.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_injectedWiiShopBgmUrl) {
|
||||||
|
console.warn("No BGM URL available.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const audio = new Audio(_injectedWiiShopBgmUrl);
|
||||||
|
audio.loop = true;
|
||||||
|
audio.style.display = 'none';
|
||||||
|
|
||||||
|
audio.play()
|
||||||
|
.then(() => {
|
||||||
|
wiiSound.currentBgmAudio = audio;
|
||||||
|
console.log('Wii Shop BGM started and looping:', _injectedWiiShopBgmUrl);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error playing Wii Shop BGM:', _injectedWiiShopBgmUrl, error);
|
||||||
|
// Autoplay policy issues are common here.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stopBGM() {
|
||||||
|
if (window._bgmAlreadyPlaying === true){
|
||||||
|
if (wiiSound.currentBgmAudio) {
|
||||||
|
wiiSound.currentBgmAudio.pause();
|
||||||
|
wiiSound.currentBgmAudio.currentTime = 0;
|
||||||
|
wiiSound.currentBgmAudio = null;
|
||||||
|
console.log('Wii Shop BGM stopped.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "wtf do you want me to stop eh?";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class wiiKeyboard {
|
class wiiKeyboard {
|
||||||
@ -458,3 +502,14 @@ window.wiiKeyboard = wiiKeyboard;
|
|||||||
window.wiiShop = wiiShop;
|
window.wiiShop = wiiShop;
|
||||||
window.wiiSound = wiiSound;
|
window.wiiSound = wiiSound;
|
||||||
window.wiiMii = wiiMii;
|
window.wiiMii = wiiMii;
|
||||||
|
|
||||||
|
if (_bgmInitiallyEnabled) {
|
||||||
|
// Use a short delay or an event listener to ensure all page elements are ready
|
||||||
|
// and to potentially work around immediate autoplay blocks (though not guaranteed).
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
if (window.wiiSound) {
|
||||||
|
const soundInstance = new window.wiiSound();
|
||||||
|
soundInstance.playBGM();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
64
content.js
64
content.js
@ -109,6 +109,7 @@ function checkFontState() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Define the relative paths to your sound files within the extension
|
||||||
const soundFilePaths = [
|
const soundFilePaths = [
|
||||||
'', // Index 0 (unused)
|
'', // Index 0 (unused)
|
||||||
'audio/1.wav',
|
'audio/1.wav',
|
||||||
@ -120,16 +121,11 @@ const soundFilePaths = [
|
|||||||
'audio/7.wav'
|
'audio/7.wav'
|
||||||
];
|
];
|
||||||
|
|
||||||
// Generate the full, web-accessible URLs
|
// Define the path for the BGM file
|
||||||
const generatedSoundUrls = [];
|
const bgmFilePath = 'audio/bgm.wav'; // <--- NEW BGM PATH
|
||||||
for (let i = 0; i < soundFilePaths.length; i++) {
|
|
||||||
if (soundFilePaths[i]) {
|
const generatedSoundUrls = soundFilePaths.map(path => path ? browser.runtime.getURL(path) : '');
|
||||||
// Use browser.runtime.getURL for Firefox
|
const generatedBgmUrl = browser.runtime.getURL(bgmFilePath);
|
||||||
generatedSoundUrls[i] = browser.runtime.getURL(soundFilePaths[i]);
|
|
||||||
} else {
|
|
||||||
generatedSoundUrls[i] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to load class definitions based on the browser
|
// Function to load class definitions based on the browser
|
||||||
const loadClassDefinitions = async () => {
|
const loadClassDefinitions = async () => {
|
||||||
@ -152,23 +148,31 @@ const loadClassDefinitions = async () => {
|
|||||||
}
|
}
|
||||||
const classDefinitionsText = await response.text();
|
const classDefinitionsText = await response.text();
|
||||||
|
|
||||||
|
// Get the current BGM enabled state from storage
|
||||||
|
// Use browser.storage.local for Firefox compatibility
|
||||||
|
const storageResult = await browser.storage.local.get(['bgmEnabled']);
|
||||||
|
const bgmInitiallyEnabled = storageResult.bgmEnabled === true; // Default to false if not set
|
||||||
|
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.setAttribute('type', 'text/javascript');
|
script.setAttribute('type', 'text/javascript');
|
||||||
|
|
||||||
// PREPEND the sound URLs as a global variable *before* the classDefinitions.js content
|
// PREPEND the sound URLs, BGM URL, and BGM enabled state as global variables
|
||||||
script.textContent = `
|
script.textContent = `
|
||||||
(function() {
|
(function() {
|
||||||
// Define a global variable that classDefinitions.js can access
|
|
||||||
window._wiiShopSoundUrls_ = ${JSON.stringify(generatedSoundUrls)};
|
window._wiiShopSoundUrls_ = ${JSON.stringify(generatedSoundUrls)};
|
||||||
|
window._wiiShopBgmUrl_ = ${JSON.stringify(generatedBgmUrl)};
|
||||||
|
window._wiiShopBgmInitiallyEnabled_ = ${JSON.stringify(bgmInitiallyEnabled)}; // <--- PASS BGM STATE
|
||||||
})();
|
})();
|
||||||
` + classDefinitionsText; // Append the actual classDefinitions.js content
|
` + classDefinitionsText;
|
||||||
|
|
||||||
document.documentElement.insertBefore(script, document.documentElement.firstChild);
|
document.documentElement.insertBefore(script, document.documentElement.firstChild);
|
||||||
|
|
||||||
script.onload = function() {
|
script.onload = function() {
|
||||||
this.remove();
|
this.remove();
|
||||||
// Clean up the global variable after classDefinitions.js has likely used it
|
// Clean up the global variables after classDefinitions.js has used them
|
||||||
delete window._wiiShopSoundUrls_;
|
delete window._wiiShopSoundUrls_;
|
||||||
|
delete window._wiiShopBgmUrl_;
|
||||||
|
delete window._wiiShopBgmInitiallyEnabled_; // <--- CLEAN UP BGM STATE
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -180,4 +184,34 @@ const loadClassDefinitions = async () => {
|
|||||||
loadClassDefinitions();
|
loadClassDefinitions();
|
||||||
// Load the existing trace and points from localStorage
|
// Load the existing trace and points from localStorage
|
||||||
const result = checkFontState();
|
const result = checkFontState();
|
||||||
console.log(result);
|
console.log(result);
|
||||||
|
|
||||||
|
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
|
if (request.action === "toggleBGM") {
|
||||||
|
// Here, you'd typically want to call a function on the page
|
||||||
|
// to control the BGM. Since wiiSound is defined in classDefinitions.js,
|
||||||
|
// which runs in the page's context, you need to use a custom event
|
||||||
|
// or directly call window.wiiSound if it's already available.
|
||||||
|
// For simplicity, let's assume classDefinitions.js has exposed a way to call it.
|
||||||
|
// Or, we could just re-inject a small script to call it.
|
||||||
|
|
||||||
|
const controlScript = document.createElement('script');
|
||||||
|
controlScript.textContent = `
|
||||||
|
(function() {
|
||||||
|
if (window.wiiSound && typeof window.wiiSound.currentBgmAudio !== 'undefined') {
|
||||||
|
if (window.wiiSound.currentBgmAudio) {
|
||||||
|
window.wiiSound.currentBgmAudio.pause();
|
||||||
|
window.wiiSound.currentBgmAudio.currentTime = 0;
|
||||||
|
}
|
||||||
|
if (${request.enabled}) {
|
||||||
|
// Re-instantiate wiiSound to get the latest instance,
|
||||||
|
// then call playBGM(). This ensures the method exists.
|
||||||
|
new window.wiiSound().playBGM();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
`;
|
||||||
|
document.documentElement.appendChild(controlScript);
|
||||||
|
controlScript.onload = function() { this.remove(); };
|
||||||
|
}
|
||||||
|
});
|
@ -34,6 +34,7 @@
|
|||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
{
|
{
|
||||||
"resources": [
|
"resources": [
|
||||||
|
"fonts/*",
|
||||||
"images/*",
|
"images/*",
|
||||||
"audio/*",
|
"audio/*",
|
||||||
"classDefinitions.js"
|
"classDefinitions.js"
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
"activeTab",
|
"activeTab",
|
||||||
"storage",
|
"storage",
|
||||||
"webRequest",
|
"webRequest",
|
||||||
"tabs"
|
"tabs",
|
||||||
|
"webRequestBlocking"
|
||||||
],
|
],
|
||||||
"host_permissions": [
|
"host_permissions": [
|
||||||
"<all_urls>"
|
"<all_urls>"
|
||||||
@ -34,6 +35,7 @@
|
|||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
{
|
{
|
||||||
"resources": [
|
"resources": [
|
||||||
|
"fonts/*",
|
||||||
"images/*",
|
"images/*",
|
||||||
"audio/*",
|
"audio/*",
|
||||||
"classDefinitions.js"
|
"classDefinitions.js"
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
<!-- popup.html -->
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -28,6 +27,8 @@
|
|||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="toggleFont"> Enable Custom Font
|
<input type="checkbox" id="toggleFont"> Enable Custom Font
|
||||||
</label>
|
</label>
|
||||||
|
<br> <label>
|
||||||
|
<input type="checkbox" id="toggleBGM"> Enable Persistent BGM </label>
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
32
popup.js
32
popup.js
@ -1,5 +1,6 @@
|
|||||||
// popup.js
|
// popup.js
|
||||||
const STORAGE_ENDPOINT = '/_extension_storage';
|
const STORAGE_ENDPOINT = '/_extension_storage'; // Your existing storage endpoint
|
||||||
|
|
||||||
document.getElementById('clearTrace').addEventListener('click', function() {
|
document.getElementById('clearTrace').addEventListener('click', function() {
|
||||||
fetch(`${STORAGE_ENDPOINT}?clogs=true`)
|
fetch(`${STORAGE_ENDPOINT}?clogs=true`)
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
@ -16,10 +17,33 @@ document.getElementById('clearPoints').addEventListener('click', function() {
|
|||||||
document.getElementById('toggleFont').addEventListener('change', function() {
|
document.getElementById('toggleFont').addEventListener('change', function() {
|
||||||
const isChecked = this.checked;
|
const isChecked = this.checked;
|
||||||
// Set the font state in the extension's storage
|
// Set the font state in the extension's storage
|
||||||
chrome.storage.local.set({ fontDisabled: !isChecked });
|
// Using chrome.storage.local for consistency with browser extension APIs
|
||||||
|
chrome.storage.local.set({ fontEnabled: isChecked }); // Renamed key to 'fontEnabled' for clarity
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check the current font state when the popup is opened
|
// Check the current font state when the popup is opened
|
||||||
chrome.storage.local.get(['fontDisabled'], function(result) {
|
chrome.storage.local.get(['fontEnabled'], function(result) {
|
||||||
document.getElementById('toggleFont').checked = !result.fontDisabled; // Set checkbox based on stored value
|
// Default to true if not set (font enabled by default)
|
||||||
|
document.getElementById('toggleFont').checked = (result.fontEnabled !== false);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// --- NEW BGM TOGGLE LOGIC ---
|
||||||
|
document.getElementById('toggleBGM').addEventListener('change', function() {
|
||||||
|
const isChecked = this.checked;
|
||||||
|
chrome.storage.local.set({ bgmEnabled: isChecked }, function() {
|
||||||
|
// Optionally, send a message to content scripts to update immediately
|
||||||
|
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
action: "toggleBGM",
|
||||||
|
enabled: isChecked
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check the current BGM state when the popup is opened
|
||||||
|
chrome.storage.local.get(['bgmEnabled'], function(result) {
|
||||||
|
// Default to false if not set (BGM disabled by default on startup)
|
||||||
|
document.getElementById('toggleBGM').checked = (result.bgmEnabled === true);
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user