//META{"name":"evenBetterRepo"}*//
var evenBetterRepo = function(){};
/* Information */
evenBetterRepo.prototype.getName = function(){
return 'Even Better Repo';
};
evenBetterRepo.prototype.getDescription = function(){
return 'Easily access theme & plugin repository from within Discord client
Want to add your plugin or theme? Submit a request here:
https://github.com/IRDeNial/BD-Even-Better-Repo/issues/new';
};
evenBetterRepo.prototype.getVersion = function(){
return '2.5.4';
};
evenBetterRepo.prototype.getAuthor = function(){
return 'DeNial';
};
// OS Specific
var theme_path;
var plugin_path;
var ebr_changelog;
// API Hooks
evenBetterRepo.prototype.load = function(){
if (process.platform == "win32") {
this.themePath = process.env.APPDATA + "\\BetterDiscord\\themes\\";
this.pluginPath = process.env.APPDATA + "\\BetterDiscord\\plugins\\";
} else if (process.platform == "linux"){
this.themePath= process.env.HOME + "/.config/BetterDiscord/themes/";
this.pluginPath= process.env.HOME + "/.config/BetterDiscord/plugins/";
} else if (process.platform == "darwin"){
this.themePath = process.env.HOME + "/Library/Preferences/BetterDiscord/themes/";
this.pluginPath = process.env.HOME + "/Library/Preferences/BetterDiscord/plugins/";
}
this.cssURL = 'https://raw.githubusercontent.com/IRDeNial/BD-Even-Better-Repo/master/ebr.css';
this.repoURL = 'https://raw.githubusercontent.com/IRDeNial/BD-Even-Better-Repo/master/repo.json';
this.pluginURL = 'https://raw.githubusercontent.com/IRDeNial/BD-Even-Better-Repo/master/evenBetterRepo.plugin.js';
this.versionURL = 'https://raw.githubusercontent.com/IRDeNial/BD-Even-Better-Repo/master/version';
this.ebrCSS = '';
this.repo = '';
this.useHTTP = false;
this.settingsAreaLoaded = false;
theme_path = this.themePath;
plugin_path = this.pluginPath;
plugin_url = this.pluginURL;
version_url = this.versionURL;
current_version = this.getVersion();
this.getChangelog = function(){
require('request').get('https://raw.githubusercontent.com/IRDeNial/BD-Even-Better-Repo/master/CHANGELOG.md',(error,response,body)=>{
if(!error) {
ebr_changelog = body.replace(/(\r\n|\n\r|\r|\n)/g, '
');
}
});
};
this.autoUpdate = function(){
var version = current_version;
require('request').get(version_url,(error,response,body)=>{
if(!error) {
if(version != body) {
if(confirm('There is an update for EvenBetterRepo. Would you like to update now?')) {
require('https').get(plugin_url, function(response) {
var file = require('fs').createWriteStream(plugin_path + 'evenBetterRepo.plugin.js');
response.pipe(file);
file.on('finish', function() {
file.close();
console.log("EvenBetterRepo plugin updated. Press OK to reload discord");
alert("EvenBetterRepo plugin updated. Press OK to reload discord");
document.location.reload();
});
}).on('error', function(err) {
console.log("Error updating EvenBetterRepo plugin: " + err);
alert("Error updating EvenBetterRepo plugin: " + err);
});
}
}
}
});
};
this.getCSS = function(){
require("request").get(this.cssURL,(error,response,body)=>{
if(!error) {
this.ebrCSS = body;
BdApi.injectCSS("ebr-css",this.ebrCSS);
}
});
};
this.getRepo = function(){
require("request").get(this.repoURL,(error,response,body)=>{
if(error) {
this.repo = JSON.parse('{"error": "Could not get repo"}');
} else {
this.repo = JSON.parse(body.trim());
}
});
};
this.doesFileExist = function(filePath) {
try{
require('fs').accessSync(filePath);
return true;
} catch(e) {
return false;
}
};
this.isThemeInstalled = function(url){
var themeName = url.substr(url.lastIndexOf('/') + 1);
if(this.doesFileExist(this.themePath + themeName)) {
return 1;
} else {
return 0;
}
};
this.isPluginInstalled = function(url) {
var pluginName = url.substr(url.lastIndexOf('/') + 1);
if(this.doesFileExist(this.pluginPath + pluginName)) {
return 1;
} else {
return 0;
}
};
this.populateThemes = function(){
var themes = this.repo.themes;
for(var i = 0;i < this.repo.themes.length;++i) {
let themeInfo = $("
", {"class": "name", text: themes[i].name})) .append($("
", {"class": "author", text: themes[i].author})) .append($("
", {"class": "description", text: themes[i].description})) .appendTo(themeInfo); if(this.isThemeInstalled(themes[i].url)) { $("