Skip to content

Commit

Permalink
Merge pull request #178 from mainIine/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
TH3C0D3R authored Mar 10, 2022
2 parents 48c8144 + fab5aa8 commit 44a8feb
Show file tree
Hide file tree
Showing 3 changed files with 1,434 additions and 1,402 deletions.
36 changes: 28 additions & 8 deletions js/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

// separate code from global scope
{
loadBeta = JSON.parse(localStorage.getItem('LoadBeta')) || false;
localStorage.setItem('LoadBeta', false);
let ScArray=[];
const loadBeta = JSON.parse(localStorage.getItem('LoadBeta')) || false;
localStorage.setItem('LoadBeta', 'false');
if (loadBeta) {
now = new Date();
let now = new Date();
fetch("https://api.github.com/repos/mainIine/foe-helfer-extension/branches/beta?" + now)
.then(response => {if (response.status === 200) {response.json()
.then((data) => {inject(true,
Expand All @@ -33,7 +34,7 @@ function inject (loadBeta = false, extUrl = chrome.extension.getURL(''), betaDat
* @param {string} src the URL to load
* @returns {Promise<void>}
*/
function promisedLoadCode(src) {
function promisedLoadCode(src, append=true) {
return new Promise(async (resolve, reject) => {
let sc = document.createElement('script');
sc.src = src;
Expand All @@ -48,11 +49,25 @@ function inject (loadBeta = false, extUrl = chrome.extension.getURL(''), betaDat
reject();
});

if (append) {
while (!document.head && !document.documentElement) await new Promise((resolve) => {
// @ts-ignore
requestIdleCallback(resolve);
});
(document.head || document.documentElement).appendChild(sc);
} else {
ScArray.push(sc);
resolve();
}
});
}

async function append(sc) {
return await new Promise(async () => {
while (!document.head && !document.documentElement) await new Promise((resolve) => {
// @ts-ignore
requestIdleCallback(resolve);
});

(document.head || document.documentElement).appendChild(sc);
});
}
Expand Down Expand Up @@ -131,7 +146,7 @@ function inject (loadBeta = false, extUrl = chrome.extension.getURL(''), betaDat
}

async function InjectCode(loadBeta, extUrl) {
try {
try {
// set some global variables
let script = document.createElement('script');
script.innerText = `
Expand Down Expand Up @@ -191,12 +206,17 @@ function inject (loadBeta = false, extUrl = chrome.extension.getURL(''), betaDat

// load scripts (one after the other)
const internalScriptsToLoad = await scriptListPromise;

for (let i = 0; i < internalScriptsToLoad.length; i++){
await promisedLoadCode(`${extUrl}js/web/${internalScriptsToLoad[i]}/js/${internalScriptsToLoad[i]}.js?v=${v}`);
await promisedLoadCode(`${extUrl}js/web/${internalScriptsToLoad[i]}/js/${internalScriptsToLoad[i]}.js?v=${v}`, false);
}
for (let sc of ScArray) {
append(sc);
}

window.dispatchEvent(new CustomEvent('foe-helper#loaded'));

localStorage.setItem('LoadBeta', loadBeta);
localStorage.setItem('LoadBeta', JSON.stringify(loadBeta));
} catch (err) {
// make sure that the packet buffer in the FoEproxy does not fill up in the event of an incomplete loading.
window.dispatchEvent(new CustomEvent('foe-helper#error-loading'));
Expand Down
24 changes: 18 additions & 6 deletions js/web/bettermusic/js/bettermusic.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ FoEproxy.addHandler('AnnouncementsService', 'fetchAllAnnouncements', (data, post
if (!betterMusic.playStatus) betterMusic.pause();

betterMusic.buildlists();
betterMusic.initialize(10000);
first = true;


Expand Down Expand Up @@ -127,8 +126,26 @@ FoEproxy.addHandler('FriendsTavernService', 'getConfig', (data, postData) => {

});

$('#game_body').click(function () {
if (!betterMusic.first || $('#betterMusic1').length === 0) return;
betterMusic.first = false;
betterMusic.TrackSelector();
})
$('#game_body').contextmenu(function () {
if (!betterMusic.first || $('#betterMusic1').length === 0) return;
betterMusic.first = false;
betterMusic.TrackSelector();
})
$('#game_body').keydown(function () {
if (!betterMusic.first || $('#betterMusic1').length === 0) return;
betterMusic.first = false;
betterMusic.TrackSelector();
})


let betterMusic = {

first: true,
NextEvent: null,
Ids: [],
currentId: "",
Expand Down Expand Up @@ -468,11 +485,6 @@ let betterMusic = {
betterMusic.buildlists();
},

initialize: (value=10000) => {
//clearTimeout(betterMusic.nextEvent);
betterMusic.nextEvent = setTimeout(function() {betterMusic.TrackSelector()}, value);
},

update (obj/*, …*/) {
for (var i=1; i<arguments.length; i++) {
for (var prop in arguments[i]) {
Expand Down
Loading

0 comments on commit 44a8feb

Please sign in to comment.