From e49c518ef36eabdc2407dd9d5067842aa918bd96 Mon Sep 17 00:00:00 2001 From: Flex Date: Mon, 14 May 2018 06:42:48 -0600 Subject: [PATCH] add settings api, move everything to proposed manifest format --- plugins/beautifuldiscord.js | 4 +- plugins/charcount.js | 4 +- plugins/dblclickedit.js | 4 +- plugins/fixmentions.js | 7 +- plugins/guildcount.js | 4 +- plugins/imgxis.js | 4 +- plugins/localstorage.js | 6 +- plugins/notifsound.js | 4 +- plugins/osutyping.js | 4 +- plugins/sailboat.js | 6 +- plugins/settingsapi.js | 217 ++++++++++++++++++++++++++++++++++++ plugins/spotifyspoof.js | 4 +- 12 files changed, 242 insertions(+), 26 deletions(-) create mode 100644 plugins/settingsapi.js diff --git a/plugins/beautifuldiscord.js b/plugins/beautifuldiscord.js index 78e88ba..8ccef14 100644 --- a/plugins/beautifuldiscord.js +++ b/plugins/beautifuldiscord.js @@ -10,10 +10,10 @@ bdwatcher = null, bdtag = null, setupCSS = function (n) { })) }; -exports.meta = { +exports.manifest = { author: "dr1ft", name: "BeautifulDiscord Port", - desc: "Allows CSS to be imported and updated on the fly." + description: "Allows CSS to be imported and updated on the fly." }, exports.start = () => { if (fs.existsSync($api.data + 'style.css')) diff --git a/plugins/charcount.js b/plugins/charcount.js index ce6bf17..c4d9fa3 100644 --- a/plugins/charcount.js +++ b/plugins/charcount.js @@ -16,10 +16,10 @@ function setupCharCount() { } exports = { - meta: { + manifest: { author: "Cynosphere", name: "Character Counter", - desc: "Counts characters in the chatbox." + description: "Counts characters in the chatbox." }, start: function(){ let charcount_mo = new MutationObserver(setupCharCount); diff --git a/plugins/dblclickedit.js b/plugins/dblclickedit.js index 7722d64..ed3ae47 100644 --- a/plugins/dblclickedit.js +++ b/plugins/dblclickedit.js @@ -1,7 +1,7 @@ -exports.meta = { +exports.manifest = { author: "Cynosphere, Jiiks", name: "Double Click Edit", - desc: "Double click messages to edit them." + description: "Double click messages to edit them." } exports.start = function(){ document.addEventListener("dblclick", ev => { diff --git a/plugins/fixmentions.js b/plugins/fixmentions.js index 9b1ec02..fe1da46 100644 --- a/plugins/fixmentions.js +++ b/plugins/fixmentions.js @@ -1,14 +1,13 @@ exportsexports = { - meta: { + manifest: { author: "Cynosphere, Adryd", name: "Mentions Fixer", - desc: "See hidden channel mentions and remove #deleted-channel." + description: "See hidden channel mentions and remove #deleted-channel." }, replacements: { '/t\\.type===(.+)\\.ChannelTypes\\.GUILD_TEXT&&(.+)\\.default\\.can\\((.+)\\.Permissions\\.VIEW_CHANNEL,n,t\\)/':'true', '/"#deleted-channel"/':'"<#"+e[1]+">"', '/"@deleted-role"/':'"<@&"+e[1]+">"', - '/guildId:null!=t\\?t\\.guild_id:null,/':'guildId:null!=t.guild_id?t.guild_id:"@me",', - '/"#deleted-channel"/':'"<#"+e[1]+">"' + '/guildId:null!=t\\?t\\.guild_id:null,/':'guildId:null!=t.guild_id?t.guild_id:"@me",' } } \ No newline at end of file diff --git a/plugins/guildcount.js b/plugins/guildcount.js index c08ca40..1e7d0ad 100644 --- a/plugins/guildcount.js +++ b/plugins/guildcount.js @@ -39,10 +39,10 @@ function scCSS() { document.body.appendChild(css); } -exports.meta = { +exports.manifest = { author: "Cynosphere", name: "Guild Count", - desc: "Shows guild count under online count." + description: "Shows guild count under online count." } exports.start = () => { scCSS(); diff --git a/plugins/imgxis.js b/plugins/imgxis.js index 2ebc5cc..b830e98 100644 --- a/plugins/imgxis.js +++ b/plugins/imgxis.js @@ -3,10 +3,10 @@ IMGXIS made by YellowAfterlife. http://yellowafterlife.itch.io/imgxis (mirror: h Ported by Jane (maybejane/statefram) and Cynthia (BoxOfFlex/Cynosphere) to a private client mod. Re-ported by Cynthia to EndPwn. */ -exports.meta = { +exports.manifest = { author: "Cynosphere, YellowAfterlife", name: "IMGXIS", - desc: "A better way to view images." + description: "A better way to view images." } exports.start = function(){ var globalPanner; diff --git a/plugins/localstorage.js b/plugins/localstorage.js index 583f19b..e8026ac 100644 --- a/plugins/localstorage.js +++ b/plugins/localstorage.js @@ -1,8 +1,8 @@ exports = { - meta: { - author: "Cynosphere, Adryd", + manifest: { + author: "Cynosphere", name: "Restore Local Storage", - desc: "Restore window.localStorage." + description: "Restore window.localStorage." }, replacements: { 'try{delete window.localStorage}catch(e){}':'' diff --git a/plugins/notifsound.js b/plugins/notifsound.js index c3d79d7..cf5bd4c 100644 --- a/plugins/notifsound.js +++ b/plugins/notifsound.js @@ -1,7 +1,7 @@ -exports.meta = { +exports.manifest = { author: "dr1ft", name: "Notification Sound Replacer", - desc: "Replaces notification sound with an unused sound thats nicer." + description: "Replaces notification sound with an unused sound thats nicer." } exports.start = function(){ var s = wc.findFunc('playSound')[1].exports; diff --git a/plugins/osutyping.js b/plugins/osutyping.js index 94acd21..80723f9 100644 --- a/plugins/osutyping.js +++ b/plugins/osutyping.js @@ -1,8 +1,8 @@ exportsexports = { - meta: { + manifest: { author: "Cynosphere, janeptrv", name: "osu! Typing", - desc: "Adds typing sounds from osu!." + description: "Adds typing sounds from osu!." }, start: function(){ var sounds = []; diff --git a/plugins/sailboat.js b/plugins/sailboat.js index b3638b7..7ef72f2 100644 --- a/plugins/sailboat.js +++ b/plugins/sailboat.js @@ -1,7 +1,7 @@ -exports.meta = { - author: "BlockBuilder57, Cynosphere", +exports.manifest = { + author: "Adryd, BlockBuilder57, Cynosphere", name: "Sailboat", - desc: "Login as bot accounts." + description: "Login as bot accounts." } exports.replacements = { '/i.default.Store.pauseEmittingChanges\\(\\),t.user.bot/':'false', diff --git a/plugins/settingsapi.js b/plugins/settingsapi.js new file mode 100644 index 0000000..af99e61 --- /dev/null +++ b/plugins/settingsapi.js @@ -0,0 +1,217 @@ +//Stolen from StackOverflow :^) +let convertToText = function(obj) { + var string = []; + + if (obj == undefined) { + return String(obj); + } else if (typeof(obj) == "object" && (obj.join == undefined)) { + for (prop in obj) { + if (obj.hasOwnProperty(prop)) + string.push(prop + ": " + convertToText(obj[prop])); + }; + return "{" + string.join(",") + "}"; + } else if (typeof(obj) == "object" && !(obj.join == undefined)) { + for(prop in obj) { + string.push(convertToText(obj[prop])); + } + return "[" + string.join(",") + "]"; + } else if (typeof(obj) == "function") { + string.push(obj.toString()) + } else { + string.push(JSON.stringify(obj)) + } + + return string.join(","); +} + +exports = { + manifest: { + author: "Cynosphere, BlockBuilder57", + name: "Settings API", + description: "Hijack the settings menu in any way you feel." + }, + replacements: { + '/function z\\(\\){return\\[{(.+)}]}/':'window.$settingsapi={sections:[{$1}]};function z(){return window.$settingsapi.sections;}', + }, + start: function(){ + var buttons = $api.util.findFuncExports('button-', 'colorBlack'); + var checkboxes = $api.util.findFuncExports('checkboxEnabled'); + var misc = $api.util.findFuncExports('statusRed-', 'inputDefault'); + var misc2 = $api.util.findFuncExports('multiInputField'); + var headers = $api.util.findFuncExports('h5-', 'h5'); + + var panels = wc.findFunc('flexChild-')[0].exports; + var panels2 = $api.util.findFuncExports('errorMessage-', 'inputWrapper'); + + let sections = window.$settingsapi.sections; + + window.$settingsapi = { + sections: sections, + ourSections: [], + _callbacks: {}, + _panels: {}, + addSection: function(name,label,callback,color){ + let data = {}; + + data.section = name || `SAPI_${Math.floor(Math.random()*10000)}`; + data.label = label; + data.color = color || undefined; + data.element = $api.util.findConstructor('FormSection', 'FormSection').FormSection; + + $settingsapi.ourSections.push(data); + $settingsapi.sections.splice($settingsapi.sections.length-4,0,data); + $settingsapi._callbacks[name] = callback; + }, + exportSections: function(){ + let out = ""; + + for(i in $settingsapi._sections){ + out = out + convertToText($settingsapi._sections[i]); + } + + return out; + }, + //All of these allow us to use Discord's elements. + elements: { + createVerticalPanel: function() { + return createElement("div") + .withClass(panels2.vertical, 'epButtonPanel') + }, + createHorizontalPanel: function() { + return createElement("div") + .withClass(panels.horizontal, 'epButtonPanel') + }, + createButton: function(name) { + return createElement('button') + .withContents(name) + .withClass( + buttons.button, + buttons.lookFilled, + buttons.colorBrand, + buttons.sizeSmall, + buttons.grow, + 'epMargin' + ); + }, + createWarnButton: function(name) { + return createElement('button') + .withContents(name) + .withClass( + buttons.button, + buttons.lookOutlined, + buttons.colorYellow, + buttons.sizeSmall, + buttons.grow, + 'epMargin' + ); + }, + createDangerButton: function(name) { + return createElement('button') + .withContents(name) + .withClass( + buttons.button, + buttons.lookOutlined, + buttons.colorRed, + buttons.sizeSmall, + buttons.grow, + 'epMargin' + ); + }, + createH2: function(text) { + return createElement("h2") + .withClass( + headers.h2, + headers.title, + headers.size16, + headers.height20, + headers.weightSemiBold, + headers.defaultColor, + 'epMargin' + ) + .withText(text); + }, + createH5: function(text) { + return createElement("h5") + .withClass( + headers.h5, + headers.title, + headers.size12, + headers.height16, + headers.weightSemiBold + ) + .withText(text); + }, + createInput: function(v) { + return createElement("input") + .withClass( + misc.inputDefault, + misc.input, + misc.size16, + 'epMargin' + ) + .modify(x => x.value = v) + }, + updateSwitch: function(s, w) { + if (s.checked) { + w.classList.remove(checkboxes.valueUnchecked.split(' ')[0]); + w.classList.add(checkboxes.valueChecked.split(' ')[0]) + } + else { + w.classList.remove(checkboxes.valueChecked.split(' ')[0]); + w.classList.add(checkboxes.valueUnchecked.split(' ')[0]) + } + }, + createSwitch: function(c, i) { + if (c === undefined) c = () => { }; + if (i === undefined) i = false; + var s, w = createElement('div') + .withClass( + checkboxes.switch, + checkboxes.switchEnabled, + checkboxes.size, + checkboxes.sizeDefault, + checkboxes.themeDefault + ) + .withChildren( + s = createElement("input") + .withClass( + checkboxes.checkbox, + checkboxes.checkboxEnabled + ) + .modify(x => x.type = 'checkbox') + .modify(x => x.checked = i) + .modify(x => x.onchange = () => { + updateSwitch(s, w); + c(s.checked); + }) + ) + $settingsapi.elements.updateSwitch(s, w); + return w; + } + } + } + + //Example settings tab + /*$settingsapi.addSection("TESTING","test owo",function(pnl){ + $settingsapi.elements.createH2("Hello World!").appendTo(pnl); + });*/ + + $api.events.hook("USER_SETTINGS_MODAL_SET_SECTION", function(e){ + if ($settingsapi._panels[e.section]) $settingsapi._panels[e.section].remove(); + + for(let i in $settingsapi.ourSections){ + let data = $settingsapi.ourSections[i]; + if(e.section == data.section){ + var pane = $(".content-column.default"); + if (!pane) return; + + $settingsapi._panels[data.section] = createElement('div') + .withClass('flex-vertical') + .appendTo(pane); + + $settingsapi._callbacks[data.section]($settingsapi._panels[data.section]); + } + } + }); + } +} \ No newline at end of file diff --git a/plugins/spotifyspoof.js b/plugins/spotifyspoof.js index 6457fbf..4fbd472 100644 --- a/plugins/spotifyspoof.js +++ b/plugins/spotifyspoof.js @@ -1,8 +1,8 @@ exports = { - meta: { + manifest: { author: "Cynosphere", name: "Spotify Premium Spoof", - desc: "Spoofs premium check and allows listen along without premium." + description: "Spoofs premium check and allows listen along without premium." }, replacements: { 'r.isPremium=n':'r.isPremium=true'