mirror of
https://wiilab.wiimart.org/wiimart/wiimart-extension
synced 2025-09-03 20:11:04 +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
|
## 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
|
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:
|
### On Chrome(or any chrome(ium) based browsers):
|
||||||
2. Rename `manifest-chrome.json` to `manifest.json`
|
Currently unsupported due to heavy issues
|
||||||
(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 Firefox:
|
### On Firefox:
|
||||||
2. Rename `manifest-firefox.json` to `manifest.json`
|
2. Rename `manifest-firefox.json` to `manifest.json`
|
||||||
(if `manifest-firefox.json` doesnt exists, that means you dont need to do step 2)
|
(if `manifest-firefox.json` doesnt exists, that means you dont need to do step 2)
|
||||||
|
@ -1,9 +1,33 @@
|
|||||||
const _injectedWiiShopSoundUrls = window._wiiShopSoundUrls_ || [];
|
// classDefinitions.js (This code runs in the page's main world)
|
||||||
const _injectedWiiShopBgmUrl = window._wiiShopBgmUrl_ || '';
|
|
||||||
const _bgmInitiallyEnabled = window._wiiShopBgmInitiallyEnabled_ === true;
|
|
||||||
const _bgmAlreadyPlaying = window._bgmAlreadyPlaying || false;
|
|
||||||
const _currentstatus = window._currentstatus || "";
|
|
||||||
|
|
||||||
|
// 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 ecsUrl = "";
|
||||||
var iasUrl = "";
|
var iasUrl = "";
|
||||||
var ccsUrl = "";
|
var ccsUrl = "";
|
||||||
@ -13,7 +37,6 @@ var tsz = "";
|
|||||||
var ttmdsz = "";
|
var ttmdsz = "";
|
||||||
var lv = "";
|
var lv = "";
|
||||||
|
|
||||||
// Expose the URLs to the global scope
|
|
||||||
window.ecsUrl = ecsUrl;
|
window.ecsUrl = ecsUrl;
|
||||||
window.iasUrl = iasUrl;
|
window.iasUrl = iasUrl;
|
||||||
window.ccsUrl = ccsUrl;
|
window.ccsUrl = ccsUrl;
|
||||||
@ -22,127 +45,125 @@ window.tid = tid;
|
|||||||
window.tsz = tsz;
|
window.tsz = tsz;
|
||||||
window.ttmdsz = ttmdsz;
|
window.ttmdsz = ttmdsz;
|
||||||
window.lv = lv;
|
window.lv = lv;
|
||||||
|
window._currentstatus = _currentstatus; // Expose _currentstatus to the global scope
|
||||||
|
|
||||||
|
|
||||||
// Define the trace function
|
// Define the trace function
|
||||||
const trace = function(...args) {
|
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.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 = {
|
const extensionStorage = {
|
||||||
set: (key, value) => {
|
set: (key, value) => {
|
||||||
storageCache[key] = value;
|
storageCache[key] = value;
|
||||||
fetch(`${STORAGE_ENDPOINT}?set_key=${encodeURIComponent(key)}&set_value=${encodeURIComponent(value)}`)
|
fetch(`${STORAGE_ENDPOINT}?set_key=${encodeURIComponent(key)}&set_value=${encodeURIComponent(value)}`)
|
||||||
.catch(() => {});
|
.catch(e => console.error("[Page] Error sending storage_set:", e));
|
||||||
},
|
},
|
||||||
|
|
||||||
get: (key) => {
|
get: (key) => {
|
||||||
if (key in storageCache) return storageCache[key];
|
if (key in storageCache) return storageCache[key];
|
||||||
|
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open('GET', `${STORAGE_ENDPOINT}?get=${encodeURIComponent(key)}`, false);
|
// Use synchronous XHR for get, which is fine in page context
|
||||||
request.send(null);
|
request.open('GET', `${STORAGE_ENDPOINT}?get=${encodeURIComponent(key)}`, false);
|
||||||
|
|
||||||
if (request.status === 0) {
|
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(request.responseText);
|
request.send(null);
|
||||||
storageCache[key] = data.value;
|
if (request.status === 200 || request.status === 0) { // status 0 for local file access in some contexts
|
||||||
return data.value;
|
const data = JSON.parse(request.responseText);
|
||||||
} catch {
|
storageCache[key] = data.value;
|
||||||
return null;
|
return data.value;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[Page] Error getting storage via XMLHttpRequest:", e);
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
slog: (message) => {
|
slog: (message) => {
|
||||||
fetch(`${STORAGE_ENDPOINT}?set_key=slogs&set_value=${encodeURIComponent(message)}`)
|
fetch(`${STORAGE_ENDPOINT}?set_key=slogs&set_value=${encodeURIComponent(message)}`)
|
||||||
.catch(() => {});
|
.catch(e => console.error("[Page] Error sending slog:", e));
|
||||||
},
|
},
|
||||||
|
|
||||||
getLogs: () => {
|
getLogs: () => {
|
||||||
return extensionStorage.get('logs') || [];
|
return extensionStorage.get('logs') || [];
|
||||||
},
|
},
|
||||||
|
|
||||||
clearLogs: () => {
|
clearLogs: () => {
|
||||||
fetch(`${STORAGE_ENDPOINT}?clogs=true`)
|
fetch(`${STORAGE_ENDPOINT}?clogs=true`)
|
||||||
.catch(() => {});
|
.catch(e => console.error("[Page] Error sending clearLogs:", e));
|
||||||
storageCache.logs = [];
|
storageCache.logs = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
spts: (points) => {
|
spts: (points) => {
|
||||||
const pointsToAdd = parseInt(points) || 0;
|
const pointsToAdd = parseInt(points) || 0;
|
||||||
if (pointsToAdd > 0) {
|
if (pointsToAdd > 0) {
|
||||||
fetch(`${STORAGE_ENDPOINT}?set_key=spts&set_value=${pointsToAdd}`)
|
fetch(`${STORAGE_ENDPOINT}?set_key=spts&set_value=${pointsToAdd}`)
|
||||||
.catch(() => {});
|
.catch(e => console.error("[Page] Error sending spts:", e));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getpts: () => {
|
getpts: () => {
|
||||||
const points = extensionStorage.get('pts');
|
const points = extensionStorage.get('pts');
|
||||||
return parseInt(points) || 0;
|
return parseInt(points) || 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
clearpts: () => {
|
clearpts: () => {
|
||||||
fetch(`${STORAGE_ENDPOINT}?cpts=true`)
|
fetch(`${STORAGE_ENDPOINT}?cpts=true`)
|
||||||
.catch(() => {});
|
.catch(e => console.error("[Page] Error sending clearpts:", e));
|
||||||
storageCache.pts = 0;
|
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
|
// Define the ECommerceInterface class
|
||||||
class ECommerceInterface {
|
class ECommerceInterface {
|
||||||
constructor() {
|
constructor() {
|
||||||
const unwantedPath = "/oss/serv/CheckRegistered.jsp";
|
const unwantedPath = "/oss/serv/CheckRegistered.jsp";
|
||||||
if (window.location.pathname === unwantedPath) {
|
if (window.location.pathname === unwantedPath) {
|
||||||
//window.location.pathname = "/oss/serv/W_01.jsp";
|
|
||||||
console.log("Do nothing...");
|
console.log("Do nothing...");
|
||||||
}/*
|
}
|
||||||
this._titlesMap = new Map([
|
trace("ECommerceInterface initialized");
|
||||||
["0001000248414241", {
|
|
||||||
name: 'Wii Shop Channel',
|
|
||||||
version: '21',
|
|
||||||
isTmdPresent: true,
|
|
||||||
}],
|
|
||||||
['0001000248414242', {
|
|
||||||
name: 'idk',
|
|
||||||
version: '1',
|
|
||||||
isTmdPresent: true,
|
|
||||||
}],
|
|
||||||
]);*/
|
|
||||||
trace("ECommerceInterface initialized"); // Use the trace function
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getTicketInfos(titleId) {
|
getTicketInfos(titleId) {
|
||||||
// Return a mock object that simulates an unlimited license
|
|
||||||
return {
|
return {
|
||||||
length: 1, // Simulate the length property
|
length: 1,
|
||||||
get: function(index) {
|
get: function(index) {
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
return {
|
return {
|
||||||
deviceId: 222222, // Simulate a personalized ticket
|
deviceId: 222222,
|
||||||
limits: null // No limits, indicating an unlimited license
|
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) {
|
getTitleInfo(titleid) {
|
||||||
if (titleid === "0001000248414241") {
|
if (titleid === "0001000248414241") {
|
||||||
return {
|
return {
|
||||||
@ -169,16 +190,16 @@ class ECommerceInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
getLog() {
|
getLog() {
|
||||||
return extensionStorage.getLogs() || ""; // Return the stored trace or an empty string
|
return extensionStorage.getLogs() || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
getPoints() {
|
getPoints() {
|
||||||
return extensionStorage.getpts() || 0; // Return the current points
|
return extensionStorage.getpts() || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
setPoints(newPoints) {
|
setPoints(newPoints) {
|
||||||
if (!Number.isInteger(newPoints)) {
|
if (!Number.isInteger(newPoints)) {
|
||||||
newPoints = parseInt(newPoints, 10); // Convert to integer if not
|
newPoints = parseInt(newPoints, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNaN(newPoints)) {
|
if (isNaN(newPoints)) {
|
||||||
@ -187,7 +208,7 @@ class ECommerceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extensionStorage.spts(newPoints);
|
extensionStorage.spts(newPoints);
|
||||||
trace("Points updated to: " + extensionStorage.getpts());
|
trace("Points updated to: " + extensionStorage.getpts());
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPoints() {
|
loadPoints() {
|
||||||
@ -199,7 +220,7 @@ class ECommerceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setWebSvcUrls(ecsuri, iasuri) {
|
setWebSvcUrls(ecsuri, iasuri) {
|
||||||
window.ecsUrl = ecsuri;
|
window.ecsUrl = ecsuri;
|
||||||
window.iasUrl = iasuri;
|
window.iasUrl = iasuri;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,8 +234,7 @@ class ECommerceInterface {
|
|||||||
const storedPoints = window.localStorage.getItem('points');
|
const storedPoints = window.localStorage.getItem('points');
|
||||||
if (storedPoints) {
|
if (storedPoints) {
|
||||||
return parseInt(storedPoints, 10);
|
return parseInt(storedPoints, 10);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,14 +252,6 @@ class ECommerceInterface {
|
|||||||
errCode: 0,
|
errCode: 0,
|
||||||
errInfo: null,
|
errInfo: null,
|
||||||
};
|
};
|
||||||
/*
|
|
||||||
const storedPoints = window.localStorage.getItem('points');
|
|
||||||
if (storedPoints) {
|
|
||||||
return parseInt(storedPoints, 10);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return 0;
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDeviceStatus() {
|
checkDeviceStatus() {
|
||||||
@ -259,18 +271,17 @@ class ECommerceInterface {
|
|||||||
|
|
||||||
getDeviceInfo() {
|
getDeviceInfo() {
|
||||||
return {
|
return {
|
||||||
country: "US", // Example value
|
country: "US",
|
||||||
region: "USA", // Example value
|
region: "USA",
|
||||||
isParentalControlEnabled: false, // Example value
|
isParentalControlEnabled: false,
|
||||||
userAge: 20, // Example value
|
userAge: 20,
|
||||||
language: "fr", // Example value
|
language: "fr",
|
||||||
accountId: "659247864", // Example value
|
accountId: "659247864",
|
||||||
deviceId: "4587571479", // Example value
|
deviceId: "4587571479",
|
||||||
serial: "PC156494873", // Example value
|
serial: "PC156494873",
|
||||||
maxUserInodes: 200000,
|
maxUserInodes: 200000,
|
||||||
usedUserInodes: 100000,
|
usedUserInodes: 100000,
|
||||||
freeChannelAppCount: 41,
|
freeChannelAppCount: 41,
|
||||||
freeChannelAppCount: 41,
|
|
||||||
blockSize: 536870912,
|
blockSize: 536870912,
|
||||||
totalBlocks: 65536,
|
totalBlocks: 65536,
|
||||||
usedBlocks: 0,
|
usedBlocks: 0,
|
||||||
@ -373,7 +384,7 @@ class ECommerceInterface {
|
|||||||
|
|
||||||
class wiiShop {
|
class wiiShop {
|
||||||
constructor() {
|
constructor() {
|
||||||
trace("wiiShop initialized"); // Use the trace function
|
trace("wiiShop initialized");
|
||||||
return "isok";
|
return "isok";
|
||||||
}
|
}
|
||||||
connecting = null;
|
connecting = null;
|
||||||
@ -390,10 +401,9 @@ class wiiShop {
|
|||||||
console.log("Does jack shit home button disabler")
|
console.log("Does jack shit home button disabler")
|
||||||
}
|
}
|
||||||
sleep(duration) {
|
sleep(duration) {
|
||||||
return new Promise(resolve => setTimeout(resolve, duration)); // duration is in milliseconds
|
return new Promise(resolve => setTimeout(resolve, duration));
|
||||||
}
|
}
|
||||||
async beginWaiting(seconds) {
|
async beginWaiting(seconds) {
|
||||||
// Check if the input is a string and convert to integer if so
|
|
||||||
if (seconds == null) {
|
if (seconds == null) {
|
||||||
seconds = 3;
|
seconds = 3;
|
||||||
}
|
}
|
||||||
@ -401,21 +411,19 @@ class wiiShop {
|
|||||||
const parsedValue = parseInt(seconds, 10);
|
const parsedValue = parseInt(seconds, 10);
|
||||||
if (isNaN(parsedValue) || parsedValue.toString() !== seconds) {
|
if (isNaN(parsedValue) || parsedValue.toString() !== seconds) {
|
||||||
console.error("Invalid input: Please provide a valid integer value.");
|
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)) {
|
if (!Number.isInteger(seconds)) {
|
||||||
console.error("Invalid input: Please provide an integer value.");
|
console.error("Invalid input: Please provide an integer value.");
|
||||||
return; // Exit the function if the input is not an integer
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let duration;
|
let duration;
|
||||||
|
|
||||||
// Convert single-digit seconds to milliseconds
|
duration = (seconds < 10) ? seconds * 1000 : seconds;
|
||||||
duration = (seconds < 10) ? seconds * 1000 : seconds; // Convert to ms if single digit
|
|
||||||
|
|
||||||
await this.sleep(duration);
|
await this.sleep(duration);
|
||||||
console.log("Wait complete!");
|
console.log("Wait complete!");
|
||||||
@ -427,21 +435,30 @@ class wiiShop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class wiiSound {
|
class wiiSound {
|
||||||
static audioUrls = _injectedWiiShopSoundUrls;
|
// These will now be populated by the message listener
|
||||||
static currentBgmAudio = null;
|
static audioUrls = [];
|
||||||
|
static bgmUrl = '';
|
||||||
|
static currentBgmAudio = null; // Stays static to manage a single BGM instance
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
trace("wiiSound initialized");
|
trace("wiiSound initialized");
|
||||||
|
// No need to copy _injected variables here, as they'll be populated by the message listener
|
||||||
}
|
}
|
||||||
|
|
||||||
playSE(snd) {
|
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);
|
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);
|
console.warn("Invalid sound index for wiiSound.playSE:", snd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const audioUrl = wiiSound.audioUrls[soundIndex];
|
const audioUrl = _wiiShopSoundUrls_[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);
|
||||||
return;
|
return;
|
||||||
@ -459,44 +476,54 @@ class wiiSound {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playBGM() {
|
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";
|
return "nah mate, i aint playin for ya, im already playin";
|
||||||
} else {
|
} else {
|
||||||
window._bgmAlreadyPlaying = true;
|
_bgmAlreadyPlaying = true;
|
||||||
if (wiiSound.currentBgmAudio && !wiiSound.currentBgmAudio.paused) {
|
if (wiiSound.currentBgmAudio && !wiiSound.currentBgmAudio.paused) {
|
||||||
wiiSound.currentBgmAudio.pause();
|
wiiSound.currentBgmAudio.pause();
|
||||||
wiiSound.currentBgmAudio.currentTime = 0;
|
wiiSound.currentBgmAudio.currentTime = 0;
|
||||||
console.log('Stopped previous BGM.');
|
console.log('Stopped previous BGM.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_injectedWiiShopBgmUrl) {
|
// Ensure BGM URL is available to send via extensionStorage
|
||||||
console.warn("No BGM URL available.");
|
if (!_wiiShopBgmUrl_) {
|
||||||
|
console.warn("No BGM URL available to send to background script.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const audio = new Audio(_injectedWiiShopBgmUrl);
|
// Use extensionStorage.sendMessageToBackground to control BGM in background
|
||||||
audio.loop = true;
|
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.sendMessageToBackground === 'function') {
|
||||||
audio.style.display = 'none';
|
window.extensionStorage.sendMessageToBackground({
|
||||||
|
action: "playBGM",
|
||||||
audio.play()
|
bgmUrl: _wiiShopBgmUrl_
|
||||||
.then(() => {
|
}).then(() => {
|
||||||
wiiSound.currentBgmAudio = audio;
|
trace('Request to play BGM sent to background script via extensionStorage.');
|
||||||
console.log('Wii Shop BGM started and looping:', _injectedWiiShopBgmUrl);
|
}).catch(error => {
|
||||||
})
|
console.error('Error sending playBGM message to background via extensionStorage:', error);
|
||||||
.catch(error => {
|
|
||||||
console.error('Error playing Wii Shop BGM:', _injectedWiiShopBgmUrl, error);
|
|
||||||
// Autoplay policy issues are common here.
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.warn("window.extensionStorage.sendMessageToBackground not available for playBGM.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stopBGM() {
|
stopBGM() {
|
||||||
if (window._bgmAlreadyPlaying === true){
|
// Use an internal flag for _bgmAlreadyPlaying
|
||||||
if (wiiSound.currentBgmAudio) {
|
if (_bgmAlreadyPlaying === true) {
|
||||||
wiiSound.currentBgmAudio.pause();
|
_bgmAlreadyPlaying = false; // Reset the flag
|
||||||
wiiSound.currentBgmAudio.currentTime = 0;
|
// Send a message to background via extensionStorage to stop BGM
|
||||||
wiiSound.currentBgmAudio = null;
|
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.sendMessageToBackground === 'function') {
|
||||||
console.log('Wii Shop BGM stopped.');
|
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 {
|
} else {
|
||||||
return "wtf do you want me to stop eh?";
|
return "wtf do you want me to stop eh?";
|
||||||
@ -549,9 +576,9 @@ class wiiNwc24 {
|
|||||||
const parsedValue = parseInt(fnm, 10);
|
const parsedValue = parseInt(fnm, 10);
|
||||||
if (isNaN(parsedValue) || parsedValue.toString() !== fnm) {
|
if (isNaN(parsedValue) || parsedValue.toString() !== fnm) {
|
||||||
console.error("Invalid input: Please provide a valid integer value.");
|
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 (data == "name") {
|
||||||
if (fnm == 0) {
|
if (fnm == 0) {
|
||||||
@ -581,7 +608,7 @@ class wiiNwc24 {
|
|||||||
}
|
}
|
||||||
if (data == "miiImage") {
|
if (data == "miiImage") {
|
||||||
return "111"
|
return "111"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
myUserId = "0302167078436756";
|
myUserId = "0302167078436756";
|
||||||
}
|
}
|
||||||
@ -605,6 +632,9 @@ window.wiiKeyboard = wiiKeyboard;
|
|||||||
window.wiiShop = wiiShop;
|
window.wiiShop = wiiShop;
|
||||||
window.wiiSound = wiiSound;
|
window.wiiSound = wiiSound;
|
||||||
window.wiiMii = wiiMii;
|
window.wiiMii = wiiMii;
|
||||||
|
window.wiiDlTask = wiiDlTask;
|
||||||
|
window.wiiNwc24 = wiiNwc24;
|
||||||
|
window.wiiSDCard = wiiSDCard;
|
||||||
|
|
||||||
if (_bgmInitiallyEnabled) {
|
if (_bgmInitiallyEnabled) {
|
||||||
// Use a short delay or an event listener to ensure all page elements are ready
|
// 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;
|
let fontLoaded = false;
|
||||||
|
|
||||||
function loadFont() {
|
function loadFont() {
|
||||||
|
return "disabled";
|
||||||
const fontUrl = runtimeAPI.runtime.getURL("fonts/fot_rodin_pro_m.ttf");
|
const fontUrl = runtimeAPI.runtime.getURL("fonts/fot_rodin_pro_m.ttf");
|
||||||
const style = document.createElement('style');
|
const style = document.createElement('style');
|
||||||
style.textContent = `
|
style.textContent = `
|
||||||
@ -81,7 +82,7 @@ function loadFont() {
|
|||||||
function checkFontState() {
|
function checkFontState() {
|
||||||
storageAPI.local.get(['fontDisabled']).then(function(result) {
|
storageAPI.local.get(['fontDisabled']).then(function(result) {
|
||||||
if (!result.fontDisabled) {
|
if (!result.fontDisabled) {
|
||||||
loadFont(); // Call loadFont, no need to return its string status here
|
//loadFont();
|
||||||
} else {
|
} else {
|
||||||
console.log("Font loading disabled by preference.");
|
console.log("Font loading disabled by preference.");
|
||||||
}
|
}
|
||||||
@ -97,7 +98,17 @@ const soundFilePaths = [
|
|||||||
'audio/4.wav',
|
'audio/4.wav',
|
||||||
'audio/5.wav',
|
'audio/5.wav',
|
||||||
'audio/6.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
|
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
|
// Function to load class definitions and inject globals
|
||||||
const loadClassDefinitions = async () => {
|
const loadClassDefinitions = () => {
|
||||||
let classDefinitionsUrl = runtimeAPI.runtime.getURL('classDefinitions.js');
|
const injectScript = () => {
|
||||||
|
if (document.documentElement.querySelector('script[data-injected-id="wii-shop-cdjs"]')) {
|
||||||
try {
|
// Already injected, prevent double injection
|
||||||
const response = await fetch(classDefinitionsUrl);
|
return;
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
}
|
}
|
||||||
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');
|
const script = document.createElement('script');
|
||||||
script.setAttribute('type', 'text/javascript');
|
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
|
// Inject into the document.documentElement (<html> tag) as the very first child
|
||||||
script.textContent = `
|
if (document.documentElement) {
|
||||||
(function() {
|
document.documentElement.insertBefore(script, document.documentElement.firstChild);
|
||||||
// Define global variables that classDefinitions.js can access
|
console.log("classDefinitions.js injected into page context via script element (early).");
|
||||||
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
|
|
||||||
|
|
||||||
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() {
|
} else {
|
||||||
this.remove();
|
console.error("Failed to inject script: document.documentElement not found.");
|
||||||
// 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.");
|
|
||||||
|
|
||||||
} catch (error) {
|
// Check if document.documentElement is already available
|
||||||
console.error("Failed to load class definitions:", error);
|
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
|
// Load the class definitions
|
||||||
loadClassDefinitions();
|
loadClassDefinitions();
|
||||||
// Load the existing trace and points from localStorage
|
checkFontState();
|
||||||
checkFontState(); // Call checkFontState to initiate font loading
|
|
||||||
|
|
||||||
|
|
||||||
// --- Initial BGM Playback on DOMContentLoaded ---
|
// --- Initial BGM Playback on DOMContentLoaded ---
|
||||||
@ -170,16 +188,13 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
await new Promise(resolve => setTimeout(resolve, 50));
|
await new Promise(resolve => setTimeout(resolve, 50));
|
||||||
|
|
||||||
// Request the initial BGM enabled state from the background script via extensionStorage
|
// 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') {
|
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.get === 'function') {
|
||||||
try {
|
try {
|
||||||
const bgmEnabled = await window.extensionStorage.get('bgmEnabled');
|
const bgmEnabled = await window.extensionStorage.get('bgmEnabled');
|
||||||
console.log("Initial BGM enabled state from storage:", 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.");
|
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({
|
window.extensionStorage.sendMessageToBackground({
|
||||||
action: "playBGM",
|
action: "playBGM",
|
||||||
bgmUrl: generatedBgmUrl
|
bgmUrl: generatedBgmUrl
|
||||||
@ -198,7 +213,6 @@ runtimeAPI.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
if (request.action === "toggleBGMImmediate") {
|
if (request.action === "toggleBGMImmediate") {
|
||||||
if (request.enabled) {
|
if (request.enabled) {
|
||||||
console.log("Received toggleBGMImmediate from popup: Play BGM.");
|
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') {
|
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.sendMessageToBackground === 'function') {
|
||||||
window.extensionStorage.sendMessageToBackground({
|
window.extensionStorage.sendMessageToBackground({
|
||||||
action: "playBGM",
|
action: "playBGM",
|
||||||
@ -207,7 +221,6 @@ runtimeAPI.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Received toggleBGMImmediate from popup: Stop BGM.");
|
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') {
|
if (typeof window.extensionStorage !== 'undefined' && typeof window.extensionStorage.sendMessageToBackground === 'function') {
|
||||||
window.extensionStorage.sendMessageToBackground({
|
window.extensionStorage.sendMessageToBackground({
|
||||||
action: "stopBGM"
|
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": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": [
|
"matches": [
|
||||||
"https://oss-auth.blinklab.com/*",
|
"https://oss-auth.thecheese.io/*"
|
||||||
"https://oss-auth.thecheese.io/*",
|
|
||||||
"https://oss-auth.shop.wii.com/*",
|
|
||||||
"http://wiimart:8080/oss/serv/*",
|
|
||||||
"https://wiimart:8080/oss/serv/*"
|
|
||||||
],
|
],
|
||||||
"js": ["content.js"],
|
"js": ["content.js"],
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
@ -41,11 +37,7 @@
|
|||||||
"classDefinitions.js"
|
"classDefinitions.js"
|
||||||
],
|
],
|
||||||
"matches": [
|
"matches": [
|
||||||
"https://oss-auth.blinklab.com/*",
|
"https://oss-auth.thecheese.io/*"
|
||||||
"https://oss-auth.thecheese.io/*",
|
|
||||||
"https://oss-auth.shop.wii.com/*",
|
|
||||||
"http://wiimart:8080/oss/serv/*",
|
|
||||||
"https://wiimart:8080/oss/serv/*"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user