Merge pull request #9 from okdargy/main
fix settings being undefined on change load
This commit is contained in:
commit
c0dbbdeb0d
2 changed files with 190 additions and 183 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
const SettingsURL = chrome.runtime.getURL('settings.html');
|
const SettingsURL = chrome.runtime.getURL('settings.html');
|
||||||
const InExtensionSettings = window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash !== '#dev' && window.location.hash !== '#debug';
|
const InExtensionSettings = window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash !== '#dev' && window.location.hash !== '#debug';
|
||||||
|
|
||||||
if (InExtensionSettings === true) {
|
if (InExtensionSettings === true) {
|
||||||
window.location.href = SettingsURL + window.location.hash;
|
window.location.href = SettingsURL + window.location.hash;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
var Settings;
|
var Settings;
|
||||||
let Theme = ``;
|
let Theme = ``;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
let Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
let Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
||||||
Utilities = Utilities.default;
|
Utilities = Utilities.default;
|
||||||
|
|
@ -9,6 +10,12 @@ let Theme = ``;
|
||||||
const RawSettings = result.PolyPlus_Settings;
|
const RawSettings = result.PolyPlus_Settings;
|
||||||
Settings = MergeObjects(RawSettings || Utilities.DefaultSettings, Utilities.DefaultSettings);
|
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 theme exists, create a style element to represent it
|
||||||
if (Settings.ThemeCreator && Settings.ThemeCreator.Enabled === true) {
|
if (Settings.ThemeCreator && Settings.ThemeCreator.Enabled === true) {
|
||||||
switch (Settings.ThemeCreator.BGImageSize) {
|
switch (Settings.ThemeCreator.BGImageSize) {
|
||||||
|
|
@ -110,11 +117,10 @@ let Theme = ``;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const combination = "reload";
|
const combination = "reload";
|
||||||
let currentCombination = "";
|
let currentCombination = "";
|
||||||
document.addEventListener("keypress", function(e) {
|
document.addEventListener("keypress", function (e) {
|
||||||
currentCombination += e.key;
|
currentCombination += e.key;
|
||||||
if (currentCombination === combination && document.activeElement.tagName !== "INPUT" && document.activeElement.tagName !== "TEXTAREA") {
|
if (currentCombination === combination && document.activeElement.tagName !== "INPUT" && document.activeElement.tagName !== "TEXTAREA") {
|
||||||
console.log("Reloading Poly+...");
|
console.log("Reloading Poly+...");
|
||||||
|
|
@ -152,7 +158,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+)
|
// 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);
|
const ThemeURL = URL.createObjectURL(ThemeBlob);
|
||||||
document.head.innerHTML += `<link href="${ThemeURL}" rel="stylesheet" type="text/css">`;
|
document.head.innerHTML += `<link href="${ThemeURL}" rel="stylesheet" type="text/css">`;
|
||||||
|
|
||||||
|
|
@ -200,7 +206,7 @@ let Theme = ``;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
}
|
||||||
|
|
||||||
function MergeObjects(obj1, obj2) {
|
function MergeObjects(obj1, obj2) {
|
||||||
var mergedObj = {};
|
var mergedObj = {};
|
||||||
|
|
|
||||||
Reference in a new issue