From 2250bf1a8e8f530963c1bd09a37e83c7d5d0200d Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Tue, 13 Feb 2018 02:49:11 -0500 Subject: [PATCH] backwards support for emote plugins --- .gitattributes | 1 - .gitignore | 17 ----------------- js/main.js | 33 +++++++++++++++++++++++++++------ js/main.min.js | 2 +- package.json | 13 ------------- 5 files changed, 28 insertions(+), 38 deletions(-) delete mode 100644 .gitattributes delete mode 100644 .gitignore delete mode 100644 package.json diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index a77ae3e0..00000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.sh text=auto \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 4c9d65ed..00000000 --- a/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -.idea/* -*.name -devjs/.idea/devjs.iml -*.bak -*.bak.* -*.xpi -Firefox/data/js/jquery-2.1.4.min.js -*.dev.* -/nbproject/private/ -node_modules -.sass-cache -/*.jiiks -Installers/dotNet/bin/ -Installers/dotNet/packages/ -Installers/dotNet/dlls/ -v2/dist/vendor/ -v2/lib/static.js \ No newline at end of file diff --git a/js/main.js b/js/main.js index 4d9891f9..334f7a7f 100644 --- a/js/main.js +++ b/js/main.js @@ -654,19 +654,22 @@ function EmoteModule() {} EmoteModule.prototype.init = function () { this.modifiers = ["flip", "spin", "pulse", "spin2", "spin3", "1spin", "2spin", "3spin", "tr", "bl", "br", "shake", "shake2", "shake3", "flap"]; this.overrides = ['twitch', 'bttv', 'ffz']; - this.categories = Object.keys(window.bdEmoteSettingIDs); + this.categories = ["TwitchGlobal", "TwitchSubscriber", "BTTV", "FrankerFaceZ", "BTTV2"]; let emoteInfo = { 'TwitchGlobal': { url: 'https://twitchemotes.com/api_cache/v3/global.json', backup: "https://" + bdConfig.updater.CDN + '/' + bdConfig.repo + '/BetterDiscordApp/' + bdConfig.hash + '/data/emotedata_twitch_global.json', variable: 'TwitchGlobal', - getEmoteURL: (e) => `https://static-cdn.jtvnw.net/emoticons/v1/${e.id}/1.0` + oldVariable: 'emotesTwitch', + getEmoteURL: (e) => `https://static-cdn.jtvnw.net/emoticons/v1/${e.id}/1.0`, + getOldData: (url, name) => { return {id: url.match(/\/([0-9]+)\//)[1], code: name, emoticon_set: 0, description: null} } }, 'TwitchSubscriber': { url: 'https://twitchemotes.com/api_cache/v3/subscriber.json', backup: "https://" + bdConfig.updater.CDN + '/' + bdConfig.repo + '/BetterDiscordApp/' + bdConfig.hash + '/data/emotedata_twitch_subscriber.json', variable: 'TwitchSubscriber', + oldVariable: 'subEmotesTwitch', parser: (data) => { let emotes = {}; for (let c in data) { @@ -678,16 +681,20 @@ EmoteModule.prototype.init = function () { } return emotes; }, - getEmoteURL: (e) => `https://static-cdn.jtvnw.net/emoticons/v1/${e}/1.0` + getEmoteURL: (e) => `https://static-cdn.jtvnw.net/emoticons/v1/${e}/1.0`, + getOldData: (url) => url.match(/\/([0-9]+)\//)[1] }, 'FrankerFaceZ': { url: "https://" + bdConfig.updater.CDN + '/' + bdConfig.repo + '/BetterDiscordApp/' + bdConfig.hash + '/data/emotedata_ffz.json', variable: 'FrankerFaceZ', - getEmoteURL: (e) => `https://cdn.frankerfacez.com/emoticon/${e}/1` + oldVariable: "emotesFfz", + getEmoteURL: (e) => `https://cdn.frankerfacez.com/emoticon/${e}/1`, + getOldData: (url) => url.match(/\/([0-9]+)\//)[1] }, 'BTTV': { url: 'https://api.betterttv.net/emotes', variable: 'BTTV', + oldVariable: "emotesBTTV", parser: (data) => { let emotes = {}; for (let e = 0, len = data.emotes.length; e < len; e++) { @@ -696,12 +703,15 @@ EmoteModule.prototype.init = function () { } return emotes; }, - getEmoteURL: (e) => `${e}` + getEmoteURL: (e) => `${e}`, + getOldData: (url) => url }, 'BTTV2': { url: "https://" + bdConfig.updater.CDN + '/' + bdConfig.repo + '/BetterDiscordApp/' + bdConfig.hash + '/data/emotedata_bttv.json', variable: 'BTTV2', - getEmoteURL: (e) => `https://cdn.betterttv.net/emote/${e}/1x` + oldVariable: "emotesBTTV2", + getEmoteURL: (e) => `https://cdn.betterttv.net/emote/${e}/1x`, + getOldData: (url) => url.match(/emote\/(.+)\//)[1] } }; @@ -742,6 +752,14 @@ EmoteModule.prototype.clearEmoteData = async function() { } }; +EmoteModule.prototype.goBack = async function(emoteInfo) { + for (let e in emoteInfo) { + for (let emote in bdEmotes[emoteInfo[e].variable]) { + window[emoteInfo[e].oldVariable][emote] = emoteInfo[e].getOldData(bdEmotes[emoteInfo[e].variable][emote], emote) + } + } +} + EmoteModule.prototype.loadEmoteData = async function(emoteInfo) { let _fs = require("fs"); let emoteFile = "emote_data.json"; @@ -763,6 +781,7 @@ EmoteModule.prototype.loadEmoteData = async function(emoteInfo) { } if (isValid) { + await this.goBack(emoteInfo) mainCore.showToast("Emotes successfully loaded.", {type: "success"}) return; } @@ -778,6 +797,8 @@ EmoteModule.prototype.loadEmoteData = async function(emoteInfo) { bdEmotes[emoteInfo[e].variable] = data; } + await this.goBack(emoteInfo) + mainCore.showToast("All emotes successfully downloaded.", {type: "success"}); try { _fs.writeFileSync(file, JSON.stringify(bdEmotes), "utf8"); } diff --git a/js/main.min.js b/js/main.min.js index cb0c8a26..ce7f312e 100644 --- a/js/main.min.js +++ b/js/main.min.js @@ -49,4 +49,4 @@ - `),r=[a(bdpluginErrors),a(bdthemeErrors)];s.find(".tab-bar-item").on("click",o=>{o.preventDefault(),s.find(".tab-bar-item").removeClass("selected"),$(o.target).addClass("selected"),s.find(".scroller").empty().append(r[$(o.target).index()])}),s.find(".footer button").on("click",()=>{s.addClass("closing"),setTimeout(()=>{s.remove()},300)}),s.find(".bd-backdrop").on("click",()=>{s.addClass("closing"),setTimeout(()=>{s.remove()},300)}),s.appendTo("#app-mount"),s.find(".tab-bar-item")[0].click()}},Core.prototype.showToast=function(a,s={}){if(!document.querySelector(".bd-toasts")){let l=document.createElement("div");l.classList.add("bd-toasts");let u=document.querySelector(".chat form, #friends, .noChannel-2EQ0a9, .activityFeed-HeiGwL");l.style.setProperty("left",u?u.getBoundingClientRect().left+"px":"0px"),l.style.setProperty("width",u?u.offsetWidth+"px":"100%"),l.style.setProperty("bottom",(document.querySelector(".chat form")?document.querySelector(".chat form").offsetHeight:80)+"px"),document.querySelector(".app").appendChild(l)}const{type:r="",icon:o=!0,timeout:n=3e3}=s;let d=document.createElement("div");d.classList.add("bd-toast"),r&&d.classList.add("toast-"+r),r&&o&&d.classList.add("icon"),d.innerText=a,document.querySelector(".bd-toasts").appendChild(d),setTimeout(()=>{d.classList.add("closing"),setTimeout(()=>{d.remove(),document.querySelectorAll(".bd-toasts .bd-toast").length||document.querySelector(".bd-toasts").remove()},300)},n)};var emotesFfz={},emotesBTTV={},emotesBTTV2={},emotesTwitch={},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=function(){this.modifiers=["flip","spin","pulse","spin2","spin3","1spin","2spin","3spin","tr","bl","br","shake","shake2","shake3","flap"],this.overrides=["twitch","bttv","ffz"],this.categories=Object.keys(window.bdEmoteSettingIDs);let a={TwitchGlobal:{url:"https://twitchemotes.com/api_cache/v3/global.json",backup:"https://"+bdConfig.updater.CDN+"/"+bdConfig.repo+"/BetterDiscordApp/"+bdConfig.hash+"/data/emotedata_twitch_global.json",variable:"TwitchGlobal",getEmoteURL:s=>`https://static-cdn.jtvnw.net/emoticons/v1/${s.id}/1.0`},TwitchSubscriber:{url:"https://twitchemotes.com/api_cache/v3/subscriber.json",backup:"https://"+bdConfig.updater.CDN+"/"+bdConfig.repo+"/BetterDiscordApp/"+bdConfig.hash+"/data/emotedata_twitch_subscriber.json",variable:"TwitchSubscriber",parser:s=>{let r={};for(let o in s){let n=s[o];for(let u,d=0,l=n.emotes.length;d`https://static-cdn.jtvnw.net/emoticons/v1/${s}/1.0`},FrankerFaceZ:{url:"https://"+bdConfig.updater.CDN+"/"+bdConfig.repo+"/BetterDiscordApp/"+bdConfig.hash+"/data/emotedata_ffz.json",variable:"FrankerFaceZ",getEmoteURL:s=>`https://cdn.frankerfacez.com/emoticon/${s}/1`},BTTV:{url:"https://api.betterttv.net/emotes",variable:"BTTV",parser:s=>{let r={};for(let d,o=0,n=s.emotes.length;o`${s}`},BTTV2:{url:"https://"+bdConfig.updater.CDN+"/"+bdConfig.repo+"/BetterDiscordApp/"+bdConfig.hash+"/data/emotedata_bttv.json",variable:"BTTV2",getEmoteURL:s=>`https://cdn.betterttv.net/emote/${s}/1x`}};if(!bdConfig.newLoader){for(let s in window.bdEmotes={TwitchGlobal:emotesTwitch,TwitchSubscriber:subEmotesTwitch,BTTV:emotesBTTV,FrankerFaceZ:emotesFfz,BTTV2:emotesBTTV2},window.bdEmotes)for(let r in window.bdEmotes[s])window.bdEmotes[s][r]=a[s].getEmoteURL(window.bdEmotes[s][r]);return}this.loadEmoteData(a)},EmoteModule.prototype.clearEmoteData=async function(){let a=require("fs"),r=bdConfig.dataPath+"emote_data.json",o=a.existsSync(r);o&&a.unlinkSync(r),window.bdEmotes={TwitchGlobal:{},TwitchSubscriber:{},BTTV:{},FrankerFaceZ:{},BTTV2:{}}},EmoteModule.prototype.loadEmoteData=async function(a){let s=require("fs"),o=bdConfig.dataPath+"emote_data.json",n=s.existsSync(o);if(n&&!bdConfig.cache.expired){mainCore.showToast("Loading emotes from cache.",{type:"info"}),utils.log("[Emotes] Loading emotes from local cache.");let d=s.readFileSync(o,"utf8"),l=this.testJSON(d);for(let u in l&&(bdEmotes=JSON.parse(d)),a)l=0{s(r,(d,l,u)=>{if(d){if(utils.err("[Emotes] Could not download "+a.variable,d),a.backup)return a.url=a.backup,a.backup=null,this.downloadEmotes(a);n({})}else{let h=JSON.parse(u);for(let g in"function"==typeof a.parser&&(h=a.parser(h)),h)h[g]=a.getEmoteURL(h[g]);o(h),utils.log("[Emotes] Downloaded: "+a.variable)}})})},EmoteModule.prototype.testJSON=function(a){try{JSON.parse(a);return!0}catch(s){return!1}return!1},EmoteModule.prototype.getBlacklist=function(){$.getJSON("https://cdn.rawgit.com/Jiiks/betterDiscordApp/"+_hash+"/data/emotefilter.json",function(a){bemotes=a.blacklist})},EmoteModule.prototype.obsCallback=function(a){for(var o,s=this,r=0;rf.length)){if(this.modifiers.includes(y)&&settingsCookie["bda-es-8"]||(y=""),this.overrides.includes(k)||(k=""),"twitch"===k){let S=!1,T=!1;if(S=l("TwitchGlobal",f,k),S||(T=l("TwitchSubscriber",f,k)),S||T)continue}else if("bttv"===k){let S=!1,T=!1;if(S=l("BTTV",f,k),S||(T=l("BTTV2",f,k)),S||T)continue}else if("ffz"===k){let S=l("FrankerFaceZ",f,k);if(S)continue}for(let S=0,T=this.categories.length;S\""+n+"\"").replace(/﷙/g,"")},EmoteModule.prototype.autoCapitalize=function(){var a=this;$("body").delegate($(".channelTextArea-1HTP3C textarea:first"),"keyup change paste",function(){if(settingsCookie["bda-es-4"]){var s=$(".channelTextArea-1HTP3C textarea:first").val();if(void 0!=s){var r=s.split(" ").pop();if(3",s+=" ",s+=" ",s+="