-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The following changes were made: * Element removing has been implemented in Element Changer, while remaining backwards compatible. * Update the way elements are indexed in Element Changer. Once again, all the credit belongs to @PlanetTheCloud. Thank you! Co-Authored-By: Planet Cloud <[email protected]>
- Loading branch information
1 parent
ac5752e
commit 3a2839e
Showing
3 changed files
with
104 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,77 @@ | ||
/* @preserve | ||
* Created at 15 September 2022 by Anyx and modified by PlanetCloud. | ||
* Last modified at 19 September 2022 by PlanetCloud. | ||
* DO NOT REMOVE CREDITS! | ||
* Created for: Wybe Network. | ||
*/ | ||
if (typeof changeElements !== "undefined") { | ||
((changeElements) => { | ||
if (changeElements.length == 0) { | ||
return console.log('ElementChanger: Nothing to modify.'); | ||
} | ||
var panelElementsIndex = [], | ||
groupIndex = 0; | ||
PAGE.appGroups.forEach(group => { | ||
var itemIndex = 0; | ||
group.items.forEach(item => { | ||
if (typeof panelElementsIndex[item.itemdesc] == 'undefined') { | ||
panelElementsIndex[item.itemdesc] = []; | ||
} | ||
panelElementsIndex[item.itemdesc].push({ | ||
group: groupIndex, | ||
item: itemIndex | ||
}); | ||
itemIndex++; | ||
function indexPanelElements() { | ||
let panelElementsIndex = [], | ||
g = i = 0; | ||
PAGE.appGroups.forEach(group => { | ||
group.items.forEach(item => { | ||
if (typeof panelElementsIndex[item.itemdesc] == 'undefined') { | ||
panelElementsIndex[item.itemdesc] = []; | ||
} | ||
panelElementsIndex[item.itemdesc].push({ | ||
group: g, | ||
item: i | ||
}); | ||
groupIndex++; | ||
i++; | ||
}); | ||
changeElements.forEach(element => { | ||
if (typeof panelElementsIndex[element.name] !== 'undefined') { | ||
panelElementsIndex[element.name].forEach(e => { | ||
PAGE.appGroups[e.group].items[e.item][element.attr] = element.value; | ||
}) | ||
} else { | ||
console.log(`ElementChanger: Trying to change element ${element.name} which does not exist.`); | ||
g++; | ||
i = 0; | ||
}); | ||
return panelElementsIndex; | ||
} | ||
|
||
(() => { | ||
if (typeof changeElements == "undefined") { | ||
return console.log("ElementChanger: changeElements variable is not defined. No elements changed."); | ||
} | ||
if (changeElements.length == 0) { | ||
return console.log('ElementChanger: Nothing to modify.'); | ||
} | ||
|
||
// Index changeElements | ||
var toChange = { | ||
modify: [], | ||
remove: [] | ||
}; | ||
changeElements.forEach(e => { | ||
if (typeof e.action == 'undefined') { | ||
e.action = 'modify'; | ||
} | ||
if (!['modify', 'remove'].includes(e.action)) { | ||
console.log(`ElementChanger: Illegal action ${e.action} specified for the following element:`, e); | ||
return; | ||
} | ||
toChange[e.action].push(e); | ||
}); | ||
|
||
// Remove elements | ||
if (toChange.remove.length > 0) { | ||
panelElementsIndex = indexPanelElements(); | ||
toChange.remove.forEach(r => { | ||
if (typeof panelElementsIndex[r.name] == 'undefined') { | ||
return console.log(`ElementChanger: Trying to remove element ${r.name} which does not exist.`) | ||
} | ||
panelElementsIndex[r.name].forEach(e => { | ||
PAGE.appGroups[e.group].items = PAGE.appGroups[e.group].items.filter(i => i.itemdesc != r.name); | ||
}); | ||
}); | ||
console.log('ElementChanger: All modifications have been made.'); | ||
})(changeElements); | ||
} else { | ||
console.log("ElementChanger: changeElements variable is not defined. No elements changed."); | ||
} | ||
} | ||
|
||
// Modify elements | ||
panelElementsIndex = indexPanelElements(); | ||
toChange.modify.forEach(c => { | ||
if (typeof panelElementsIndex[c.name] == 'undefined') { | ||
return console.log(`ElementChanger: Trying to change element ${c.name} which does not exist.`); | ||
} | ||
panelElementsIndex[c.name].forEach(e => { | ||
PAGE.appGroups[e.group].items[e.item][c.attr] = c.value; | ||
}) | ||
}); | ||
|
||
// Done! | ||
console.log('ElementChanger: All modifications have been made.'); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.