Merge branch 'indexxing:main' into main
This commit is contained in:
commit
d25b2f97c2
5 changed files with 418 additions and 858 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": ["https://polytoria.com/*"],
|
"matches": ["https://polytoria.com/*"],
|
||||||
"js": ["/js/everywhere.js","/js/membership-themes.js"],
|
"js": ["/js/sitewide.js","/js/membership-themes.js"],
|
||||||
"css": ["/css/specific.css"],
|
"css": ["/css/specific.css"],
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -687,6 +687,6 @@
|
||||||
made by <a href="https://polytoria.com/u/Index" target="_blank">Index</a> with the help of several contributors <3
|
made by <a href="https://polytoria.com/u/Index" target="_blank">Index</a> with the help of several contributors <3
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<script src="settings2.js"></script>
|
<script src="settings.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
855
settings.js
Executable file → Normal file
855
settings.js
Executable file → Normal file
|
|
@ -1,440 +1,417 @@
|
||||||
const SaveBtn = document.getElementById('Save')
|
const SaveBtn = document.getElementById('Save')
|
||||||
const Elements = Array.from(document.getElementsByClassName('setting-container'))
|
const Elements = Array.from(document.getElementsByClassName('setting-container'))
|
||||||
|
|
||||||
var Settings;
|
var Settings;
|
||||||
var ExpectedSettings;
|
|
||||||
|
var Utilities;
|
||||||
var Utilities;
|
(async () => {
|
||||||
(async () => {
|
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
||||||
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
Utilities = Utilities.default
|
||||||
Utilities = Utilities.default
|
LoadCurrent()
|
||||||
|
|
||||||
ExpectedSettings = Utilities.DefaultSettings
|
document.getElementById('PinnedGames-limit').innerText = Utilities.Limits.PinnedGames
|
||||||
LoadCurrent()
|
document.getElementById('BestFriends-limit').innerText = Utilities.Limits.BestFriends
|
||||||
|
document.getElementById('ImprovedFrLists-limit').innerText = Utilities.Limits.ImprovedFrLists
|
||||||
document.getElementById('PinnedGames-limit').innerText = Utilities.Limits.PinnedGames
|
document.getElementById('ItemWishlist-limit').innerText = Utilities.Limits.ItemWishlist
|
||||||
document.getElementById('BestFriends-limit').innerText = Utilities.Limits.BestFriends
|
})();
|
||||||
document.getElementById('ImprovedFrLists-limit').innerText = Utilities.Limits.ImprovedFrLists
|
|
||||||
document.getElementById('ItemWishlist-limit').innerText = Utilities.Limits.ItemWishlist
|
// Handle buttons at the bottom of the page
|
||||||
})();
|
document.getElementById('ResetDefaults').addEventListener('click', function() {
|
||||||
|
document.getElementById('ResetDefaults-Modal').showModal();
|
||||||
// Handle buttons at the bottom of the page
|
});
|
||||||
document.getElementById('ResetDefaults').addEventListener('click', function() {
|
SaveBtn.addEventListener("click", function() {
|
||||||
document.getElementById('ResetDefaults-Modal').showModal();
|
Save();
|
||||||
});
|
});
|
||||||
SaveBtn.addEventListener("click", function() {
|
|
||||||
Save();
|
// Handle modal buttons for Reset Defaults modal
|
||||||
});
|
document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function() {
|
||||||
|
Settings = Utilities.DefaultSettings
|
||||||
// Handle modal buttons for Reset Defaults modal
|
Save()
|
||||||
document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function() {
|
setTimeout(function () {
|
||||||
Settings = ExpectedSettings
|
LoadCurrent();
|
||||||
Save()
|
document.getElementById('ResetDefaults-Modal').close();
|
||||||
setTimeout(function () {
|
}, 400)
|
||||||
LoadCurrent();
|
});
|
||||||
document.getElementById('ResetDefaults-Modal').close();
|
document.getElementById('ResetDefaults-Modal-No').addEventListener('click', function() {
|
||||||
}, 400)
|
document.getElementById('ResetDefaults-Modal').close();
|
||||||
});
|
});
|
||||||
document.getElementById('ResetDefaults-Modal-No').addEventListener('click', function() {
|
|
||||||
document.getElementById('ResetDefaults-Modal').close();
|
// Handle leaving the settings page before saving
|
||||||
});
|
window.onbeforeunload = function() {
|
||||||
|
if (SaveBtn.getAttribute('disabled') !== undefined) {
|
||||||
// Handle leaving the settings page before saving
|
return "Are you sure you'd like to leave? Your Poly+ settings haven't been saved."
|
||||||
/*
|
}
|
||||||
window.onbeforeunload = function() {
|
}
|
||||||
if (SaveBtn.getAttribute('disabled') !== null) {
|
|
||||||
return "Are you sure you'd like to leave? Your Poly+ settings haven't been saved."
|
// Loop thru each setting container and handle toggling, selecting, opening modal, etc
|
||||||
}
|
Elements.forEach(element => {
|
||||||
return "aaa"
|
console.log('Handle Element', element)
|
||||||
}
|
let Button = element.getElementsByTagName('button')[0]
|
||||||
*/
|
let Options = element.getElementsByTagName('button')[1]
|
||||||
|
let Select = element.getElementsByTagName('select')[0]
|
||||||
// Loop thru each setting container and handle toggling, selecting, opening modal, etc
|
let Checkbox = element.getElementsByTagName('input')[0]
|
||||||
Elements.forEach(element => {
|
|
||||||
let Button = element.getElementsByTagName('button')[0]
|
if (Button) {
|
||||||
let Options = element.getElementsByTagName('button')[1]
|
Button.addEventListener('click', function() {
|
||||||
let Select = element.getElementsByTagName('select') || []
|
SetSetting(Button, "bool")
|
||||||
//let Checkbox = element.getElementsByTagName('input') || []
|
});
|
||||||
//console.log(Checkbox)
|
}
|
||||||
|
|
||||||
if (Button) {
|
if (Select) {
|
||||||
Button.addEventListener('click', function() {
|
Select.addEventListener('change', function(){
|
||||||
ToggleSetting(Button.getAttribute('data-setting'), element)
|
if (Select.getAttribute('data-useValue') !== undefined) {
|
||||||
|
let Value = Select.options[Select.selectedIndex].value
|
||||||
/*
|
if (!isNaN(Value)) { Value = parseInt(Value) }
|
||||||
if (!(Button.getAttribute('data-parent'))) {
|
SetSetting(Select, Value, false)
|
||||||
ToggleSetting(Button.getAttribute('data-setting'), element)
|
} else {
|
||||||
} else {
|
SetSetting(Select, Select.selectedIndex, false)
|
||||||
let Parent = Button.getAttribute('data-parent')
|
}
|
||||||
if (!isNaN(parseInt(Parent))) {
|
})
|
||||||
Parent = parseInt(Parent)
|
}
|
||||||
}
|
|
||||||
|
if (Checkbox) {
|
||||||
if (!Settings[Parent]) {
|
Checkbox.addEventListener('change', function(){
|
||||||
Settings[Parent] = {}
|
SetSetting(Checkbox, Checkbox.checked, false)
|
||||||
console.log('empty btn')
|
})
|
||||||
}
|
}
|
||||||
console.log(Button.getAttribute('data-setting'), Parent, Settings[Parent])
|
|
||||||
ToggleSetting(Button.getAttribute('data-setting'), element, Parent)
|
if (Options) {
|
||||||
}
|
const Modal = document.getElementById(Options.getAttribute('data-modal') + '-Modal')
|
||||||
*/
|
const ModalButtons = Modal.getElementsByTagName('button')
|
||||||
});
|
const ModalInputs = Modal.getElementsByTagName('input')
|
||||||
}
|
const ModalSelect = Modal.getElementsByTagName('select')
|
||||||
|
|
||||||
/*
|
Options.addEventListener('click', function(){
|
||||||
Array.from(Checkbox).forEach(check => {
|
Array.from(ModalButtons).filter((x) => !x.classList.contains('ignore')).forEach(button => {
|
||||||
check.addEventListener('click', function(){
|
button.addEventListener('click', function(){
|
||||||
if (!(check.getAttribute('data-parent'))) {
|
const Setting = button.getAttribute('data-setting')
|
||||||
ToggleSetting(check.getAttribute('data-setting'), element)
|
|
||||||
} else {
|
if (Setting === '[save]') {
|
||||||
let Parent = check.getAttribute('data-parent')
|
// Save Modal Button
|
||||||
if (!isNaN(parseInt(Parent))) {
|
|
||||||
Parent = parseInt(Parent)
|
Array.from(ModalInputs).filter((x) => !x.classList.contains('ignore')).forEach(input => {
|
||||||
}
|
SetSetting(input, input.value, false, Modal.getAttribute('data-setting'))
|
||||||
|
});
|
||||||
if (!Settings[Parent]) {
|
Array.from(ModalSelect).filter((x) => !x.classList.contains('ignore')).forEach(select => {
|
||||||
Settings[Parent] = {}
|
SetSetting(select, select.selectedIndex, false, Modal.getAttribute('data-setting'))
|
||||||
console.log('empty')
|
});
|
||||||
}
|
Save();
|
||||||
|
setTimeout(function () {
|
||||||
console.log(check.getAttribute('data-setting'), Parent, Settings[Parent])
|
LoadCurrent();
|
||||||
ToggleSetting(check.getAttribute('data-setting'), null, Parent)
|
Modal.close();
|
||||||
}
|
}, 400)
|
||||||
})
|
} else if (Setting === '[reset-default]') {
|
||||||
})
|
// Reset to Defaults Modal Button
|
||||||
*/
|
|
||||||
|
if (confirm("Are you sure you'd like to reset these options to their defaults?") === true) {
|
||||||
if (Options) {
|
Settings[Modal.getAttribute('data-setting')] = Utilities.DefaultSettings[Modal.getAttribute('data-setting')]
|
||||||
Options.addEventListener('click', function() {
|
Save()
|
||||||
let Modal = document.getElementById(Options.getAttribute('data-modal') + '-Modal')
|
Modal.close();
|
||||||
let ModalButtons = Modal.getElementsByTagName('button')
|
}
|
||||||
let ModalInputs = Modal.getElementsByTagName('input')
|
} else if (Setting === '[cancel]') {
|
||||||
let ModalSelect = Modal.getElementsByTagName('select')
|
// Cancel Changes Button
|
||||||
|
|
||||||
Array.from(ModalButtons).forEach(btn => {
|
Modal.close();
|
||||||
if (!(btn.getAttribute('data-ignore') === 'true')) {
|
} else {
|
||||||
btn.addEventListener('click', function(){
|
// Default Toggle Button
|
||||||
let Setting = btn.getAttribute('data-setting')
|
|
||||||
if (Setting === '[save]') {
|
SetSetting(button, "bool", false, Modal.getAttribute('data-setting'))
|
||||||
Array.from(ModalInputs).forEach(input => {
|
}
|
||||||
if (!(input.getAttribute('data-ignore') === 'true')) {
|
})
|
||||||
if (!(input.getAttribute('data-parent'))) {
|
})
|
||||||
Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] = input.value || null
|
|
||||||
} else {
|
Array.from(ModalInputs).filter((x) => !x.classList.contains('ignore')).forEach(input => {
|
||||||
let Parent = input.getAttribute('data-parent')
|
const Status = GetSettingValue(input, Modal.getAttribute('data-setting'))
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
if (Status !== "undefined" && Status !== undefined) {
|
||||||
Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] = input.value || null
|
input.value = Status
|
||||||
}
|
} else {
|
||||||
}
|
input.value = ''
|
||||||
});
|
}
|
||||||
Array.from(ModalSelect).forEach(select => {
|
});
|
||||||
if (!(select.getAttribute('data-ignore') === 'true')) {
|
|
||||||
if (!(select.getAttribute('data-parent'))) {
|
Array.from(ModalSelect).filter((x) => !x.classList.contains('ignore')).forEach(select => {
|
||||||
Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] = select.selectedIndex
|
const Status = GetSettingValue(select, Modal.getAttribute('data-setting'))
|
||||||
} else {
|
if (Status !== "undefined" && Status !== undefined) {
|
||||||
let Parent = input.getAttribute('data-parent')
|
select.selectedIndex = Status
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
}
|
||||||
Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] = select.selectedIndex
|
});
|
||||||
}
|
|
||||||
}
|
Modal.showModal()
|
||||||
});
|
})
|
||||||
Save();
|
}
|
||||||
setTimeout(function () {
|
});
|
||||||
LoadCurrent();
|
|
||||||
Modal.close();
|
function LoadCurrent() {
|
||||||
}, 400)
|
chrome.storage.sync.get(["PolyPlus_Settings"], function(result) {
|
||||||
} else if (Setting === '[reset-default]') {
|
Settings = MergeObjects(result.PolyPlus_Settings || Utilities.DefaultSettings, Utilities.DefaultSettings)
|
||||||
if (confirm("Are you sure you'd like to reset these options to their defaults?") === true) {
|
|
||||||
Settings[Modal.getAttribute('data-setting')] = ExpectedSettings[Modal.getAttribute('data-setting')]
|
console.log("Current Settings: ", Settings)
|
||||||
Save()
|
|
||||||
Modal.close();
|
Elements.forEach(element => {
|
||||||
}
|
console.log('For Each Update')
|
||||||
} else if (Setting === '[cancel]') {
|
UpdateElementState(element)
|
||||||
Modal.close();
|
});
|
||||||
} else {
|
});
|
||||||
if (!(btn.getAttribute('data-parent'))) {
|
}
|
||||||
ToggleSetting(Modal.getAttribute('data-setting')[btn.getAttribute('data-setting')], null)
|
|
||||||
} else {
|
function SetSetting(element, value, update, modalParent) {
|
||||||
let Parent = input.getAttribute('data-parent')
|
const name = element.getAttribute('data-setting')
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
let parent = element.getAttribute('data-parent')
|
||||||
ToggleSetting(Modal.getAttribute('data-setting')[Parent][btn.getAttribute('data-setting')], null)
|
|
||||||
}
|
if (modalParent !== undefined) {
|
||||||
}
|
console.log(modalParent)
|
||||||
});
|
parent = modalParent
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
if (value === "bool") {
|
||||||
Array.from(ModalInputs).forEach(input => {
|
value = !GetSettingValue(element, modalParent)
|
||||||
if (!(input.getAttribute('data-ignore') === 'true')) {
|
}
|
||||||
if (!(input.getAttribute('data-parent'))) {
|
if (parent !== null) {
|
||||||
if (Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] !== "undefined" && Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] !== undefined) {
|
let Parent = Object.values(Settings)[Object.keys(Settings).indexOf(parent)]
|
||||||
input.value = Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')]
|
if (!isNaN(element.getAttribute('data-parent')) && element.getAttribute('data-parent') !== null) {
|
||||||
} else {
|
console.log('is numbere!!!!')
|
||||||
input.value = ''
|
Parent = Parent[parseInt(element.getAttribute('data-parent'))]
|
||||||
}
|
}
|
||||||
} else {
|
Parent[name] = value
|
||||||
let Parent = input.getAttribute('data-parent')
|
} else {
|
||||||
if (Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] !== "undefined" && Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] !== undefined) {
|
Settings[name] = value
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
}
|
||||||
input.value = Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')]
|
if (update !== false) {
|
||||||
} else {
|
UpdateElementState(document.querySelector(`.setting-container:has([data-setting="${name}"])${ (parent !== null) ? `:has([data-parent="${parent}"])` : '' }`), value)
|
||||||
input.value = ''
|
}
|
||||||
}
|
if (SaveBtn.getAttribute('disabled')) {
|
||||||
}
|
SaveBtn.removeAttribute('disabled')
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
const getInObject = function(a, b) { return Object.values(a)[Object.keys(a).indexOf(b)] }
|
||||||
Array.from(ModalSelect).forEach(select => {
|
}
|
||||||
if (!(select.getAttribute('data-ignore') === 'true')) {
|
|
||||||
if (!(select.getAttribute('data-parent'))) {
|
function GetSettingValue(element, modalParent) {
|
||||||
if (Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] !== "undefined") {
|
const name = element.getAttribute('data-setting')
|
||||||
select.selectedIndex = Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')]
|
let parent = element.getAttribute('data-parent')
|
||||||
}
|
|
||||||
} else {
|
if (modalParent !== undefined) {
|
||||||
let Parent = input.getAttribute('data-parent')
|
parent = modalParent
|
||||||
if (Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] !== "undefined") {
|
}
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
|
||||||
select.selectedIndex = Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')]
|
let Status = name;
|
||||||
}
|
if (parent !== null) {
|
||||||
}
|
|
||||||
}
|
let Parent = Object.values(Settings)[Object.keys(Settings).indexOf(parent)]
|
||||||
});
|
if (!isNaN(element.getAttribute('data-parent')) && element.getAttribute('data-parent') !== null) {
|
||||||
|
Parent = Parent[parseInt(element.getAttribute('data-parent'))]
|
||||||
Modal.showModal()
|
Status = Parent[name]
|
||||||
});
|
} else {
|
||||||
}
|
Status = Object.values(Parent)[Object.keys(Parent).indexOf(name)]
|
||||||
|
}
|
||||||
if (Select.length > 0) {
|
|
||||||
Array.from(Select).forEach(element => {
|
/*
|
||||||
element.addEventListener('change', function() {
|
if (!isNaN(element.getAttribute('data-parent'))) {
|
||||||
SetSetting(element.getAttribute('data-setting'), element, element.selectedIndex)
|
Parent = Parent[parseInt(element.getAttribute('data-parent'))]
|
||||||
Save()
|
}
|
||||||
});
|
Status = Object.values(Parent)[Object.keys(Parent).indexOf(Status)]
|
||||||
});
|
*/
|
||||||
}
|
} else {
|
||||||
});
|
Status = Settings[Status]
|
||||||
|
}
|
||||||
function LoadCurrent() {
|
console.log('Get Value Result', Status)
|
||||||
chrome.storage.sync.get(["PolyPlus_Settings"], function(result) {
|
|
||||||
Settings = MergeObjects(result.PolyPlus_Settings || ExpectedSettings, ExpectedSettings)
|
return Status
|
||||||
|
}
|
||||||
console.log("Current: ", Settings)
|
|
||||||
|
function UpdateElementState(element, status) {
|
||||||
Elements.forEach(element => {
|
console.log('Update Element State', element, status)
|
||||||
const ToggleBtn = element.getElementsByClassName('toggle-btn')[0]
|
|
||||||
if (Settings[ToggleBtn.getAttribute('data-setting')] === true) {
|
const Button = element.getElementsByClassName('toggle-btn')[0]
|
||||||
element.classList.add('enabled')
|
|
||||||
ToggleBtn.innerText = 'Disable'
|
if (status === undefined) {
|
||||||
ToggleBtn.classList.add('btn-danger')
|
console.log('Update Element State, no status provided')
|
||||||
} else {
|
status = GetSettingValue(Button)
|
||||||
element.classList.add('disabled')
|
}
|
||||||
ToggleBtn.innerText = 'Enable'
|
|
||||||
ToggleBtn.classList.add('btn-success')
|
if (status === true) {
|
||||||
}
|
console.log('Is Enabled so Set False')
|
||||||
let SelectInput = element.getElementsByTagName('select')[0]
|
element.classList.add('enabled')
|
||||||
if (SelectInput) {
|
element.classList.remove('disabled')
|
||||||
SelectInput.selectedIndex = Settings[SelectInput.getAttribute('data-setting')]
|
Button.innerText = 'Disable'
|
||||||
}
|
Button.classList.add('btn-danger')
|
||||||
});
|
Button.classList.remove('btn-success')
|
||||||
});
|
} else {
|
||||||
}
|
console.log('Is Disabled so Set True')
|
||||||
|
element.classList.add('disabled')
|
||||||
function ToggleSetting(Name, Element, Parent) {
|
element.classList.remove('enabled')
|
||||||
document.title = "*unsaved | Poly+ Settings"
|
Button.innerText = 'Enable'
|
||||||
let Status;
|
Button.classList.add('btn-success')
|
||||||
if (!Parent) {
|
Button.classList.remove('btn-danger')
|
||||||
Status = Settings[Name]
|
}
|
||||||
if (Settings[Name] === true) {
|
|
||||||
Settings[Name] = false;
|
let SelectInput = element.getElementsByTagName('select')[0]
|
||||||
} else {
|
if (SelectInput) {
|
||||||
Settings[Name] = true;
|
console.log('Select Found')
|
||||||
}
|
SelectInput.selectedIndex = GetSettingValue(SelectInput)
|
||||||
} else {
|
}
|
||||||
Status = Settings[Parent][Name]
|
|
||||||
if (Settings[Parent][Name] === true) {
|
let Checkbox = Array.from(element.getElementsByTagName('input'))
|
||||||
Settings[Parent][Name] = false;
|
if (Checkbox.length > 0) {
|
||||||
} else {
|
console.log('Checkbox/Input(s) Found', Checkbox)
|
||||||
Settings[Parent][Name] = true;
|
Checkbox.forEach(check => {
|
||||||
}
|
console.log('check', GetSettingValue(check))
|
||||||
}
|
check.checked = GetSettingValue(check)
|
||||||
if (Element !== null) {
|
})
|
||||||
const ToggleBtn = Element.getElementsByClassName('toggle-btn')[0]
|
}
|
||||||
if (Status === false) {
|
}
|
||||||
ToggleBtn.innerText = 'Enable'
|
|
||||||
} else {
|
function Save() {
|
||||||
ToggleBtn.innerText = 'Disable'
|
document.title = 'Poly+ Settings'
|
||||||
}
|
SaveBtn.setAttribute('disabled', 'true')
|
||||||
Element.classList.toggle('enabled')
|
chrome.storage.sync.set({ 'PolyPlus_Settings': Settings, arrayOrder: true }, function() {
|
||||||
Element.classList.toggle('disabled')
|
console.log('Saved successfully!');
|
||||||
ToggleBtn.classList.toggle('btn-success')
|
});
|
||||||
ToggleBtn.classList.toggle('btn-danger')
|
|
||||||
}
|
console.log("Save:", Settings);
|
||||||
|
}
|
||||||
if (SaveBtn.getAttribute('disabled')) {
|
|
||||||
SaveBtn.removeAttribute('disabled')
|
let LoadThemeFromJSONBtn = document.getElementById('LoadThemeFromJSONBtn')
|
||||||
}
|
let SaveThemeToJSONInput = document.getElementById('SaveThemeToJSONInput')
|
||||||
}
|
let CopyThemeJSONBtn = document.getElementById('CopyThemeJSONBtn')
|
||||||
|
LoadThemeFromJSONBtn.addEventListener('click', function(){
|
||||||
function SetSetting(Name, Element, Value) {
|
LoadThemeJSON(LoadThemeFromJSONBtn.previousElementSibling.value)
|
||||||
console.log(Settings)
|
});
|
||||||
Settings[Name] = Value
|
document.getElementById('theme-creator').getElementsByTagName('button')[1].addEventListener('click', function(){
|
||||||
|
SaveThemeToJSONInput.value = JSON.stringify(Settings.ThemeCreator)
|
||||||
if (SaveBtn.getAttribute('disabled')) {
|
});
|
||||||
SaveBtn.removeAttribute('disabled')
|
CopyThemeJSONBtn.addEventListener('click', function(){
|
||||||
}
|
if (SaveThemeToJSONInput.value.length > 0) {
|
||||||
}
|
navigator.clipboard.writeText(SaveThemeToJSONInput.value)
|
||||||
|
.then(() => {
|
||||||
function Save() {
|
alert('Successfully copied theme data to clipboard!')
|
||||||
document.title = 'Poly+ Settings'
|
})
|
||||||
SaveBtn.setAttribute('disabled', 'true')
|
.catch(() => {
|
||||||
chrome.storage.sync.set({ 'PolyPlus_Settings': Settings, arrayOrder: true }, function() {
|
alert('Failure to copy theme data to clipboard.')
|
||||||
console.log('Saved successfully!');
|
});
|
||||||
});
|
}
|
||||||
|
});
|
||||||
console.log("Save:", Settings);
|
|
||||||
}
|
function LoadThemeJSON(string) {
|
||||||
|
try {
|
||||||
let LoadThemeFromJSONBtn = document.getElementById('LoadThemeFromJSONBtn')
|
let JSONTable = JSON.parse(string)
|
||||||
let SaveThemeToJSONInput = document.getElementById('SaveThemeToJSONInput')
|
if (JSONTable.length === Utilities.DefaultSettings.ThemeCreator.length) {
|
||||||
let CopyThemeJSONBtn = document.getElementById('CopyThemeJSONBtn')
|
if (confirm('Are you sure you\'d like to replace this theme with the theme specified in the JSON?') === true) {
|
||||||
LoadThemeFromJSONBtn.addEventListener('click', function(){
|
LoadThemeFromJSONBtn.previousElementSibling.value = ''
|
||||||
LoadThemeJSON(LoadThemeFromJSONBtn.previousElementSibling.value)
|
document.getElementById('ThemeCreator-Modal').close()
|
||||||
});
|
for (let i = 0; i < JSONTable.length; i++) {
|
||||||
document.getElementById('theme-creator').getElementsByTagName('button')[1].addEventListener('click', function(){
|
if (JSONTable[i][0] !== "#") {
|
||||||
SaveThemeToJSONInput.value = JSON.stringify(Settings.ThemeCreator)
|
JSONTable[i] = ""
|
||||||
});
|
}
|
||||||
CopyThemeJSONBtn.addEventListener('click', function(){
|
}
|
||||||
if (SaveThemeToJSONInput.value.length > 0) {
|
Settings.ThemeCreator = MergeObjects(JSONTable, Utilities.DefaultSettings.ThemeCreator)
|
||||||
navigator.clipboard.writeText(SaveThemeToJSONInput.value)
|
Save();
|
||||||
.then(() => {
|
console.log(JSONTable.length, JSONTable, 'applied')
|
||||||
alert('Successfully copied theme data to clipboard!')
|
document.getElementById('ThemeCreator').getElementsByTagName('button')[1].click();
|
||||||
})
|
}
|
||||||
.catch(() => {
|
} else {
|
||||||
alert('Failure to copy theme data to clipboard.')
|
alert('JSON is not a theme!')
|
||||||
});
|
}
|
||||||
}
|
} catch (error) {
|
||||||
});
|
alert('JSON is invalid!')
|
||||||
|
}
|
||||||
function LoadThemeJSON(string) {
|
}
|
||||||
try {
|
|
||||||
let JSONTable = JSON.parse(string)
|
// MergeObjects function was written by ChatGPT cause I was lazy and it was awhile ago
|
||||||
if (JSONTable.length === ExpectedSettings.ThemeCreator.length) {
|
function MergeObjects(obj1, obj2) {
|
||||||
if (confirm('Are you sure you\'d like to replace this theme with the theme specified in the JSON?') === true) {
|
var mergedObj = {};
|
||||||
LoadThemeFromJSONBtn.previousElementSibling.value = ''
|
|
||||||
document.getElementById('ThemeCreator-Modal').close()
|
// Copy the values from obj1 to the mergedObj
|
||||||
for (let i = 0; i < JSONTable.length; i++) {
|
for (var key in obj1) {
|
||||||
if (JSONTable[i][0] !== "#") {
|
mergedObj[key] = obj1[key];
|
||||||
JSONTable[i] = ""
|
}
|
||||||
}
|
|
||||||
}
|
// Merge the values from obj2 into the mergedObj, favoring obj2 for non-existing keys in obj1
|
||||||
Settings.ThemeCreator = MergeObjects(JSONTable, ExpectedSettings.ThemeCreator)
|
for (var key in obj2) {
|
||||||
Save();
|
if (!obj1.hasOwnProperty(key)) {
|
||||||
console.log(JSONTable.length, JSONTable, 'applied')
|
mergedObj[key] = obj2[key];
|
||||||
document.getElementById('ThemeCreator').getElementsByTagName('button')[1].click();
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
alert('JSON is not a theme!')
|
return mergedObj;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
alert('JSON is invalid!')
|
function FormatBool(bool){
|
||||||
}
|
if (bool === true) { return 'enabled' }
|
||||||
}
|
else { return 'disabled' }
|
||||||
|
}
|
||||||
// MergeObjects function was written by ChatGPT cause I was lazy and it was awhile ago
|
|
||||||
function MergeObjects(obj1, obj2) {
|
const Manifest = chrome.runtime.getManifest()
|
||||||
var mergedObj = {};
|
let BuildType = "Stable"
|
||||||
|
if (Manifest.version_name !== undefined) {BuildType = "Pre-Release"}
|
||||||
// Copy the values from obj1 to the mergedObj
|
|
||||||
for (var key in obj1) {
|
const FooterText = document.getElementById('footer-text')
|
||||||
mergedObj[key] = obj1[key];
|
FooterText.children[0].innerHTML = `Version: v${Manifest.version} | Build Type: ${BuildType}`
|
||||||
}
|
|
||||||
|
const CheckForUpdatesButton = document.getElementById('check-for-updates')
|
||||||
// Merge the values from obj2 into the mergedObj, favoring obj2 for non-existing keys in obj1
|
function CheckForUpdates() {
|
||||||
for (var key in obj2) {
|
CheckForUpdatesButton.removeEventListener('click', CheckForUpdates)
|
||||||
if (!obj1.hasOwnProperty(key)) {
|
CheckForUpdatesButton.disabled = true
|
||||||
mergedObj[key] = obj2[key];
|
fetch('https://polyplus.vercel.app/data/version.json')
|
||||||
}
|
.then(response => {
|
||||||
}
|
if (!response.ok) {
|
||||||
|
throw new Error('Network not ok')
|
||||||
return mergedObj;
|
}
|
||||||
}
|
return response.json()
|
||||||
|
})
|
||||||
function FormatBool(bool){
|
.then(data => {
|
||||||
if (bool === true) { return 'enabled' }
|
if (data.version === Manifest.version || Math.floor((data.version - Manifest.version) * 10) === 0) {
|
||||||
else { return 'disabled' }
|
CheckForUpdatesButton.innerHTML = '<b>No updates available</b>'
|
||||||
}
|
alert('No updates available')
|
||||||
|
} else {
|
||||||
const Manifest = chrome.runtime.getManifest()
|
const NumberOfUpdatesAvailable = Math.floor((data.version - Version) * 10)
|
||||||
let BuildType = "Stable"
|
CheckForUpdatesButton.innerHTML = '<b>'+NumberOfUpdatesAvailable+' update(s) available</b>'
|
||||||
if (Manifest.version_name !== undefined) {BuildType = "Pre-Release"}
|
alert(NumberOfUpdatesAvailable + ' updates available')
|
||||||
|
}
|
||||||
const FooterText = document.getElementById('footer-text')
|
})
|
||||||
FooterText.children[0].innerHTML = `Version: v${Manifest.version} | Build Type: ${BuildType}`
|
.catch(error => {console.log(error)});
|
||||||
|
}
|
||||||
const CheckForUpdatesButton = document.getElementById('check-for-updates')
|
CheckForUpdatesButton.addEventListener('click', CheckForUpdates)
|
||||||
function CheckForUpdates() {
|
|
||||||
CheckForUpdatesButton.removeEventListener('click', CheckForUpdates)
|
fetch(chrome.runtime.getURL('resources/currencies.json'))
|
||||||
CheckForUpdatesButton.disabled = true
|
.then(response => {
|
||||||
fetch('https://polyplus.vercel.app/data/version.json')
|
if (!response.ok) {
|
||||||
.then(response => {
|
throw new Error('Network not ok')
|
||||||
if (!response.ok) {
|
}
|
||||||
throw new Error('Network not ok')
|
return response.json()
|
||||||
}
|
})
|
||||||
return response.json()
|
.then(data => {
|
||||||
})
|
const DateText = new Date(data.Date).toLocaleDateString("en-US", {day:"numeric",month:"long",year:"numeric"})
|
||||||
.then(data => {
|
document.getElementById('IRLPriceWithCurrency-Date').innerText = DateText
|
||||||
if (data.version === Manifest.version || Math.floor((data.version - Manifest.version) * 10) === 0) {
|
})
|
||||||
CheckForUpdatesButton.innerHTML = '<b>No updates available</b>'
|
.catch(error => {console.log(error)})
|
||||||
alert('No updates available')
|
|
||||||
} else {
|
chrome.storage.local.get(['PolyPlus_OutOfDate', 'PolyPlus_LiveVersion', 'PolyPlus_ReleaseNotes', 'PolyPlus_SkipUpdate'], function(result) {
|
||||||
const NumberOfUpdatesAvailable = Math.floor((data.version - Version) * 10)
|
const OutOfDate = result.PolyPlus_OutOfDate || false
|
||||||
CheckForUpdatesButton.innerHTML = '<b>'+NumberOfUpdatesAvailable+' update(s) available</b>'
|
const SkipUpdate = result.PolyPlus_SkipUpdate || null
|
||||||
alert(NumberOfUpdatesAvailable + ' updates available')
|
const LiveVersion = result.PolyPlus_LiveVersion || Manifest.version
|
||||||
}
|
if (OutOfDate === true && SkipUpdate !== LiveVersion) {
|
||||||
})
|
const Banner = document.createElement('div')
|
||||||
.catch(error => {console.log(error)});
|
Banner.classList = 'alert position-sticky p-3'
|
||||||
}
|
Banner.style = 'top: 30px; box-shadow: 0 0 20px 2px #000; z-index: 2000; background: rgb(163 39 39);'
|
||||||
CheckForUpdatesButton.addEventListener('click', CheckForUpdates)
|
Banner.innerHTML = `
|
||||||
|
<b>New Update Available!</b>
|
||||||
fetch(chrome.runtime.getURL('resources/currencies.json'))
|
<br>
|
||||||
.then(response => {
|
Your Poly+ installation is out of date! If you would like to get the latest and greatest features, improvements, and bug fixes click on one of the links below to dismiss this banner!
|
||||||
if (!response.ok) {
|
<br>
|
||||||
throw new Error('Network not ok')
|
<div role="group" class="btn-group w-100 mt-2">
|
||||||
}
|
<a href="${result.PolyPlus_ReleaseNotes}" class="btn btn-primary btn-sm w-25" target="_blank">Go to Release Notes</a>
|
||||||
return response.json()
|
<button id="skip-this-update" class="btn btn-warning btn-sm w-25">(Not Recommended) Skip this Update</button>
|
||||||
})
|
</div>
|
||||||
.then(data => {
|
`
|
||||||
const DateText = new Date(data.Date).toLocaleDateString("en-US", {day:"numeric",month:"long",year:"numeric"})
|
document.getElementById('page').insertBefore(Banner, document.getElementById('page').children[1])
|
||||||
document.getElementById('IRLPriceWithCurrency-Date').innerText = DateText
|
|
||||||
})
|
const SkipButton = document.getElementById('skip-this-update')
|
||||||
.catch(error => {console.log(error)})
|
SkipButton.addEventListener('click', function(){
|
||||||
|
Banner.remove()
|
||||||
chrome.storage.local.get(['PolyPlus_OutOfDate', 'PolyPlus_LiveVersion', 'PolyPlus_ReleaseNotes', 'PolyPlus_SkipUpdate'], function(result) {
|
chrome.storage.local.set({'PolyPlus_SkipUpdate': result.PolyPlus_LiveVersion}, function(){
|
||||||
const OutOfDate = result.PolyPlus_OutOfDate || false
|
console.log('set skip update to live version: ', result.PolyPlus_LiveVersion)
|
||||||
const SkipUpdate = result.PolyPlus_SkipUpdate || null
|
})
|
||||||
const LiveVersion = result.PolyPlus_LiveVersion || Manifest.version
|
});
|
||||||
if (OutOfDate === true && SkipUpdate !== LiveVersion) {
|
}
|
||||||
const Banner = document.createElement('div')
|
|
||||||
Banner.classList = 'alert position-sticky p-3'
|
|
||||||
Banner.style = 'top: 30px; box-shadow: 0 0 20px 2px #000; z-index: 2000; background: rgb(163 39 39);'
|
|
||||||
Banner.innerHTML = `
|
|
||||||
<b>New Update Available!</b>
|
|
||||||
<br>
|
|
||||||
Your Poly+ installation is out of date! If you would like to get the latest and greatest features, improvements, and bug fixes click on one of the links below to dismiss this banner!
|
|
||||||
<br>
|
|
||||||
<div role="group" class="btn-group w-100 mt-2">
|
|
||||||
<a href="${result.PolyPlus_ReleaseNotes}" class="btn btn-primary btn-sm w-25" target="_blank">Go to Release Notes</a>
|
|
||||||
<button id="skip-this-update" class="btn btn-warning btn-sm w-25">(Not Recommended) Skip this Update</button>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
document.getElementById('page').insertBefore(Banner, document.getElementById('page').children[1])
|
|
||||||
|
|
||||||
const SkipButton = document.getElementById('skip-this-update')
|
|
||||||
SkipButton.addEventListener('click', function(){
|
|
||||||
Banner.remove()
|
|
||||||
chrome.storage.local.set({'PolyPlus_SkipUpdate': result.PolyPlus_LiveVersion}, function(){
|
|
||||||
console.log('set skip update to live version: ', result.PolyPlus_LiveVersion)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
417
settings2.js
417
settings2.js
|
|
@ -1,417 +0,0 @@
|
||||||
const SaveBtn = document.getElementById('Save')
|
|
||||||
const Elements = Array.from(document.getElementsByClassName('setting-container'))
|
|
||||||
|
|
||||||
var Settings;
|
|
||||||
|
|
||||||
var Utilities;
|
|
||||||
(async () => {
|
|
||||||
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
|
||||||
Utilities = Utilities.default
|
|
||||||
LoadCurrent()
|
|
||||||
|
|
||||||
document.getElementById('PinnedGames-limit').innerText = Utilities.Limits.PinnedGames
|
|
||||||
document.getElementById('BestFriends-limit').innerText = Utilities.Limits.BestFriends
|
|
||||||
document.getElementById('ImprovedFrLists-limit').innerText = Utilities.Limits.ImprovedFrLists
|
|
||||||
document.getElementById('ItemWishlist-limit').innerText = Utilities.Limits.ItemWishlist
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Handle buttons at the bottom of the page
|
|
||||||
document.getElementById('ResetDefaults').addEventListener('click', function() {
|
|
||||||
document.getElementById('ResetDefaults-Modal').showModal();
|
|
||||||
});
|
|
||||||
SaveBtn.addEventListener("click", function() {
|
|
||||||
Save();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle modal buttons for Reset Defaults modal
|
|
||||||
document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function() {
|
|
||||||
Settings = Utilities.DefaultSettings
|
|
||||||
Save()
|
|
||||||
setTimeout(function () {
|
|
||||||
LoadCurrent();
|
|
||||||
document.getElementById('ResetDefaults-Modal').close();
|
|
||||||
}, 400)
|
|
||||||
});
|
|
||||||
document.getElementById('ResetDefaults-Modal-No').addEventListener('click', function() {
|
|
||||||
document.getElementById('ResetDefaults-Modal').close();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle leaving the settings page before saving
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
if (SaveBtn.getAttribute('disabled') !== undefined) {
|
|
||||||
return "Are you sure you'd like to leave? Your Poly+ settings haven't been saved."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop thru each setting container and handle toggling, selecting, opening modal, etc
|
|
||||||
Elements.forEach(element => {
|
|
||||||
console.log('Handle Element', element)
|
|
||||||
let Button = element.getElementsByTagName('button')[0]
|
|
||||||
let Options = element.getElementsByTagName('button')[1]
|
|
||||||
let Select = element.getElementsByTagName('select')[0]
|
|
||||||
let Checkbox = element.getElementsByTagName('input')[0]
|
|
||||||
|
|
||||||
if (Button) {
|
|
||||||
Button.addEventListener('click', function() {
|
|
||||||
SetSetting(Button, "bool")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Select) {
|
|
||||||
Select.addEventListener('change', function(){
|
|
||||||
if (Select.getAttribute('data-useValue') !== undefined) {
|
|
||||||
let Value = Select.options[Select.selectedIndex].value
|
|
||||||
if (!isNaN(Value)) { Value = parseInt(Value) }
|
|
||||||
SetSetting(Select, Value, false)
|
|
||||||
} else {
|
|
||||||
SetSetting(Select, Select.selectedIndex, false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Checkbox) {
|
|
||||||
Checkbox.addEventListener('change', function(){
|
|
||||||
SetSetting(Checkbox, Checkbox.checked, false)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Options) {
|
|
||||||
const Modal = document.getElementById(Options.getAttribute('data-modal') + '-Modal')
|
|
||||||
const ModalButtons = Modal.getElementsByTagName('button')
|
|
||||||
const ModalInputs = Modal.getElementsByTagName('input')
|
|
||||||
const ModalSelect = Modal.getElementsByTagName('select')
|
|
||||||
|
|
||||||
Options.addEventListener('click', function(){
|
|
||||||
Array.from(ModalButtons).filter((x) => !x.classList.contains('ignore')).forEach(button => {
|
|
||||||
button.addEventListener('click', function(){
|
|
||||||
const Setting = button.getAttribute('data-setting')
|
|
||||||
|
|
||||||
if (Setting === '[save]') {
|
|
||||||
// Save Modal Button
|
|
||||||
|
|
||||||
Array.from(ModalInputs).filter((x) => !x.classList.contains('ignore')).forEach(input => {
|
|
||||||
SetSetting(input, input.value, false, Modal.getAttribute('data-setting'))
|
|
||||||
});
|
|
||||||
Array.from(ModalSelect).filter((x) => !x.classList.contains('ignore')).forEach(select => {
|
|
||||||
SetSetting(select, select.selectedIndex, false, Modal.getAttribute('data-setting'))
|
|
||||||
});
|
|
||||||
Save();
|
|
||||||
setTimeout(function () {
|
|
||||||
LoadCurrent();
|
|
||||||
Modal.close();
|
|
||||||
}, 400)
|
|
||||||
} else if (Setting === '[reset-default]') {
|
|
||||||
// Reset to Defaults Modal Button
|
|
||||||
|
|
||||||
if (confirm("Are you sure you'd like to reset these options to their defaults?") === true) {
|
|
||||||
Settings[Modal.getAttribute('data-setting')] = Utilities.DefaultSettings[Modal.getAttribute('data-setting')]
|
|
||||||
Save()
|
|
||||||
Modal.close();
|
|
||||||
}
|
|
||||||
} else if (Setting === '[cancel]') {
|
|
||||||
// Cancel Changes Button
|
|
||||||
|
|
||||||
Modal.close();
|
|
||||||
} else {
|
|
||||||
// Default Toggle Button
|
|
||||||
|
|
||||||
SetSetting(button, "bool", false, Modal.getAttribute('data-setting'))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
Array.from(ModalInputs).filter((x) => !x.classList.contains('ignore')).forEach(input => {
|
|
||||||
const Status = GetSettingValue(input, Modal.getAttribute('data-setting'))
|
|
||||||
if (Status !== "undefined" && Status !== undefined) {
|
|
||||||
input.value = Status
|
|
||||||
} else {
|
|
||||||
input.value = ''
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Array.from(ModalSelect).filter((x) => !x.classList.contains('ignore')).forEach(select => {
|
|
||||||
const Status = GetSettingValue(select, Modal.getAttribute('data-setting'))
|
|
||||||
if (Status !== "undefined" && Status !== undefined) {
|
|
||||||
select.selectedIndex = Status
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Modal.showModal()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function LoadCurrent() {
|
|
||||||
chrome.storage.sync.get(["PolyPlus_Settings"], function(result) {
|
|
||||||
Settings = MergeObjects(result.PolyPlus_Settings || Utilities.DefaultSettings, Utilities.DefaultSettings)
|
|
||||||
|
|
||||||
console.log("Current Settings: ", Settings)
|
|
||||||
|
|
||||||
Elements.forEach(element => {
|
|
||||||
console.log('For Each Update')
|
|
||||||
UpdateElementState(element)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function SetSetting(element, value, update, modalParent) {
|
|
||||||
const name = element.getAttribute('data-setting')
|
|
||||||
let parent = element.getAttribute('data-parent')
|
|
||||||
|
|
||||||
if (modalParent !== undefined) {
|
|
||||||
console.log(modalParent)
|
|
||||||
parent = modalParent
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value === "bool") {
|
|
||||||
value = !GetSettingValue(element, modalParent)
|
|
||||||
}
|
|
||||||
if (parent !== null) {
|
|
||||||
let Parent = Object.values(Settings)[Object.keys(Settings).indexOf(parent)]
|
|
||||||
if (!isNaN(element.getAttribute('data-parent')) && element.getAttribute('data-parent') !== null) {
|
|
||||||
console.log('is numbere!!!!')
|
|
||||||
Parent = Parent[parseInt(element.getAttribute('data-parent'))]
|
|
||||||
}
|
|
||||||
Parent[name] = value
|
|
||||||
} else {
|
|
||||||
Settings[name] = value
|
|
||||||
}
|
|
||||||
if (update !== false) {
|
|
||||||
UpdateElementState(document.querySelector(`.setting-container:has([data-setting="${name}"])${ (parent !== null) ? `:has([data-parent="${parent}"])` : '' }`), value)
|
|
||||||
}
|
|
||||||
if (SaveBtn.getAttribute('disabled')) {
|
|
||||||
SaveBtn.removeAttribute('disabled')
|
|
||||||
}
|
|
||||||
|
|
||||||
const getInObject = function(a, b) { return Object.values(a)[Object.keys(a).indexOf(b)] }
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetSettingValue(element, modalParent) {
|
|
||||||
const name = element.getAttribute('data-setting')
|
|
||||||
let parent = element.getAttribute('data-parent')
|
|
||||||
|
|
||||||
if (modalParent !== undefined) {
|
|
||||||
parent = modalParent
|
|
||||||
}
|
|
||||||
|
|
||||||
let Status = name;
|
|
||||||
if (parent !== null) {
|
|
||||||
|
|
||||||
let Parent = Object.values(Settings)[Object.keys(Settings).indexOf(parent)]
|
|
||||||
if (!isNaN(element.getAttribute('data-parent')) && element.getAttribute('data-parent') !== null) {
|
|
||||||
Parent = Parent[parseInt(element.getAttribute('data-parent'))]
|
|
||||||
Status = Parent[name]
|
|
||||||
} else {
|
|
||||||
Status = Object.values(Parent)[Object.keys(Parent).indexOf(name)]
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (!isNaN(element.getAttribute('data-parent'))) {
|
|
||||||
Parent = Parent[parseInt(element.getAttribute('data-parent'))]
|
|
||||||
}
|
|
||||||
Status = Object.values(Parent)[Object.keys(Parent).indexOf(Status)]
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
Status = Settings[Status]
|
|
||||||
}
|
|
||||||
console.log('Get Value Result', Status)
|
|
||||||
|
|
||||||
return Status
|
|
||||||
}
|
|
||||||
|
|
||||||
function UpdateElementState(element, status) {
|
|
||||||
console.log('Update Element State', element, status)
|
|
||||||
|
|
||||||
const Button = element.getElementsByClassName('toggle-btn')[0]
|
|
||||||
|
|
||||||
if (status === undefined) {
|
|
||||||
console.log('Update Element State, no status provided')
|
|
||||||
status = GetSettingValue(Button)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status === true) {
|
|
||||||
console.log('Is Enabled so Set False')
|
|
||||||
element.classList.add('enabled')
|
|
||||||
element.classList.remove('disabled')
|
|
||||||
Button.innerText = 'Disable'
|
|
||||||
Button.classList.add('btn-danger')
|
|
||||||
Button.classList.remove('btn-success')
|
|
||||||
} else {
|
|
||||||
console.log('Is Disabled so Set True')
|
|
||||||
element.classList.add('disabled')
|
|
||||||
element.classList.remove('enabled')
|
|
||||||
Button.innerText = 'Enable'
|
|
||||||
Button.classList.add('btn-success')
|
|
||||||
Button.classList.remove('btn-danger')
|
|
||||||
}
|
|
||||||
|
|
||||||
let SelectInput = element.getElementsByTagName('select')[0]
|
|
||||||
if (SelectInput) {
|
|
||||||
console.log('Select Found')
|
|
||||||
SelectInput.selectedIndex = GetSettingValue(SelectInput)
|
|
||||||
}
|
|
||||||
|
|
||||||
let Checkbox = Array.from(element.getElementsByTagName('input'))
|
|
||||||
if (Checkbox.length > 0) {
|
|
||||||
console.log('Checkbox/Input(s) Found', Checkbox)
|
|
||||||
Checkbox.forEach(check => {
|
|
||||||
console.log('check', GetSettingValue(check))
|
|
||||||
check.checked = GetSettingValue(check)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Save() {
|
|
||||||
document.title = 'Poly+ Settings'
|
|
||||||
SaveBtn.setAttribute('disabled', 'true')
|
|
||||||
chrome.storage.sync.set({ 'PolyPlus_Settings': Settings, arrayOrder: true }, function() {
|
|
||||||
console.log('Saved successfully!');
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("Save:", Settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
let LoadThemeFromJSONBtn = document.getElementById('LoadThemeFromJSONBtn')
|
|
||||||
let SaveThemeToJSONInput = document.getElementById('SaveThemeToJSONInput')
|
|
||||||
let CopyThemeJSONBtn = document.getElementById('CopyThemeJSONBtn')
|
|
||||||
LoadThemeFromJSONBtn.addEventListener('click', function(){
|
|
||||||
LoadThemeJSON(LoadThemeFromJSONBtn.previousElementSibling.value)
|
|
||||||
});
|
|
||||||
document.getElementById('theme-creator').getElementsByTagName('button')[1].addEventListener('click', function(){
|
|
||||||
SaveThemeToJSONInput.value = JSON.stringify(Settings.ThemeCreator)
|
|
||||||
});
|
|
||||||
CopyThemeJSONBtn.addEventListener('click', function(){
|
|
||||||
if (SaveThemeToJSONInput.value.length > 0) {
|
|
||||||
navigator.clipboard.writeText(SaveThemeToJSONInput.value)
|
|
||||||
.then(() => {
|
|
||||||
alert('Successfully copied theme data to clipboard!')
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
alert('Failure to copy theme data to clipboard.')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function LoadThemeJSON(string) {
|
|
||||||
try {
|
|
||||||
let JSONTable = JSON.parse(string)
|
|
||||||
if (JSONTable.length === Utilities.DefaultSettings.ThemeCreator.length) {
|
|
||||||
if (confirm('Are you sure you\'d like to replace this theme with the theme specified in the JSON?') === true) {
|
|
||||||
LoadThemeFromJSONBtn.previousElementSibling.value = ''
|
|
||||||
document.getElementById('ThemeCreator-Modal').close()
|
|
||||||
for (let i = 0; i < JSONTable.length; i++) {
|
|
||||||
if (JSONTable[i][0] !== "#") {
|
|
||||||
JSONTable[i] = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Settings.ThemeCreator = MergeObjects(JSONTable, Utilities.DefaultSettings.ThemeCreator)
|
|
||||||
Save();
|
|
||||||
console.log(JSONTable.length, JSONTable, 'applied')
|
|
||||||
document.getElementById('ThemeCreator').getElementsByTagName('button')[1].click();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
alert('JSON is not a theme!')
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
alert('JSON is invalid!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MergeObjects function was written by ChatGPT cause I was lazy and it was awhile ago
|
|
||||||
function MergeObjects(obj1, obj2) {
|
|
||||||
var mergedObj = {};
|
|
||||||
|
|
||||||
// Copy the values from obj1 to the mergedObj
|
|
||||||
for (var key in obj1) {
|
|
||||||
mergedObj[key] = obj1[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge the values from obj2 into the mergedObj, favoring obj2 for non-existing keys in obj1
|
|
||||||
for (var key in obj2) {
|
|
||||||
if (!obj1.hasOwnProperty(key)) {
|
|
||||||
mergedObj[key] = obj2[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mergedObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
function FormatBool(bool){
|
|
||||||
if (bool === true) { return 'enabled' }
|
|
||||||
else { return 'disabled' }
|
|
||||||
}
|
|
||||||
|
|
||||||
const Manifest = chrome.runtime.getManifest()
|
|
||||||
let BuildType = "Stable"
|
|
||||||
if (Manifest.version_name !== undefined) {BuildType = "Pre-Release"}
|
|
||||||
|
|
||||||
const FooterText = document.getElementById('footer-text')
|
|
||||||
FooterText.children[0].innerHTML = `Version: v${Manifest.version} | Build Type: ${BuildType}`
|
|
||||||
|
|
||||||
const CheckForUpdatesButton = document.getElementById('check-for-updates')
|
|
||||||
function CheckForUpdates() {
|
|
||||||
CheckForUpdatesButton.removeEventListener('click', CheckForUpdates)
|
|
||||||
CheckForUpdatesButton.disabled = true
|
|
||||||
fetch('https://polyplus.vercel.app/data/version.json')
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network not ok')
|
|
||||||
}
|
|
||||||
return response.json()
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
if (data.version === Manifest.version || Math.floor((data.version - Manifest.version) * 10) === 0) {
|
|
||||||
CheckForUpdatesButton.innerHTML = '<b>No updates available</b>'
|
|
||||||
alert('No updates available')
|
|
||||||
} else {
|
|
||||||
const NumberOfUpdatesAvailable = Math.floor((data.version - Version) * 10)
|
|
||||||
CheckForUpdatesButton.innerHTML = '<b>'+NumberOfUpdatesAvailable+' update(s) available</b>'
|
|
||||||
alert(NumberOfUpdatesAvailable + ' updates available')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {console.log(error)});
|
|
||||||
}
|
|
||||||
CheckForUpdatesButton.addEventListener('click', CheckForUpdates)
|
|
||||||
|
|
||||||
fetch(chrome.runtime.getURL('resources/currencies.json'))
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network not ok')
|
|
||||||
}
|
|
||||||
return response.json()
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
const DateText = new Date(data.Date).toLocaleDateString("en-US", {day:"numeric",month:"long",year:"numeric"})
|
|
||||||
document.getElementById('IRLPriceWithCurrency-Date').innerText = DateText
|
|
||||||
})
|
|
||||||
.catch(error => {console.log(error)})
|
|
||||||
|
|
||||||
chrome.storage.local.get(['PolyPlus_OutOfDate', 'PolyPlus_LiveVersion', 'PolyPlus_ReleaseNotes', 'PolyPlus_SkipUpdate'], function(result) {
|
|
||||||
const OutOfDate = result.PolyPlus_OutOfDate || false
|
|
||||||
const SkipUpdate = result.PolyPlus_SkipUpdate || null
|
|
||||||
const LiveVersion = result.PolyPlus_LiveVersion || Manifest.version
|
|
||||||
if (OutOfDate === true && SkipUpdate !== LiveVersion) {
|
|
||||||
const Banner = document.createElement('div')
|
|
||||||
Banner.classList = 'alert position-sticky p-3'
|
|
||||||
Banner.style = 'top: 30px; box-shadow: 0 0 20px 2px #000; z-index: 2000; background: rgb(163 39 39);'
|
|
||||||
Banner.innerHTML = `
|
|
||||||
<b>New Update Available!</b>
|
|
||||||
<br>
|
|
||||||
Your Poly+ installation is out of date! If you would like to get the latest and greatest features, improvements, and bug fixes click on one of the links below to dismiss this banner!
|
|
||||||
<br>
|
|
||||||
<div role="group" class="btn-group w-100 mt-2">
|
|
||||||
<a href="${result.PolyPlus_ReleaseNotes}" class="btn btn-primary btn-sm w-25" target="_blank">Go to Release Notes</a>
|
|
||||||
<button id="skip-this-update" class="btn btn-warning btn-sm w-25">(Not Recommended) Skip this Update</button>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
document.getElementById('page').insertBefore(Banner, document.getElementById('page').children[1])
|
|
||||||
|
|
||||||
const SkipButton = document.getElementById('skip-this-update')
|
|
||||||
SkipButton.addEventListener('click', function(){
|
|
||||||
Banner.remove()
|
|
||||||
chrome.storage.local.set({'PolyPlus_SkipUpdate': result.PolyPlus_LiveVersion}, function(){
|
|
||||||
console.log('set skip update to live version: ', result.PolyPlus_LiveVersion)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
Reference in a new issue