diff --git a/element-changer/README.md b/element-changer/README.md index a572457..f324b3b 100644 --- a/element-changer/README.md +++ b/element-changer/README.md @@ -2,6 +2,7 @@ ## What does it do? As the name might suggest, it allows you to modify any VistaPanel widget element! (Well, aside from the right sidebar ones.) +You are currently able to change and remove elements. ## Where should I put it? You can put it anywhere! We recommend avoiding the left advert area, as it will break the sidebar. @@ -9,15 +10,21 @@ You can put it anywhere! We recommend avoiding the left advert area, as it will ## How can I install it? You'll first need to declare an array with the name ``changeElements`` within a script tag. -To change the elements of a group, you will need to create an object with the following properties that we'll analyze afterwards: +To change an element, you will need to create an object with the following properties that we'll analyze afterwards: ```js -{name: "Element name", attr: "attribute", value: "new value"} +{name: "Element name", action: "modify", attr: "attribute", value: "new value"} +``` +To remove an element, the object will be structured like this: +```js +{name: "Element name", action: "remove"} ``` ### Properties In ``name``, you'll assign a value that corresponds with the name of the element exactly as it appears on the panel. For instance ``"Change Password"`` is what you'll need to enter to modify the Change Password element. +The action you wish to perform will be defined in ``action``. Currently, there are two actions supported, ``modify`` and ``remove``. Ensuring backwards compatibility, if you declare no action in your object the script will assume ``modify `` to be the intended action. + ``attr`` is the attribute you wish to modify. There are two main attributes: ``itemdesc`` and ``url``. The first defines the name the element will have on the panel, while the second, as you can tell by the name, defines the URL for it. @@ -27,8 +34,15 @@ Finally, ``value`` holds the new value of the element you'll be changing, for ex An example of the code modifying the name and URL of ``Change Password`` to ``Your Domain`` and ``https://yourdomain.com`` respectively can be seen below: ```js changeElements = [ - {name: "Change Password", attr: "itemdesc", value: "Your Domain"}, - {name: "Change Password", attr: "url", value: "https://yourdomain.com"} + {name: "Change Password", action: "modify", attr: "itemdesc", value: "Your Domain"}, + {name: "Change Password", action: "modify", attr: "url", value: "https://yourdomain.com"} +]; +``` +Likewise, an example of removing ``CNAME Records`` and ``MX Entry`` is provided here: +```js +changeElements = [ + {name: "MX Entry", action: "remove"}, + {name: "CNAME Records", action: "remove"} ]; ``` Objects are separated by commas, so don't forget to include them when adding a new one. @@ -36,14 +50,16 @@ Objects are separated by commas, so don't forget to include them when adding a n ### What is all of this? Where is my ready-to-use code? Please read the Properties section before attempting to make your own modifications. -We'll provide a ready code for modifying the names and URLs of ``SiteBuilder`` and ``Softaculous Apps Installer``. Try it out in your panel (with the script, of course) to be able to better understand the process in adding your own objects. +We'll provide a ready code for modifying the names and URLs of ``SiteBuilder`` and ``Softaculous Apps Installer``, and removing ``Access Logs`` and ``Remote MySQL``. Try it out in your panel (with the script, of course) to be able to better understand the process in adding your own objects. ```html ``` @@ -68,14 +84,17 @@ A full code utilizing our example and our CDN: ```html ``` ## Changelog -* Created on 15 August 2022 by [Anyx](https://github.com/4yx) -* Modified on 15 August 2022 by [PlanetCloud](https://github.com/PlanetTheCloud) \ No newline at end of file +* Created on 15 September 2022 by [Anyx](https://github.com/4yx) +* Modified on 15 September 2022 by [PlanetCloud](https://github.com/PlanetTheCloud) +* Last modified on 19 September 2022 by [PlanetCloud](https://github.com/PlanetTheCloud) \ No newline at end of file diff --git a/element-changer/element-changer.js b/element-changer/element-changer.js index 0d58936..3833bf8 100644 --- a/element-changer/element-changer.js +++ b/element-changer/element-changer.js @@ -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."); -} \ No newline at end of file + } + + // 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.'); +})(); \ No newline at end of file diff --git a/element-changer/element-changer.min.js b/element-changer/element-changer.min.js index 205beb7..6f476e4 100644 --- a/element-changer/element-changer.min.js +++ b/element-changer/element-changer.min.js @@ -1,6 +1,7 @@ /* @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. */ -"undefined"!=typeof changeElements?(e=>{if(0==e.length)return console.log("ElementChanger: Nothing to modify.");var n=[],o=0;PAGE.appGroups.forEach(e=>{var t=0;e.items.forEach(e=>{void 0===n[e.itemdesc]&&(n[e.itemdesc]=[]),n[e.itemdesc].push({group:o,item:t}),t++}),o++}),e.forEach(e=>{void 0!==n[e.name]?n[e.name].forEach(n=>{PAGE.appGroups[n.group].items[n.item][e.attr]=e.value}):console.log(`ElementChanger: Trying to change element ${e.name} which does not exist.`)}),console.log("ElementChanger: All modifications have been made.")})(changeElements):console.log("ElementChanger: changeElements variable is not defined. No elements changed."); \ No newline at end of file +function indexPanelElements(){let e=[],n=i=0;return PAGE.appGroups.forEach(o=>{o.items.forEach(o=>{void 0===e[o.itemdesc]&&(e[o.itemdesc]=[]),e[o.itemdesc].push({group:n,item:i}),i++}),n++,i=0}),e}(()=>{if("undefined"==typeof changeElements)return console.log("ElementChanger: changeElements variable is not defined. No elements changed.");if(0==changeElements.length)return console.log("ElementChanger: Nothing to modify.");var e={modify:[],remove:[]};changeElements.forEach(n=>{void 0===n.action&&(n.action="modify"),["modify","remove"].includes(n.action)?e[n.action].push(n):console.log(`ElementChanger: Illegal action ${n.action} specified for the following element:`,n)}),e.remove.length>0&&(panelElementsIndex=indexPanelElements(),e.remove.forEach(e=>{if(void 0===panelElementsIndex[e.name])return console.log(`ElementChanger: Trying to remove element ${e.name} which does not exist.`);panelElementsIndex[e.name].forEach(n=>{PAGE.appGroups[n.group].items=PAGE.appGroups[n.group].items.filter(n=>n.itemdesc!=e.name)})})),panelElementsIndex=indexPanelElements(),e.modify.forEach(e=>{if(void 0===panelElementsIndex[e.name])return console.log(`ElementChanger: Trying to change element ${e.name} which does not exist.`);panelElementsIndex[e.name].forEach(n=>{PAGE.appGroups[n.group].items[n.item][e.attr]=e.value})}),console.log("ElementChanger: All modifications have been made.")})(); \ No newline at end of file