From 5132b05c617294a0eff0bf1be33e7a393bf1f4d9 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Thu, 3 Jan 2019 19:49:09 -0500 Subject: [PATCH] fix for emote issues --- .eslintrc | 6 ++++-- .gitignore | 5 ++++- js/main.js | 41 ++++++++++++++++++++++------------------- js/main.min.js | 2 +- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/.eslintrc b/.eslintrc index 30ce44fe..20410b7a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,7 +6,8 @@ "jquery": true }, "parserOptions": { - "ecmaVersion": 8 + "ecmaVersion": 8, + "sourceType": "module" }, "rules": { "semi": 2, @@ -36,6 +37,7 @@ "version": false, "_bdhash": true, "ace": false, - "Reflect": false + "Reflect": false, + "DiscordNative": false } } \ No newline at end of file diff --git a/.gitignore b/.gitignore index b512c09d..98f97486 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -node_modules \ No newline at end of file +node_modules +src +webpack.config.js +current.js \ No newline at end of file diff --git a/js/main.js b/js/main.js index 0a73dde3..edf14d09 100644 --- a/js/main.js +++ b/js/main.js @@ -631,11 +631,7 @@ window.bdEmoteSettingIDs = { BTTV2: "bda-es-2" }; -function EmoteModule() {} - -EmoteModule.prototype.init = async function () { - this.modifiers = ["flip", "spin", "pulse", "spin2", "spin3", "1spin", "2spin", "3spin", "tr", "bl", "br", "shake", "shake2", "shake3", "flap"]; - this.overrides = ["twitch", "bttv", "ffz"]; +function EmoteModule() { Object.defineProperty(this, "categories", { get: function() { const cats = []; @@ -645,11 +641,16 @@ EmoteModule.prototype.init = async function () { return cats; } }); +} + +EmoteModule.prototype.init = async function () { + this.modifiers = ["flip", "spin", "pulse", "spin2", "spin3", "1spin", "2spin", "3spin", "tr", "bl", "br", "shake", "shake2", "shake3", "flap"]; + this.overrides = ["twitch", "bttv", "ffz"]; let emoteInfo = { TwitchGlobal: { url: "https://twitchemotes.com/api_cache/v3/global.json", - backup: "https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotedata_twitch_global.json", + backup: `https://rauenzi.github.io/BetterDiscordApp/data/emotedata_twitch_global.json`, variable: "TwitchGlobal", oldVariable: "emotesTwitch", getEmoteURL: (e) => `https://static-cdn.jtvnw.net/emoticons/v1/${e.id}/1.0`, @@ -657,7 +658,7 @@ EmoteModule.prototype.init = async function () { }, TwitchSubscriber: { url: "https://twitchemotes.com/api_cache/v3/subscriber.json", - backup: "https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotedata_twitch_subscriber.json", + backup: `https://rauenzi.github.io/BetterDiscordApp/data/emotedata_twitch_subscriber.json`, variable: "TwitchSubscriber", oldVariable: "subEmotesTwitch", parser: (data) => { @@ -678,7 +679,7 @@ EmoteModule.prototype.init = async function () { getOldData: (url) => url.match(/\/([0-9]+)\//)[1] }, FrankerFaceZ: { - url: "https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotedata_ffz.json", + url: `https://rauenzi.github.io/BetterDiscordApp/data/emotedata_ffz.json`, variable: "FrankerFaceZ", oldVariable: "emotesFfz", getEmoteURL: (e) => `https://cdn.frankerfacez.com/emoticon/${e}/1`, @@ -700,7 +701,7 @@ EmoteModule.prototype.init = async function () { getOldData: (url) => url }, BTTV2: { - url: "https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotedata_bttv.json", + url: `https://rauenzi.github.io/BetterDiscordApp/data/emotedata_ffz.json`, variable: "BTTV2", oldVariable: "emotesBTTV2", getEmoteURL: (e) => `https://cdn.betterttv.net/emote/${e}/1x`, @@ -879,7 +880,7 @@ EmoteModule.prototype.downloadEmotes = function(emoteMeta) { timeout: emoteMeta.timeout ? emoteMeta.timeout : 5000 }; - Utils.log("Emotes", "Downloading: " + emoteMeta.variable); + Utils.log("Emotes", `Downloading: ${emoteMeta.variable} (${emoteMeta.url})`); return new Promise((resolve, reject) => { request(options, (error, response, body) => { @@ -899,7 +900,7 @@ EmoteModule.prototype.downloadEmotes = function(emoteMeta) { parsedData = JSON.parse(body); } catch (err) { - Utils.err("Emotes", "Could not download " + emoteMeta.variable, error); + Utils.err("Emotes", "Could not download " + emoteMeta.variable, err); if (emoteMeta.backup) { emoteMeta.url = emoteMeta.backup; emoteMeta.backup = null; @@ -925,7 +926,7 @@ EmoteModule.prototype.downloadEmotes = function(emoteMeta) { EmoteModule.prototype.getBlacklist = function () { return new Promise(resolve => { - $.getJSON("https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotefilter.json", function (data) { + $.getJSON(`https://rauenzi.github.io/BetterDiscordApp/data/emotefilter.json`, function (data) { resolve(bemotes = data.blacklist); }); }); @@ -978,7 +979,7 @@ function QuickEmoteMenu() { } QuickEmoteMenu.prototype.init = function() { - + this.initialized = true; $(document).on("mousedown", function(e) { if (e.target.id != "rmenu") $("#rmenu").remove(); }); @@ -1099,6 +1100,7 @@ QuickEmoteMenu.prototype.switchQem = function(id) { }; QuickEmoteMenu.prototype.obsCallback = function (elem) { + if (!this.initialized) return; var e = $(elem); if (!settingsCookie["bda-es-9"]) { e.addClass("bda-qme-hidden"); @@ -4303,12 +4305,13 @@ class V2_PublicServers { } render() { - let root = this.root; - if (!root) { - console.log("FAILED TO LOCATE ROOT: .layers"); - return; - } - BDV2.reactDom.render(this.component, root); + BdApi.alert("Broken", "Sorry but the Public Servers modules is currently broken, I recommend disabling this feature for now."); + // let root = this.root; + // if (!root) { + // console.log("FAILED TO LOCATE ROOT: .layers"); + // return; + // } + // BDV2.reactDom.render(this.component, root); } get button() { diff --git a/js/main.min.js b/js/main.min.js index c9850f5c..13678ed3 100644 --- a/js/main.min.js +++ b/js/main.min.js @@ -52,4 +52,4 @@ - `),o=[a(e),a(t)];n.find(".tab-bar-item").on("click",t=>{t.preventDefault(),n.find(".tab-bar-item").removeClass("selected"),$(t.target).addClass("selected"),n.find(".scroller").empty().append(o[$(t.target).index()])}),n.find(".footer button").on("click",()=>{n.addClass("closing"),setTimeout(()=>{n.remove()},300)}),n.find(".bd-backdrop").on("click",()=>{n.addClass("closing"),setTimeout(()=>{n.remove()},300)}),n.appendTo("#app-mount"),e.length?n.find(".tab-bar-item")[0].click():n.find(".tab-bar-item")[1].click()},Core.prototype.showToast=function(e,t={}){if(!bdConfig.deferLoaded)return;if(!document.querySelector(".bd-toasts")){let e=document.createElement("div");e.classList.add("bd-toasts");let t=document.querySelector(".chat-3bRxxu form, #friends, .noChannel-Z1DQK7, .activityFeed-28jde9");e.style.setProperty("left",t?t.getBoundingClientRect().left+"px":"0px"),e.style.setProperty("width",t?t.offsetWidth+"px":"100%"),e.style.setProperty("bottom",(document.querySelector(".chat-3bRxxu form")?document.querySelector(".chat-3bRxxu form").offsetHeight:80)+"px"),document.querySelector(".app").appendChild(e)}const{type:a="",icon:n=!0,timeout:o=3e3}=t;let s=document.createElement("div");s.classList.add("bd-toast"),a&&s.classList.add("toast-"+a),a&&n&&s.classList.add("icon"),s.innerText=e,document.querySelector(".bd-toasts").appendChild(s),setTimeout(()=>{s.classList.add("closing"),setTimeout(()=>{s.remove(),document.querySelectorAll(".bd-toasts .bd-toast").length||document.querySelector(".bd-toasts").remove()},300)},o)},window.emotesFfz={},window.emotesBTTV={},window.emotesBTTV2={},window.emotesTwitch={},window.subEmotesTwitch={},window.bdEmotes={TwitchGlobal:{},TwitchSubscriber:{},BTTV:{},FrankerFaceZ:{},BTTV2:{}},window.bdEmoteSettingIDs={TwitchGlobal:"bda-es-7",TwitchSubscriber:"bda-es-7",BTTV:"bda-es-2",FrankerFaceZ:"bda-es-1",BTTV2:"bda-es-2"};function EmoteModule(){}EmoteModule.prototype.init=async function(){this.modifiers=["flip","spin","pulse","spin2","spin3","1spin","2spin","3spin","tr","bl","br","shake","shake2","shake3","flap"],this.overrides=["twitch","bttv","ffz"],Object.defineProperty(this,"categories",{get:function(){const e=[];for(const t in window.bdEmoteSettingIDs)settingsCookie[window.bdEmoteSettingIDs[t]]&&e.push(t);return e}});let e={TwitchGlobal:{url:"https://twitchemotes.com/api_cache/v3/global.json",backup:"https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotedata_twitch_global.json",variable:"TwitchGlobal",oldVariable:"emotesTwitch",getEmoteURL:t=>`https://static-cdn.jtvnw.net/emoticons/v1/${t.id}/1.0`,getOldData:(e,t)=>({id:e.match(/\/([0-9]+)\//)[1],code:t,emoticon_set:0,description:null})},TwitchSubscriber:{url:"https://twitchemotes.com/api_cache/v3/subscriber.json",backup:"https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotedata_twitch_subscriber.json",variable:"TwitchSubscriber",oldVariable:"subEmotesTwitch",parser:e=>{let t={};for(let a in e){let n=e[a];for(let a,o=0,e=n.emotes.length;oe,getEmoteURL:t=>`https://static-cdn.jtvnw.net/emoticons/v1/${t}/1.0`,getOldData:e=>e.match(/\/([0-9]+)\//)[1]},FrankerFaceZ:{url:"https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotedata_ffz.json",variable:"FrankerFaceZ",oldVariable:"emotesFfz",getEmoteURL:t=>`https://cdn.frankerfacez.com/emoticon/${t}/1`,getOldData:e=>e.match(/\/([0-9]+)\//)[1]},BTTV:{url:"https://api.betterttv.net/emotes",variable:"BTTV",oldVariable:"emotesBTTV",parser:t=>{let a={};for(let n,o=0,e=t.emotes.length;o`${t}`,getOldData:e=>e},BTTV2:{url:"https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotedata_bttv.json",variable:"BTTV2",oldVariable:"emotesBTTV2",getEmoteURL:t=>`https://cdn.betterttv.net/emote/${t}/1x`,getOldData:e=>e.match(/emote\/(.+)\//)[1]}};for(await this.getBlacklist(),await this.loadEmoteData(e);!BDV2.MessageContentComponent;)await new Promise(e=>setTimeout(e,100));this.cancelEmoteRender||(this.cancelEmoteRender=Utils.monkeyPatch(BDV2.MessageContentComponent.prototype,"render",{after:({returnValue:e})=>{Utils.monkeyPatch(e.props,"children",{silent:!0,after:({returnValue:e})=>{if(0!=this.categories.length){const t=e.props.children[1];if(t.props.children){const e=t.props.children[1];if(e&&e.length){for(let t=0;ti.length||bemotes.includes(i))continue;this.modifiers.includes(l)&&settingsCookie["bda-es-8"]||(l=""),this.overrides.includes(d)?l=d:d="";let c=this.categories[a];if("twitch"===d?window.bdEmotes.TwitchGlobal[i]?c="TwitchGlobal":window.bdEmotes.TwitchSubscriber[i]&&(c="TwitchSubscriber"):"bttv"===d?window.bdEmotes.BTTV[i]?c="BTTV":window.bdEmotes.BTTV2[i]&&(c="BTTV2"):"ffz"===d&&window.bdEmotes.FrankerFaceZ[i]&&(c="FrankerFaceZ"),!window.bdEmotes[c][i]||!settingsCookie[window.bdEmoteSettingIDs[c]])continue;const m=e[t].match(new RegExp(`([\\s]|^)${Utils.escape(l?i+":"+l:i)}([\\s]|$)`));if(!m)continue;const p=e[t].substring(0,m.index+m[1].length),u=e[t].substring(m.index+m[0].length-m[2].length);e[t]=p;const h=BDV2.react.createElement(BDEmote,{name:i,url:window.bdEmotes[c][i],modifier:l});e.splice(t+1,0,u),e.splice(t+1,0,h)}}const t=e.every(e=>"string"==typeof e&&""==e.replace(/\s*/,"")||!!(e.type&&"BDEmote"==e.type.name)||!!(e.props&&e.props.children&&e.props.children.props&&e.props.children.props.emojiName));if(t)for(let t of e)"object"==typeof t&&("BDEmote"==t.type.name?t.props.jumboable=!0:t.props&&t.props.children&&t.props.children.props&&t.props.children.props.emojiName&&(t.props.children.props.jumboable=!0))}}}}})}}))},EmoteModule.prototype.disable=function(){this.disableAutoCapitalize();this.cancelEmoteRender||(this.cancelEmoteRender(),this.cancelEmoteRender=null)},EmoteModule.prototype.clearEmoteData=async function(){let e=require("fs"),t=bdConfig.dataPath+"emote_data.json",a=e.existsSync(t);a&&e.unlinkSync(t),DataStore.setBDData("emoteCacheDate",new Date().toJSON()),window.bdEmotes={TwitchGlobal:{},TwitchSubscriber:{},BTTV:{},FrankerFaceZ:{},BTTV2:{}}},EmoteModule.prototype.goBack=async function(t){for(let a in t)for(let e in window.bdEmotes[t[a].variable])window[t[a].oldVariable][e]=t[a].getOldData(window.bdEmotes[t[a].variable][e],e)},EmoteModule.prototype.isCacheValid=function(){const e=new Date(DataStore.getBDData("emoteCacheDate")||null),t=new Date,a=Math.round(Math.abs((t.getTime()-e.getTime())/86400000));return!(a>bdConfig.cache.days)||(DataStore.setBDData("emoteCacheDate",t.toJSON()),!1)},EmoteModule.prototype.loadEmoteData=async function(t){const a=require("fs"),n=bdConfig.dataPath+"emote_data.json",o=a.existsSync(n);if(o&&this.isCacheValid()){settingsCookie["fork-ps-2"]&&mainCore.showToast("Loading emotes from cache.",{type:"info"}),Utils.log("Emotes","Loading emotes from local cache.");const o=await new Promise(e=>{a.readFile(n,"utf8",(t,a)=>{Utils.log("Emotes","Emotes loaded from cache."),t&&(a={}),e(a)})});let s=Utils.testJSON(o);for(const a in s&&(window.bdEmotes=JSON.parse(o)),t)s=0setTimeout(e,1e3));let e=await this.downloadEmotes(t[a]);window.bdEmotes[t[a].variable]=e}settingsCookie["fork-ps-2"]&&mainCore.showToast("All emotes successfully downloaded.",{type:"success"});try{a.writeFileSync(n,JSON.stringify(window.bdEmotes),"utf8")}catch(e){Utils.err("Emotes","Could not save emote data.",e)}}},EmoteModule.prototype.downloadEmotes=function(e){let t=require("request"),a={url:e.url,timeout:e.timeout?e.timeout:5e3};return Utils.log("Emotes","Downloading: "+e.variable),new Promise((n,o)=>{t(a,(t,a,s)=>{if(t)return Utils.err("Emotes","Could not download "+e.variable,t),e.backup?(e.url=e.backup,e.backup=null,e.backupParser&&(e.parser=e.backupParser),n(this.downloadEmotes(e))):o({});let r={};try{r=JSON.parse(s)}catch(a){return Utils.err("Emotes","Could not download "+e.variable,t),e.backup?(e.url=e.backup,e.backup=null,e.backupParser&&(e.parser=e.backupParser),n(this.downloadEmotes(e))):o({})}for(let n in"function"==typeof e.parser&&(r=e.parser(r)),r){if(4>n.length||bemotes.includes(n)){delete r[n];continue}r[n]=e.getEmoteURL(r[n])}n(r),Utils.log("Emotes","Downloaded: "+e.variable)})})},EmoteModule.prototype.getBlacklist=function(){return new Promise(e=>{$.getJSON("https://cdn.staticaly.com/gh/rauenzi/BetterDiscordApp/master/data/emotefilter.json",function(t){e(bemotes=t.blacklist)})})};var bemotes=[];EmoteModule.prototype.autoCapitalize=function(){!settingsCookie["bda-es-4"]||this.autoCapitalizeActive||($("body").on("keyup.bdac change.bdac paste.bdac",$(".channelTextArea-1LDbYG textarea:first"),()=>{var e=$(".channelTextArea-1LDbYG textarea:first").val();if(null!=e){var t=e.split(" ").pop();if(3",t+=" ",t+=" ",t+="