renamed files
This commit is contained in:
parent
fc230ec3b8
commit
b21af09301
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>
|
||||||
|
|
|
||||||
349
settings.js
Executable file → Normal file
349
settings.js
Executable file → Normal file
|
|
@ -2,14 +2,11 @@ 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
|
||||||
|
|
||||||
ExpectedSettings = Utilities.DefaultSettings
|
|
||||||
LoadCurrent()
|
LoadCurrent()
|
||||||
|
|
||||||
document.getElementById('PinnedGames-limit').innerText = Utilities.Limits.PinnedGames
|
document.getElementById('PinnedGames-limit').innerText = Utilities.Limits.PinnedGames
|
||||||
|
|
@ -28,7 +25,7 @@ SaveBtn.addEventListener("click", function() {
|
||||||
|
|
||||||
// Handle modal buttons for Reset Defaults modal
|
// Handle modal buttons for Reset Defaults modal
|
||||||
document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function() {
|
document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function() {
|
||||||
Settings = ExpectedSettings
|
Settings = Utilities.DefaultSettings
|
||||||
Save()
|
Save()
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
LoadCurrent();
|
LoadCurrent();
|
||||||
|
|
@ -40,103 +37,63 @@ document.getElementById('ResetDefaults-Modal-No').addEventListener('click', func
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle leaving the settings page before saving
|
// Handle leaving the settings page before saving
|
||||||
/*
|
|
||||||
window.onbeforeunload = function() {
|
window.onbeforeunload = function() {
|
||||||
if (SaveBtn.getAttribute('disabled') !== null) {
|
if (SaveBtn.getAttribute('disabled') !== undefined) {
|
||||||
return "Are you sure you'd like to leave? Your Poly+ settings haven't been saved."
|
return "Are you sure you'd like to leave? Your Poly+ settings haven't been saved."
|
||||||
}
|
}
|
||||||
return "aaa"
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Loop thru each setting container and handle toggling, selecting, opening modal, etc
|
// Loop thru each setting container and handle toggling, selecting, opening modal, etc
|
||||||
Elements.forEach(element => {
|
Elements.forEach(element => {
|
||||||
|
console.log('Handle Element', element)
|
||||||
let Button = element.getElementsByTagName('button')[0]
|
let Button = element.getElementsByTagName('button')[0]
|
||||||
let Options = element.getElementsByTagName('button')[1]
|
let Options = element.getElementsByTagName('button')[1]
|
||||||
let Select = element.getElementsByTagName('select') || []
|
let Select = element.getElementsByTagName('select')[0]
|
||||||
//let Checkbox = element.getElementsByTagName('input') || []
|
let Checkbox = element.getElementsByTagName('input')[0]
|
||||||
//console.log(Checkbox)
|
|
||||||
|
|
||||||
if (Button) {
|
if (Button) {
|
||||||
Button.addEventListener('click', function() {
|
Button.addEventListener('click', function() {
|
||||||
ToggleSetting(Button.getAttribute('data-setting'), element)
|
SetSetting(Button, "bool")
|
||||||
|
|
||||||
/*
|
|
||||||
if (!(Button.getAttribute('data-parent'))) {
|
|
||||||
ToggleSetting(Button.getAttribute('data-setting'), element)
|
|
||||||
} else {
|
|
||||||
let Parent = Button.getAttribute('data-parent')
|
|
||||||
if (!isNaN(parseInt(Parent))) {
|
|
||||||
Parent = parseInt(Parent)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Settings[Parent]) {
|
|
||||||
Settings[Parent] = {}
|
|
||||||
console.log('empty btn')
|
|
||||||
}
|
|
||||||
console.log(Button.getAttribute('data-setting'), Parent, Settings[Parent])
|
|
||||||
ToggleSetting(Button.getAttribute('data-setting'), element, Parent)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (Select) {
|
||||||
Array.from(Checkbox).forEach(check => {
|
Select.addEventListener('change', function(){
|
||||||
check.addEventListener('click', function(){
|
if (Select.getAttribute('data-useValue') !== undefined) {
|
||||||
if (!(check.getAttribute('data-parent'))) {
|
let Value = Select.options[Select.selectedIndex].value
|
||||||
ToggleSetting(check.getAttribute('data-setting'), element)
|
if (!isNaN(Value)) { Value = parseInt(Value) }
|
||||||
|
SetSetting(Select, Value, false)
|
||||||
} else {
|
} else {
|
||||||
let Parent = check.getAttribute('data-parent')
|
SetSetting(Select, Select.selectedIndex, false)
|
||||||
if (!isNaN(parseInt(Parent))) {
|
|
||||||
Parent = parseInt(Parent)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Settings[Parent]) {
|
|
||||||
Settings[Parent] = {}
|
|
||||||
console.log('empty')
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(check.getAttribute('data-setting'), Parent, Settings[Parent])
|
|
||||||
ToggleSetting(check.getAttribute('data-setting'), null, Parent)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Checkbox) {
|
||||||
|
Checkbox.addEventListener('change', function(){
|
||||||
|
SetSetting(Checkbox, Checkbox.checked, false)
|
||||||
})
|
})
|
||||||
*/
|
}
|
||||||
|
|
||||||
if (Options) {
|
if (Options) {
|
||||||
Options.addEventListener('click', function() {
|
const Modal = document.getElementById(Options.getAttribute('data-modal') + '-Modal')
|
||||||
let Modal = document.getElementById(Options.getAttribute('data-modal') + '-Modal')
|
const ModalButtons = Modal.getElementsByTagName('button')
|
||||||
let ModalButtons = Modal.getElementsByTagName('button')
|
const ModalInputs = Modal.getElementsByTagName('input')
|
||||||
let ModalInputs = Modal.getElementsByTagName('input')
|
const ModalSelect = Modal.getElementsByTagName('select')
|
||||||
let 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')
|
||||||
|
|
||||||
Array.from(ModalButtons).forEach(btn => {
|
|
||||||
if (!(btn.getAttribute('data-ignore') === 'true')) {
|
|
||||||
btn.addEventListener('click', function(){
|
|
||||||
let Setting = btn.getAttribute('data-setting')
|
|
||||||
if (Setting === '[save]') {
|
if (Setting === '[save]') {
|
||||||
Array.from(ModalInputs).forEach(input => {
|
// Save Modal Button
|
||||||
if (!(input.getAttribute('data-ignore') === 'true')) {
|
|
||||||
if (!(input.getAttribute('data-parent'))) {
|
Array.from(ModalInputs).filter((x) => !x.classList.contains('ignore')).forEach(input => {
|
||||||
Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] = input.value || null
|
SetSetting(input, input.value, false, Modal.getAttribute('data-setting'))
|
||||||
} else {
|
|
||||||
let Parent = input.getAttribute('data-parent')
|
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
|
||||||
Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] = input.value || null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Array.from(ModalSelect).forEach(select => {
|
Array.from(ModalSelect).filter((x) => !x.classList.contains('ignore')).forEach(select => {
|
||||||
if (!(select.getAttribute('data-ignore') === 'true')) {
|
SetSetting(select, select.selectedIndex, false, Modal.getAttribute('data-setting'))
|
||||||
if (!(select.getAttribute('data-parent'))) {
|
|
||||||
Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] = select.selectedIndex
|
|
||||||
} else {
|
|
||||||
let Parent = input.getAttribute('data-parent')
|
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
|
||||||
Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] = select.selectedIndex
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Save();
|
Save();
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
|
@ -144,143 +101,163 @@ Elements.forEach(element => {
|
||||||
Modal.close();
|
Modal.close();
|
||||||
}, 400)
|
}, 400)
|
||||||
} else if (Setting === '[reset-default]') {
|
} 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 (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')]
|
Settings[Modal.getAttribute('data-setting')] = Utilities.DefaultSettings[Modal.getAttribute('data-setting')]
|
||||||
Save()
|
Save()
|
||||||
Modal.close();
|
Modal.close();
|
||||||
}
|
}
|
||||||
} else if (Setting === '[cancel]') {
|
} else if (Setting === '[cancel]') {
|
||||||
|
// Cancel Changes Button
|
||||||
|
|
||||||
Modal.close();
|
Modal.close();
|
||||||
} else {
|
} else {
|
||||||
if (!(btn.getAttribute('data-parent'))) {
|
// Default Toggle Button
|
||||||
ToggleSetting(Modal.getAttribute('data-setting')[btn.getAttribute('data-setting')], null)
|
|
||||||
} else {
|
|
||||||
let Parent = input.getAttribute('data-parent')
|
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
|
||||||
ToggleSetting(Modal.getAttribute('data-setting')[Parent][btn.getAttribute('data-setting')], null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Array.from(ModalInputs).forEach(input => {
|
SetSetting(button, "bool", false, Modal.getAttribute('data-setting'))
|
||||||
if (!(input.getAttribute('data-ignore') === 'true')) {
|
}
|
||||||
if (!(input.getAttribute('data-parent'))) {
|
})
|
||||||
if (Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] !== "undefined" && Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] !== undefined) {
|
})
|
||||||
input.value = Settings[Modal.getAttribute('data-setting')][input.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 {
|
} else {
|
||||||
input.value = ''
|
input.value = ''
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
let Parent = input.getAttribute('data-parent')
|
|
||||||
if (Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] !== "undefined" && Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] !== undefined) {
|
|
||||||
if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)}
|
|
||||||
input.value = Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')]
|
|
||||||
} else {
|
|
||||||
input.value = ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Array.from(ModalSelect).forEach(select => {
|
Array.from(ModalSelect).filter((x) => !x.classList.contains('ignore')).forEach(select => {
|
||||||
if (!(select.getAttribute('data-ignore') === 'true')) {
|
const Status = GetSettingValue(select, Modal.getAttribute('data-setting'))
|
||||||
if (!(select.getAttribute('data-parent'))) {
|
if (Status !== "undefined" && Status !== undefined) {
|
||||||
if (Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] !== "undefined") {
|
select.selectedIndex = Status
|
||||||
select.selectedIndex = Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let Parent = input.getAttribute('data-parent')
|
|
||||||
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')]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Modal.showModal()
|
Modal.showModal()
|
||||||
});
|
})
|
||||||
}
|
|
||||||
|
|
||||||
if (Select.length > 0) {
|
|
||||||
Array.from(Select).forEach(element => {
|
|
||||||
element.addEventListener('change', function() {
|
|
||||||
SetSetting(element.getAttribute('data-setting'), element, element.selectedIndex)
|
|
||||||
Save()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function LoadCurrent() {
|
function LoadCurrent() {
|
||||||
chrome.storage.sync.get(["PolyPlus_Settings"], function(result) {
|
chrome.storage.sync.get(["PolyPlus_Settings"], function(result) {
|
||||||
Settings = MergeObjects(result.PolyPlus_Settings || ExpectedSettings, ExpectedSettings)
|
Settings = MergeObjects(result.PolyPlus_Settings || Utilities.DefaultSettings, Utilities.DefaultSettings)
|
||||||
|
|
||||||
console.log("Current: ", Settings)
|
console.log("Current Settings: ", Settings)
|
||||||
|
|
||||||
Elements.forEach(element => {
|
Elements.forEach(element => {
|
||||||
const ToggleBtn = element.getElementsByClassName('toggle-btn')[0]
|
console.log('For Each Update')
|
||||||
if (Settings[ToggleBtn.getAttribute('data-setting')] === true) {
|
UpdateElementState(element)
|
||||||
element.classList.add('enabled')
|
});
|
||||||
ToggleBtn.innerText = 'Disable'
|
});
|
||||||
ToggleBtn.classList.add('btn-danger')
|
}
|
||||||
} else {
|
|
||||||
element.classList.add('disabled')
|
function SetSetting(element, value, update, modalParent) {
|
||||||
ToggleBtn.innerText = 'Enable'
|
const name = element.getAttribute('data-setting')
|
||||||
ToggleBtn.classList.add('btn-success')
|
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]
|
let SelectInput = element.getElementsByTagName('select')[0]
|
||||||
if (SelectInput) {
|
if (SelectInput) {
|
||||||
SelectInput.selectedIndex = Settings[SelectInput.getAttribute('data-setting')]
|
console.log('Select Found')
|
||||||
}
|
SelectInput.selectedIndex = GetSettingValue(SelectInput)
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function ToggleSetting(Name, Element, Parent) {
|
|
||||||
document.title = "*unsaved | Poly+ Settings"
|
|
||||||
let Status;
|
|
||||||
if (!Parent) {
|
|
||||||
Status = Settings[Name]
|
|
||||||
if (Settings[Name] === true) {
|
|
||||||
Settings[Name] = false;
|
|
||||||
} else {
|
|
||||||
Settings[Name] = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Status = Settings[Parent][Name]
|
|
||||||
if (Settings[Parent][Name] === true) {
|
|
||||||
Settings[Parent][Name] = false;
|
|
||||||
} else {
|
|
||||||
Settings[Parent][Name] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Element !== null) {
|
|
||||||
const ToggleBtn = Element.getElementsByClassName('toggle-btn')[0]
|
|
||||||
if (Status === false) {
|
|
||||||
ToggleBtn.innerText = 'Enable'
|
|
||||||
} else {
|
|
||||||
ToggleBtn.innerText = 'Disable'
|
|
||||||
}
|
|
||||||
Element.classList.toggle('enabled')
|
|
||||||
Element.classList.toggle('disabled')
|
|
||||||
ToggleBtn.classList.toggle('btn-success')
|
|
||||||
ToggleBtn.classList.toggle('btn-danger')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SaveBtn.getAttribute('disabled')) {
|
let Checkbox = Array.from(element.getElementsByTagName('input'))
|
||||||
SaveBtn.removeAttribute('disabled')
|
if (Checkbox.length > 0) {
|
||||||
}
|
console.log('Checkbox/Input(s) Found', Checkbox)
|
||||||
}
|
Checkbox.forEach(check => {
|
||||||
|
console.log('check', GetSettingValue(check))
|
||||||
function SetSetting(Name, Element, Value) {
|
check.checked = GetSettingValue(check)
|
||||||
console.log(Settings)
|
})
|
||||||
Settings[Name] = Value
|
|
||||||
|
|
||||||
if (SaveBtn.getAttribute('disabled')) {
|
|
||||||
SaveBtn.removeAttribute('disabled')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,7 +295,7 @@ CopyThemeJSONBtn.addEventListener('click', function(){
|
||||||
function LoadThemeJSON(string) {
|
function LoadThemeJSON(string) {
|
||||||
try {
|
try {
|
||||||
let JSONTable = JSON.parse(string)
|
let JSONTable = JSON.parse(string)
|
||||||
if (JSONTable.length === ExpectedSettings.ThemeCreator.length) {
|
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) {
|
if (confirm('Are you sure you\'d like to replace this theme with the theme specified in the JSON?') === true) {
|
||||||
LoadThemeFromJSONBtn.previousElementSibling.value = ''
|
LoadThemeFromJSONBtn.previousElementSibling.value = ''
|
||||||
document.getElementById('ThemeCreator-Modal').close()
|
document.getElementById('ThemeCreator-Modal').close()
|
||||||
|
|
@ -327,7 +304,7 @@ function LoadThemeJSON(string) {
|
||||||
JSONTable[i] = ""
|
JSONTable[i] = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Settings.ThemeCreator = MergeObjects(JSONTable, ExpectedSettings.ThemeCreator)
|
Settings.ThemeCreator = MergeObjects(JSONTable, Utilities.DefaultSettings.ThemeCreator)
|
||||||
Save();
|
Save();
|
||||||
console.log(JSONTable.length, JSONTable, 'applied')
|
console.log(JSONTable.length, JSONTable, 'applied')
|
||||||
document.getElementById('ThemeCreator').getElementsByTagName('button')[1].click();
|
document.getElementById('ThemeCreator').getElementsByTagName('button')[1].click();
|
||||||
|
|
|
||||||
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