fix: theme settings being applied before settings
fixes `TypeError: Settings is undefined` on firefox
This commit is contained in:
parent
35bc026724
commit
456bf389f0
3 changed files with 191 additions and 183 deletions
|
|
@ -4,6 +4,7 @@ var Settings;
|
|||
let Utilities;
|
||||
|
||||
chrome.storage.sync.get(['PolyPlus_Settings'], function (result) {
|
||||
console.log(result);
|
||||
Settings = result.PolyPlus_Settings;
|
||||
|
||||
if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
const SettingsURL = chrome.runtime.getURL('settings.html');
|
||||
const InExtensionSettings = window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash !== '#dev' && window.location.hash !== '#debug';
|
||||
|
||||
if (InExtensionSettings === true) {
|
||||
window.location.href = SettingsURL + window.location.hash;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
var Settings;
|
||||
let Theme = ``;
|
||||
|
||||
(async () => {
|
||||
let Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
||||
Utilities = Utilities.default;
|
||||
|
|
@ -9,6 +10,12 @@ let Theme = ``;
|
|||
const RawSettings = result.PolyPlus_Settings;
|
||||
Settings = MergeObjects(RawSettings || Utilities.DefaultSettings, Utilities.DefaultSettings);
|
||||
|
||||
// Apply theme settings after Settings is defined
|
||||
applyThemeSettings();
|
||||
});
|
||||
})();
|
||||
|
||||
function applyThemeSettings() {
|
||||
// If theme exists, create a style element to represent it
|
||||
if (Settings.ThemeCreator && Settings.ThemeCreator.Enabled === true) {
|
||||
switch (Settings.ThemeCreator.BGImageSize) {
|
||||
|
|
@ -110,12 +117,11 @@ let Theme = ``;
|
|||
}
|
||||
`;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const combination = "reload";
|
||||
let currentCombination = "";
|
||||
document.addEventListener("keypress", function(e) {
|
||||
document.addEventListener("keypress", function (e) {
|
||||
currentCombination += e.key;
|
||||
if (currentCombination === combination && document.activeElement.tagName !== "INPUT") {
|
||||
console.log("Reloading Poly+...");
|
||||
|
|
@ -153,7 +159,7 @@ let Theme = ``;
|
|||
}
|
||||
|
||||
// Credit to @SK-Fast (also known as DevPixels) for the improved loading code (taken from his original Poly+, and reformatted to Index Poly+)
|
||||
const ThemeBlob = new Blob([Theme], {type: 'text/css'});
|
||||
const ThemeBlob = new Blob([Theme], { type: 'text/css' });
|
||||
const ThemeURL = URL.createObjectURL(ThemeBlob);
|
||||
document.head.innerHTML += `<link href="${ThemeURL}" rel="stylesheet" type="text/css">`;
|
||||
|
||||
|
|
@ -201,7 +207,7 @@ let Theme = ``;
|
|||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
function MergeObjects(obj1, obj2) {
|
||||
var mergedObj = {};
|
||||
|
|
|
|||
Reference in a new issue