mirror of
https://wiilab.wiimart.org/wiimart/wiimart-extension
synced 2025-09-02 19:41:00 +02:00
audio fuckin works
This commit is contained in:
parent
ff645bd4a6
commit
db7d7137d0
BIN
audio/1.wav
Normal file
BIN
audio/1.wav
Normal file
Binary file not shown.
BIN
audio/2.wav
Normal file
BIN
audio/2.wav
Normal file
Binary file not shown.
BIN
audio/3.wav
Normal file
BIN
audio/3.wav
Normal file
Binary file not shown.
BIN
audio/4.wav
Normal file
BIN
audio/4.wav
Normal file
Binary file not shown.
BIN
audio/5.wav
Normal file
BIN
audio/5.wav
Normal file
Binary file not shown.
BIN
audio/6.wav
Normal file
BIN
audio/6.wav
Normal file
Binary file not shown.
BIN
audio/7.wav
Normal file
BIN
audio/7.wav
Normal file
Binary file not shown.
@ -1,3 +1,5 @@
|
||||
const _injectedWiiShopSoundUrls = window._wiiShopSoundUrls_ || [];
|
||||
|
||||
var ecsUrl = "";
|
||||
var iasUrl = "";
|
||||
var ccsUrl = "";
|
||||
@ -320,11 +322,39 @@ class wiiShop {
|
||||
}
|
||||
|
||||
class wiiSound {
|
||||
// === THIS IS THE CRUCIAL CHANGE ===
|
||||
// Use a static property to store the sound URLs, accessible by all instances
|
||||
static audioUrls = _injectedWiiShopSoundUrls;
|
||||
|
||||
constructor() {
|
||||
trace("wiiSound initialized"); // Use the trace function
|
||||
}
|
||||
playSE(snd) {
|
||||
console.log("i play this sound hehehehe (it dont exist lol): " + snd);
|
||||
const soundIndex = parseInt(snd, 10);
|
||||
// Access the URLs via the static property
|
||||
if (isNaN(soundIndex) || soundIndex < 1 || soundIndex >= wiiSound.audioUrls.length) {
|
||||
console.warn("Invalid sound index for wiiSound.playSE:", snd);
|
||||
return;
|
||||
}
|
||||
|
||||
// Access the URLs via the static property
|
||||
const audioUrl = wiiSound.audioUrls[soundIndex];
|
||||
if (!audioUrl) {
|
||||
console.warn("No audio URL found for sound index:", soundIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
const audio = new Audio(audioUrl);
|
||||
audio.style.display = 'none'; // Keep it hidden
|
||||
audio.play()
|
||||
.then(() => {
|
||||
console.log('Wii Shop Sound played:', soundIndex, audioUrl);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error playing Wii Shop Sound:', soundIndex, audioUrl, error);
|
||||
// Common error: Autoplay policy blocked.
|
||||
// Consider a fallback, like playing on user interaction.
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
57
content.js
57
content.js
@ -109,33 +109,68 @@ function checkFontState() {
|
||||
});
|
||||
}
|
||||
|
||||
const soundFilePaths = [
|
||||
'', // Index 0 (unused)
|
||||
'audio/1.wav',
|
||||
'audio/2.wav',
|
||||
'audio/3.wav',
|
||||
'audio/4.wav',
|
||||
'audio/5.wav',
|
||||
'audio/6.wav',
|
||||
'audio/7.wav'
|
||||
];
|
||||
|
||||
// Generate the full, web-accessible URLs
|
||||
const generatedSoundUrls = [];
|
||||
for (let i = 0; i < soundFilePaths.length; i++) {
|
||||
if (soundFilePaths[i]) {
|
||||
// Use browser.runtime.getURL for Firefox
|
||||
generatedSoundUrls[i] = browser.runtime.getURL(soundFilePaths[i]);
|
||||
} else {
|
||||
generatedSoundUrls[i] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Function to load class definitions based on the browser
|
||||
const loadClassDefinitions = async () => {
|
||||
let classDefinitionsUrl;
|
||||
// Check the user agent to determine the browser
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
|
||||
if (userAgent.includes("chrome")) {
|
||||
// Load the class definitions for Chrome
|
||||
classDefinitionsUrl = chrome.runtime.getURL('classDefinitions.js'); // Adjust the path as necessary
|
||||
classDefinitionsUrl = chrome.runtime.getURL('classDefinitions.js');
|
||||
} else if (userAgent.includes("firefox")) {
|
||||
// Load the class definitions for Firefox
|
||||
classDefinitionsUrl = browser.runtime.getURL('classDefinitions.js'); // Adjust the path as necessary
|
||||
classDefinitionsUrl = browser.runtime.getURL('classDefinitions.js');
|
||||
} else {
|
||||
console.warn("Unsupported browser. Class definitions will not be loaded.");
|
||||
return; // Exit if the browser is not supported
|
||||
return;
|
||||
}
|
||||
// Fetch the class definitions file
|
||||
|
||||
try {
|
||||
const response = await fetch(classDefinitionsUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const classDefinitions = await response.text();
|
||||
// Create a script element and set its content
|
||||
const classDefinitionsText = await response.text();
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.textContent = classDefinitions;
|
||||
// Insert the script at the start of the <html> element
|
||||
script.setAttribute('type', 'text/javascript');
|
||||
|
||||
// PREPEND the sound URLs as a global variable *before* the classDefinitions.js content
|
||||
script.textContent = `
|
||||
(function() {
|
||||
// Define a global variable that classDefinitions.js can access
|
||||
window._wiiShopSoundUrls_ = ${JSON.stringify(generatedSoundUrls)};
|
||||
})();
|
||||
` + classDefinitionsText; // Append the actual classDefinitions.js content
|
||||
|
||||
document.documentElement.insertBefore(script, document.documentElement.firstChild);
|
||||
|
||||
script.onload = function() {
|
||||
this.remove();
|
||||
// Clean up the global variable after classDefinitions.js has likely used it
|
||||
delete window._wiiShopSoundUrls_;
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error("Failed to load class definitions:", error);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@
|
||||
"resources": [
|
||||
"fonts/*",
|
||||
"images/*",
|
||||
"audio/*",
|
||||
"classDefinitions.js"
|
||||
],
|
||||
"matches": [
|
||||
|
Loading…
x
Reference in New Issue
Block a user