mirror of
https://wiilab.wiimart.org/wiimart/wiimart-extension
synced 2025-09-02 19:41:00 +02:00
updated stuff
This commit is contained in:
parent
8dabf7102a
commit
721bef3e6c
@ -14,13 +14,8 @@ This is the source code to the WiiMart extension, which allows you to navigate W
|
||||
|
||||
## How to use
|
||||
1. Download the [latest code](https://wiilab.wiimart.org/wiimart/wiimart-extension/-/archive/main/wiimart-extension-main.zip) and extract that zip somewhere safe that you will remember
|
||||
### On Chrome:
|
||||
2. Rename `manifest-chrome.json` to `manifest.json`
|
||||
(if `manifest-chrome.json` doesnt exists, that means you dont need to do step 2)
|
||||
3. Go to your extensions and click `Manage extensions`
|
||||
4. Enable `Developer Mode` it should be at the top right of the screen
|
||||
5. Click `Load Unpacked` and go to the folder of the code that you extracted
|
||||
6. Go to [WiiMart's Shop](https://oss-auth.thecheese.io/oss/serv/index.jsp) and enjoy
|
||||
### On Chrome(or any chrome(ium) based browsers):
|
||||
Currently unsupported due to heavy issues
|
||||
### On Firefox:
|
||||
2. Rename `manifest-firefox.json` to `manifest.json`
|
||||
(if `manifest-firefox.json` doesnt exists, that means you dont need to do step 2)
|
||||
|
@ -1,9 +1,33 @@
|
||||
const _injectedWiiShopSoundUrls = window._wiiShopSoundUrls_ || [];
|
||||
const _injectedWiiShopBgmUrl = window._wiiShopBgmUrl_ || '';
|
||||
const _bgmInitiallyEnabled = window._wiiShopBgmInitiallyEnabled_ === true;
|
||||
const _bgmAlreadyPlaying = window._bgmAlreadyPlaying || false;
|
||||
const _currentstatus = window._currentstatus || "";
|
||||
// classDefinitions.js (This code runs in the page's main world)
|
||||
|
||||
// IMPORTANT: This script will now receive URLs via window.postMessage from the content script.
|
||||
|
||||
// These will be populated by the message listener
|
||||
let _wiiShopSoundUrls_ = [];
|
||||
let _wiiShopBgmUrl_ = '';
|
||||
let _bgmInitiallyEnabled = false; // This flag will also be passed via postMessage if needed, or handled by content.js
|
||||
let _bgmAlreadyPlaying = false; // This flag can be managed internally by wiiSound
|
||||
|
||||
// Add a variable to track the current status (matching your original logic)
|
||||
let _currentstatus = "";
|
||||
|
||||
// --- Listener for messages from the content script ---
|
||||
window.addEventListener('message', (event) => {
|
||||
// Ensure the message is from our extension and the correct type
|
||||
if (event.source === window && event.data && event.data.type === "WII_SHOP_EXTENSION_INIT") {
|
||||
_wiiShopSoundUrls_ = event.data.soundUrls;
|
||||
_wiiShopBgmUrl_ = event.data.bgmUrl;
|
||||
_bgmInitiallyEnabled = event.data.bgmInitiallyEnabled; // Capture this if needed in classDefinitions.js
|
||||
console.log("classDefinitions.js received URLs and initial BGM state from content script.");
|
||||
|
||||
// If you need to trigger BGM playback from *within* classDefinitions.js based on initial state, do it here
|
||||
// However, your content.js already handles this by sending a message to the background, which is better.
|
||||
// The _bgmInitiallyEnabled flag is now more for reference within this script if needed by other logic.
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Existing global variables exposed (these remain the same as your original)
|
||||
var ecsUrl = "";
|
||||
var iasUrl = "";
|
||||
var ccsUrl = "";
|
||||
@ -13,7 +37,6 @@ var tsz = "";
|
||||
var ttmdsz = "";
|
||||
var lv = "";
|
||||
|
||||
// Expose the URLs to the global scope
|
||||
window.ecsUrl = ecsUrl;
|
||||
window.iasUrl = iasUrl;
|
||||
window.ccsUrl = ccsUrl;
|
||||
@ -22,127 +45,125 @@ window.tid = tid;
|
||||
window.tsz = tsz;
|
||||
window.ttmdsz = ttmdsz;
|
||||
window.lv = lv;
|
||||
window._currentstatus = _currentstatus; // Expose _currentstatus to the global scope
|
||||
|
||||
|
||||
// Define the trace function
|
||||
const trace = function(...args) {
|
||||
extensionStorage.slog(...args)
|
||||
if (typeof extensionStorage !== 'undefined' && typeof extensionStorage.slog === 'function') {
|
||||
extensionStorage.slog(args.map(a => String(a)).join(' '));
|
||||
}
|
||||
console.log(...args);
|
||||
//console.trace(...args);
|
||||
};
|
||||
// content-script.js
|
||||
const storageCache = {};
|
||||
const STORAGE_ENDPOINT = '/_extension_storage';
|
||||
|
||||
// --- extensionStorage (remains largely the same, but will include sendMessageToBackground) ---
|
||||
const storageCache = {};
|
||||
const STORAGE_ENDPOINT = '/_extension_storage'; // This endpoint must be intercepted by background.js
|
||||
|
||||
const extensionStorage = {
|
||||
set: (key, value) => {
|
||||
storageCache[key] = value;
|
||||
fetch(`${STORAGE_ENDPOINT}?set_key=${encodeURIComponent(key)}&set_value=${encodeURIComponent(value)}`)
|
||||
.catch(() => {});
|
||||
storageCache[key] = value;
|
||||
fetch(`${STORAGE_ENDPOINT}?set_key=${encodeURIComponent(key)}&set_value=${encodeURIComponent(value)}`)
|
||||
.catch(e => console.error("[Page] Error sending storage_set:", e));
|
||||
},
|
||||
|
||||
|
||||
get: (key) => {
|
||||
if (key in storageCache) return storageCache[key];
|
||||
|
||||
const request = new XMLHttpRequest();
|
||||
request.open('GET', `${STORAGE_ENDPOINT}?get=${encodeURIComponent(key)}`, false);
|
||||
request.send(null);
|
||||
|
||||
if (request.status === 0) {
|
||||
if (key in storageCache) return storageCache[key];
|
||||
|
||||
const request = new XMLHttpRequest();
|
||||
// Use synchronous XHR for get, which is fine in page context
|
||||
request.open('GET', `${STORAGE_ENDPOINT}?get=${encodeURIComponent(key)}`, false);
|
||||
try {
|
||||
const data = JSON.parse(request.responseText);
|
||||
storageCache[key] = data.value;
|
||||
return data.value;
|
||||
} catch {
|
||||
return null;
|
||||
request.send(null);
|
||||
if (request.status === 200 || request.status === 0) { // status 0 for local file access in some contexts
|
||||
const data = JSON.parse(request.responseText);
|
||||
storageCache[key] = data.value;
|
||||
return data.value;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[Page] Error getting storage via XMLHttpRequest:", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
},
|
||||
|
||||
|
||||
slog: (message) => {
|
||||
fetch(`${STORAGE_ENDPOINT}?set_key=slogs&set_value=${encodeURIComponent(message)}`)
|
||||
.catch(() => {});
|
||||
fetch(`${STORAGE_ENDPOINT}?set_key=slogs&set_value=${encodeURIComponent(message)}`)
|
||||
.catch(e => console.error("[Page] Error sending slog:", e));
|
||||
},
|
||||
|
||||
|
||||
getLogs: () => {
|
||||
return extensionStorage.get('logs') || [];
|
||||
return extensionStorage.get('logs') || [];
|
||||
},
|
||||
|
||||
|
||||
clearLogs: () => {
|
||||
fetch(`${STORAGE_ENDPOINT}?clogs=true`)
|
||||
.catch(() => {});
|
||||
storageCache.logs = [];
|
||||
fetch(`${STORAGE_ENDPOINT}?clogs=true`)
|
||||
.catch(e => console.error("[Page] Error sending clearLogs:", e));
|
||||
storageCache.logs = [];
|
||||
},
|
||||
|
||||
spts: (points) => {
|
||||
const pointsToAdd = parseInt(points) || 0;
|
||||
if (pointsToAdd > 0) {
|
||||
fetch(`${STORAGE_ENDPOINT}?set_key=spts&set_value=${pointsToAdd}`)
|
||||
.catch(() => {});
|
||||
.catch(e => console.error("[Page] Error sending spts:", e));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getpts: () => {
|
||||
const points = extensionStorage.get('pts');
|
||||
return parseInt(points) || 0;
|
||||
},
|
||||
|
||||
|
||||
clearpts: () => {
|
||||
fetch(`${STORAGE_ENDPOINT}?cpts=true`)
|
||||
.catch(() => {});
|
||||
.catch(e => console.error("[Page] Error sending clearpts:", e));
|
||||
storageCache.pts = 0;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
// New method to send messages to the background script for BGM control
|
||||
sendMessageToBackground: async (message) => {
|
||||
let url = `${STORAGE_ENDPOINT}?action=${encodeURIComponent(message.action)}`;
|
||||
if (message.bgmUrl) {
|
||||
url += `&bgmUrl=${encodeURIComponent(message.bgmUrl)}`;
|
||||
}
|
||||
try {
|
||||
await fetch(url);
|
||||
} catch (e) {
|
||||
console.error(`[Page] Error sending BGM command '${message.action}':`, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.extensionStorage = extensionStorage;
|
||||
|
||||
console.log("Current points (from injected script):", extensionStorage.getpts());
|
||||
console.log("Trace loaded (from injected script):", extensionStorage.getLogs());
|
||||
|
||||
console.log("Current points:", extensionStorage.getpts());
|
||||
console.log("Trace loaded:", extensionStorage.getLogs());
|
||||
|
||||
// Define the ECommerceInterface class
|
||||
class ECommerceInterface {
|
||||
constructor() {
|
||||
const unwantedPath = "/oss/serv/CheckRegistered.jsp";
|
||||
if (window.location.pathname === unwantedPath) {
|
||||
//window.location.pathname = "/oss/serv/W_01.jsp";
|
||||
console.log("Do nothing...");
|
||||
}/*
|
||||
this._titlesMap = new Map([
|
||||
["0001000248414241", {
|
||||
name: 'Wii Shop Channel',
|
||||
version: '21',
|
||||
isTmdPresent: true,
|
||||
}],
|
||||
['0001000248414242', {
|
||||
name: 'idk',
|
||||
version: '1',
|
||||
isTmdPresent: true,
|
||||
}],
|
||||
]);*/
|
||||
trace("ECommerceInterface initialized"); // Use the trace function
|
||||
}
|
||||
trace("ECommerceInterface initialized");
|
||||
}
|
||||
|
||||
getTicketInfos(titleId) {
|
||||
// Return a mock object that simulates an unlimited license
|
||||
return {
|
||||
length: 1, // Simulate the length property
|
||||
length: 1,
|
||||
get: function(index) {
|
||||
if (index === 0) {
|
||||
return {
|
||||
deviceId: 222222, // Simulate a personalized ticket
|
||||
limits: null // No limits, indicating an unlimited license
|
||||
deviceId: 222222,
|
||||
limits: null
|
||||
};
|
||||
}
|
||||
return null; // Return null for any other index
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
/*
|
||||
getTitleInfo(shopAppTitleId) {
|
||||
const title = this._titlesMap.get(shopAppTitleId);
|
||||
if (!title || typeof title !== 'object' || !title.isTmdPresent || title.version == null) {
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
getTitleInfo(titleid) {
|
||||
if (titleid === "0001000248414241") {
|
||||
return {
|
||||
@ -169,16 +190,16 @@ class ECommerceInterface {
|
||||
}
|
||||
}
|
||||
getLog() {
|
||||
return extensionStorage.getLogs() || ""; // Return the stored trace or an empty string
|
||||
return extensionStorage.getLogs() || "";
|
||||
}
|
||||
|
||||
getPoints() {
|
||||
return extensionStorage.getpts() || 0; // Return the current points
|
||||
return extensionStorage.getpts() || 0;
|
||||
}
|
||||
|
||||
setPoints(newPoints) {
|
||||
if (!Number.isInteger(newPoints)) {
|
||||
newPoints = parseInt(newPoints, 10); // Convert to integer if not
|
||||
newPoints = parseInt(newPoints, 10);
|
||||
}
|
||||
|
||||
if (isNaN(newPoints)) {
|
||||
@ -187,7 +208,7 @@ class ECommerceInterface {
|
||||
}
|
||||
|
||||
extensionStorage.spts(newPoints);
|
||||
trace("Points updated to: " + extensionStorage.getpts());
|
||||
trace("Points updated to: " + extensionStorage.getpts());
|
||||
}
|
||||
|
||||
loadPoints() {
|
||||
@ -199,7 +220,7 @@ class ECommerceInterface {
|
||||
}
|
||||
|
||||
setWebSvcUrls(ecsuri, iasuri) {
|
||||
window.ecsUrl = ecsuri;
|
||||
window.ecsUrl = ecsuri;
|
||||
window.iasUrl = iasuri;
|
||||
}
|
||||
|
||||
@ -213,8 +234,7 @@ class ECommerceInterface {
|
||||
const storedPoints = window.localStorage.getItem('points');
|
||||
if (storedPoints) {
|
||||
return parseInt(storedPoints, 10);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -232,14 +252,6 @@ class ECommerceInterface {
|
||||
errCode: 0,
|
||||
errInfo: null,
|
||||
};
|
||||
/*
|
||||
const storedPoints = window.localStorage.getItem('points');
|
||||
if (storedPoints) {
|
||||
return parseInt(storedPoints, 10);
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}*/
|
||||
}
|
||||
|
||||
checkDeviceStatus() {
|
||||
@ -259,18 +271,17 @@ class ECommerceInterface {
|
||||
|
||||
getDeviceInfo() {
|
||||
return {
|
||||
country: "US", // Example value
|
||||
region: "USA", // Example value
|
||||
isParentalControlEnabled: false, // Example value
|
||||
userAge: 20, // Example value
|
||||
language: "fr", // Example value
|
||||
accountId: "659247864", // Example value
|
||||
deviceId: "4587571479", // Example value
|
||||
serial: "PC156494873", // Example value
|
||||
country: "US",
|
||||
region: "USA",
|
||||
isParentalControlEnabled: false,
|
||||
userAge: 20,
|
||||
language: "fr",
|
||||
accountId: "659247864",
|
||||
deviceId: "4587571479",
|
||||
serial: "PC156494873",
|
||||
maxUserInodes: 200000,
|
||||
usedUserInodes: 100000,
|
||||
freeChannelAppCount: 41,
|
||||
freeChannelAppCount: 41,
|
||||
blockSize: 536870912,
|
||||
totalBlocks: 65536,
|
||||
usedBlocks: 0,
|
||||
@ -373,7 +384,7 @@ class ECommerceInterface {
|
||||
|
||||
class wiiShop {
|
||||
constructor() {
|
||||
trace("wiiShop initialized"); // Use the trace function
|
||||
trace("wiiShop initialized");
|
||||
return "isok";
|
||||
}
|
||||
connecting = null;
|
||||
@ -390,10 +401,9 @@ class wiiShop {
|
||||
console.log("Does jack shit home button disabler")
|
||||
}
|
||||
sleep(duration) {
|
||||
return new Promise(resolve => setTimeout(resolve, duration)); // duration is in milliseconds
|
||||
return new Promise(resolve => setTimeout(resolve, duration));
|
||||
}
|
||||
async beginWaiting(seconds) {
|
||||
// Check if the input is a string and convert to integer if so
|
||||
if (seconds == null) {
|
||||
seconds = 3;
|
||||
}
|
||||
@ -401,21 +411,19 @@ class wiiShop {
|
||||
const parsedValue = parseInt(seconds, 10);
|
||||
if (isNaN(parsedValue) || parsedValue.toString() !== seconds) {
|
||||
console.error("Invalid input: Please provide a valid integer value.");
|
||||
return; // Exit the function if the string is not a valid integer
|
||||
return;
|
||||
}
|
||||
seconds = parsedValue; // Convert string to integer
|
||||
seconds = parsedValue;
|
||||
}
|
||||
|
||||
// Check if the input is a valid integer
|
||||
if (!Number.isInteger(seconds)) {
|
||||
console.error("Invalid input: Please provide an integer value.");
|
||||
return; // Exit the function if the input is not an integer
|
||||
return;
|
||||
}
|
||||
|
||||
let duration;
|
||||
|
||||
// Convert single-digit seconds to milliseconds
|
||||
duration = (seconds < 10) ? seconds * 1000 : seconds; // Convert to ms if single digit
|
||||
duration = (seconds < 10) ? seconds * 1000 : seconds;
|
||||
|
||||
await this.sleep(duration);
|
||||
console.log("Wait complete!");
|
||||
@ -427,21 +435,30 @@ class wiiShop {
|
||||
}
|
||||
|
||||
class wiiSound {
|
||||
static audioUrls = _injectedWiiShopSoundUrls;
|
||||
static currentBgmAudio = null;
|
||||
// These will now be populated by the message listener
|
||||
static audioUrls = [];
|
||||
static bgmUrl = '';
|
||||
static currentBgmAudio = null; // Stays static to manage a single BGM instance
|
||||
|
||||
constructor() {
|
||||
trace("wiiSound initialized");
|
||||
// No need to copy _injected variables here, as they'll be populated by the message listener
|
||||
}
|
||||
|
||||
playSE(snd) {
|
||||
// Ensure URLs are available before attempting to play
|
||||
if (!_wiiShopSoundUrls_ || _wiiShopSoundUrls_.length === 0) {
|
||||
console.warn("Audio URLs not yet loaded. Cannot play sound effect.");
|
||||
return;
|
||||
}
|
||||
|
||||
const soundIndex = parseInt(snd, 10);
|
||||
if (isNaN(soundIndex) || soundIndex < 1 || soundIndex >= wiiSound.audioUrls.length) {
|
||||
if (isNaN(soundIndex) || soundIndex < 1 || soundIndex >= _wiiShopSoundUrls_.length) {
|
||||
console.warn("Invalid sound index for wiiSound.playSE:", snd);
|
||||
return;
|
||||
}
|
||||
|
||||
const audioUrl = wiiSound.audioUrls[soundIndex];
|
||||
const audioUrl = _wiiShopSoundUrls_[soundIndex];
|
||||
if (!audioUrl) {
|
||||
console.warn("No audio URL found for sound index:", soundIndex);
|
||||
return;
|
||||
@ -459,44 +476,54 @@ class wiiSound {
|
||||
}
|
||||
|
||||
playBGM() {
|
||||
if (window._bgmAlreadyPlaying === true) {
|
||||
// Use an internal flag for _bgmAlreadyPlaying
|
||||
if (_bgmAlreadyPlaying === true) {
|
||||
return "nah mate, i aint playin for ya, im already playin";
|
||||
} else {
|
||||
window._bgmAlreadyPlaying = true;
|
||||
_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.");
|
||||
// Ensure BGM URL is available to send via extensionStorage
|
||||
if (!_wiiShopBgmUrl_) {
|
||||
console.warn("No BGM URL available to send to background script.");
|
||||
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.
|
||||
// Use extensionStorage.sendMessageToBackground to control BGM in background
|
||||
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.sendMessageToBackground === 'function') {
|
||||
window.extensionStorage.sendMessageToBackground({
|
||||
action: "playBGM",
|
||||
bgmUrl: _wiiShopBgmUrl_
|
||||
}).then(() => {
|
||||
trace('Request to play BGM sent to background script via extensionStorage.');
|
||||
}).catch(error => {
|
||||
console.error('Error sending playBGM message to background via extensionStorage:', error);
|
||||
});
|
||||
} else {
|
||||
console.warn("window.extensionStorage.sendMessageToBackground not available for playBGM.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stopBGM() {
|
||||
if (window._bgmAlreadyPlaying === true){
|
||||
if (wiiSound.currentBgmAudio) {
|
||||
wiiSound.currentBgmAudio.pause();
|
||||
wiiSound.currentBgmAudio.currentTime = 0;
|
||||
wiiSound.currentBgmAudio = null;
|
||||
console.log('Wii Shop BGM stopped.');
|
||||
// Use an internal flag for _bgmAlreadyPlaying
|
||||
if (_bgmAlreadyPlaying === true) {
|
||||
_bgmAlreadyPlaying = false; // Reset the flag
|
||||
// Send a message to background via extensionStorage to stop BGM
|
||||
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.sendMessageToBackground === 'function') {
|
||||
window.extensionStorage.sendMessageToBackground({
|
||||
action: "stopBGM"
|
||||
}).then(() => {
|
||||
trace('Request to stop BGM sent to background script via extensionStorage.');
|
||||
}).catch(error => {
|
||||
console.error('Error sending stopBGM message to background via extensionStorage:', error);
|
||||
});
|
||||
} else {
|
||||
console.warn("window.extensionStorage.sendMessageToBackground not available for stopBGM.");
|
||||
}
|
||||
} else {
|
||||
return "wtf do you want me to stop eh?";
|
||||
@ -549,9 +576,9 @@ class wiiNwc24 {
|
||||
const parsedValue = parseInt(fnm, 10);
|
||||
if (isNaN(parsedValue) || parsedValue.toString() !== fnm) {
|
||||
console.error("Invalid input: Please provide a valid integer value.");
|
||||
return; // Exit the function if the string is not a valid integer
|
||||
return;
|
||||
}
|
||||
fnm = parsedValue; // Convert string to integer
|
||||
fnm = parsedValue;
|
||||
}
|
||||
if (data == "name") {
|
||||
if (fnm == 0) {
|
||||
@ -581,7 +608,7 @@ class wiiNwc24 {
|
||||
}
|
||||
if (data == "miiImage") {
|
||||
return "111"
|
||||
}
|
||||
}
|
||||
}
|
||||
myUserId = "0302167078436756";
|
||||
}
|
||||
@ -605,6 +632,9 @@ window.wiiKeyboard = wiiKeyboard;
|
||||
window.wiiShop = wiiShop;
|
||||
window.wiiSound = wiiSound;
|
||||
window.wiiMii = wiiMii;
|
||||
window.wiiDlTask = wiiDlTask;
|
||||
window.wiiNwc24 = wiiNwc24;
|
||||
window.wiiSDCard = wiiSDCard;
|
||||
|
||||
if (_bgmInitiallyEnabled) {
|
||||
// Use a short delay or an event listener to ensure all page elements are ready
|
||||
|
99
content.js
99
content.js
@ -11,6 +11,7 @@ const storageAPI = runtimeAPI.storage; // This will be browser.storage or chrome
|
||||
let fontLoaded = false;
|
||||
|
||||
function loadFont() {
|
||||
return "disabled";
|
||||
const fontUrl = runtimeAPI.runtime.getURL("fonts/fot_rodin_pro_m.ttf");
|
||||
const style = document.createElement('style');
|
||||
style.textContent = `
|
||||
@ -81,7 +82,7 @@ function loadFont() {
|
||||
function checkFontState() {
|
||||
storageAPI.local.get(['fontDisabled']).then(function(result) {
|
||||
if (!result.fontDisabled) {
|
||||
loadFont(); // Call loadFont, no need to return its string status here
|
||||
//loadFont();
|
||||
} else {
|
||||
console.log("Font loading disabled by preference.");
|
||||
}
|
||||
@ -97,7 +98,17 @@ const soundFilePaths = [
|
||||
'audio/4.wav',
|
||||
'audio/5.wav',
|
||||
'audio/6.wav',
|
||||
'audio/7.wav'
|
||||
'audio/7.wav',
|
||||
'audio/8.wav',
|
||||
'audio/9.wav',
|
||||
'audio/10.wav',
|
||||
'audio/11.wav',
|
||||
'audio/12.wav',
|
||||
'audio/13.wav',
|
||||
'audio/14.wav',
|
||||
'audio/15.wav',
|
||||
'audio/16.wav'
|
||||
|
||||
];
|
||||
const bgmFilePath = 'audio/bgm.wav'; // Define BGM file path
|
||||
|
||||
@ -114,54 +125,61 @@ const generatedBgmUrl = runtimeAPI.runtime.getURL(bgmFilePath); // Generate BGM
|
||||
|
||||
|
||||
// Function to load class definitions and inject globals
|
||||
const loadClassDefinitions = async () => {
|
||||
let classDefinitionsUrl = runtimeAPI.runtime.getURL('classDefinitions.js');
|
||||
|
||||
try {
|
||||
const response = await fetch(classDefinitionsUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
const loadClassDefinitions = () => {
|
||||
const injectScript = () => {
|
||||
if (document.documentElement.querySelector('script[data-injected-id="wii-shop-cdjs"]')) {
|
||||
// Already injected, prevent double injection
|
||||
return;
|
||||
}
|
||||
const classDefinitionsText = await response.text();
|
||||
|
||||
// Get the current BGM enabled state from storage
|
||||
const storageResult = await storageAPI.local.get(['bgmEnabled']);
|
||||
const bgmInitiallyEnabled = storageResult.bgmEnabled === true; // Default to false if not set
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.setAttribute('type', 'text/javascript');
|
||||
script.setAttribute('src', runtimeAPI.runtime.getURL('classDefinitions.js')); // Set src to the external file
|
||||
script.setAttribute('data-injected-id', 'wii-shop-cdjs'); // Add an ID to prevent duplicates
|
||||
|
||||
// PREPEND the sound and BGM URLs as global variables *before* the classDefinitions.js content
|
||||
script.textContent = `
|
||||
(function() {
|
||||
// Define global variables that classDefinitions.js can access
|
||||
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
|
||||
// Inject into the document.documentElement (<html> tag) as the very first child
|
||||
if (document.documentElement) {
|
||||
document.documentElement.insertBefore(script, document.documentElement.firstChild);
|
||||
console.log("classDefinitions.js injected into page context via script element (early).");
|
||||
|
||||
document.documentElement.insertBefore(script, document.documentElement.firstChild);
|
||||
// --- Post message to the injected script AFTER it's loaded ---
|
||||
// This ensures classDefinitions.js has a chance to set up its message listener.
|
||||
script.onload = () => {
|
||||
window.postMessage({
|
||||
type: "WII_SHOP_EXTENSION_INIT",
|
||||
soundUrls: generatedSoundUrls,
|
||||
bgmUrl: generatedBgmUrl
|
||||
}, window.location.origin); // Specify origin for security
|
||||
console.log("WII_SHOP_EXTENSION_INIT message sent to page context.");
|
||||
};
|
||||
script.onerror = (e) => {
|
||||
console.error("Error loading classDefinitions.js:", e);
|
||||
};
|
||||
|
||||
script.onload = function() {
|
||||
this.remove();
|
||||
// Clean up the global variables after classDefinitions.js has likely used them
|
||||
// These are no longer needed as they are referenced immediately by the injected script.
|
||||
// delete window._wiiShopSoundUrls_;
|
||||
// delete window._wiiShopBgmUrl_;
|
||||
// delete window._wiiShopBgmInitiallyEnabled_; // Clean up BGM state
|
||||
};
|
||||
console.log("classDefinitions.js and global URLs injected into page context via script element.");
|
||||
} else {
|
||||
console.error("Failed to inject script: document.documentElement not found.");
|
||||
}
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error("Failed to load class definitions:", error);
|
||||
// Check if document.documentElement is already available
|
||||
if (document.documentElement) {
|
||||
injectScript();
|
||||
} else {
|
||||
// If not, use a MutationObserver to wait for the <html> element to be available
|
||||
const observer = new MutationObserver((mutations, obs) => {
|
||||
if (document.documentElement) {
|
||||
injectScript();
|
||||
obs.disconnect(); // Stop observing once injected
|
||||
}
|
||||
});
|
||||
// Observe the document for changes in its child nodes (to catch <html> being added)
|
||||
observer.observe(document, { childList: true, subtree: true });
|
||||
}
|
||||
};
|
||||
|
||||
// Load the class definitions
|
||||
loadClassDefinitions();
|
||||
// Load the existing trace and points from localStorage
|
||||
checkFontState(); // Call checkFontState to initiate font loading
|
||||
checkFontState();
|
||||
|
||||
|
||||
// --- Initial BGM Playback on DOMContentLoaded ---
|
||||
@ -170,16 +188,13 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
|
||||
// Request the initial BGM enabled state from the background script via extensionStorage
|
||||
// We expect extensionStorage to be available after classDefinitions.js is injected
|
||||
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.get === 'function') {
|
||||
try {
|
||||
const bgmEnabled = await window.extensionStorage.get('bgmEnabled');
|
||||
console.log("Initial BGM enabled state from storage:", bgmEnabled);
|
||||
|
||||
if (bgmEnabled === true) { // Explicitly check for true
|
||||
if (bgmEnabled === true) {
|
||||
console.log("Attempting to play initial BGM from content script.");
|
||||
// Use the new sendMessageToBackground proxy for BGM control
|
||||
// This will send a request to /_extension_storage?action=playBGM&bgmUrl=...
|
||||
window.extensionStorage.sendMessageToBackground({
|
||||
action: "playBGM",
|
||||
bgmUrl: generatedBgmUrl
|
||||
@ -198,7 +213,6 @@ runtimeAPI.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.action === "toggleBGMImmediate") {
|
||||
if (request.enabled) {
|
||||
console.log("Received toggleBGMImmediate from popup: Play BGM.");
|
||||
// Send a message to background via extensionStorage proxy for consistency
|
||||
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.sendMessageToBackground === 'function') {
|
||||
window.extensionStorage.sendMessageToBackground({
|
||||
action: "playBGM",
|
||||
@ -207,7 +221,6 @@ runtimeAPI.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
}
|
||||
} else {
|
||||
console.log("Received toggleBGMImmediate from popup: Stop BGM.");
|
||||
// Send a message to background via extensionStorage proxy for consistency
|
||||
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.sendMessageToBackground === 'function') {
|
||||
window.extensionStorage.sendMessageToBackground({
|
||||
action: "stopBGM"
|
||||
|
@ -1,51 +0,0 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "WiiShop but on browsers (Chrome)",
|
||||
"version": "1.0",
|
||||
"permissions": [
|
||||
"scripting",
|
||||
"activeTab",
|
||||
"storage",
|
||||
"webRequest",
|
||||
"webRequestBlocking"
|
||||
],
|
||||
"host_permissions": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"action": {
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"https://oss-auth.blinklab.com/*",
|
||||
"https://oss-auth.thecheese.io/*",
|
||||
"https://oss-auth.shop.wii.com/*",
|
||||
"http://wiimart:8080/oss/serv/*",
|
||||
"https://wiimart:8080/oss/serv/*"
|
||||
],
|
||||
"js": ["content.js"],
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
"web_accessible_resources": [
|
||||
{
|
||||
"resources": [
|
||||
"images/*",
|
||||
"audio/*",
|
||||
"classDefinitions.js",
|
||||
"fonts/*"
|
||||
],
|
||||
"matches": [
|
||||
"https://oss-auth.blinklab.com/*",
|
||||
"https://oss-auth.thecheese.io/*",
|
||||
"https://oss-auth.shop.wii.com/*",
|
||||
"http://wiimart:8080/*",
|
||||
"https://wiimart:8080/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -22,11 +22,7 @@
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"https://oss-auth.blinklab.com/*",
|
||||
"https://oss-auth.thecheese.io/*",
|
||||
"https://oss-auth.shop.wii.com/*",
|
||||
"http://wiimart:8080/oss/serv/*",
|
||||
"https://wiimart:8080/oss/serv/*"
|
||||
"https://oss-auth.thecheese.io/*"
|
||||
],
|
||||
"js": ["content.js"],
|
||||
"run_at": "document_start"
|
||||
@ -41,11 +37,7 @@
|
||||
"classDefinitions.js"
|
||||
],
|
||||
"matches": [
|
||||
"https://oss-auth.blinklab.com/*",
|
||||
"https://oss-auth.thecheese.io/*",
|
||||
"https://oss-auth.shop.wii.com/*",
|
||||
"http://wiimart:8080/oss/serv/*",
|
||||
"https://wiimart:8080/oss/serv/*"
|
||||
"https://oss-auth.thecheese.io/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user