diff --git a/audio/1.wav b/audio/1.wav new file mode 100644 index 0000000..6a6edee Binary files /dev/null and b/audio/1.wav differ diff --git a/audio/2.wav b/audio/2.wav new file mode 100644 index 0000000..5beec5c Binary files /dev/null and b/audio/2.wav differ diff --git a/audio/3.wav b/audio/3.wav new file mode 100644 index 0000000..fdca6e5 Binary files /dev/null and b/audio/3.wav differ diff --git a/audio/4.wav b/audio/4.wav new file mode 100644 index 0000000..1222962 Binary files /dev/null and b/audio/4.wav differ diff --git a/audio/5.wav b/audio/5.wav new file mode 100644 index 0000000..4b54ed5 Binary files /dev/null and b/audio/5.wav differ diff --git a/audio/6.wav b/audio/6.wav new file mode 100644 index 0000000..2bb6e22 Binary files /dev/null and b/audio/6.wav differ diff --git a/audio/7.wav b/audio/7.wav new file mode 100644 index 0000000..97049b8 Binary files /dev/null and b/audio/7.wav differ diff --git a/classDefinitions.js b/classDefinitions.js index a8af3a8..4c1b352 100644 --- a/classDefinitions.js +++ b/classDefinitions.js @@ -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. + }); } } diff --git a/content.js b/content.js index 710e0cf..ed1233f 100644 --- a/content.js +++ b/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 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); } diff --git a/manifest.json b/manifest.json index ef0f415..63530b6 100644 --- a/manifest.json +++ b/manifest.json @@ -37,6 +37,7 @@ "resources": [ "fonts/*", "images/*", + "audio/*", "classDefinitions.js" ], "matches": [