mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-13 07:17:12 +03:00
Refactor viewer (template literals, classes, minor refactoring)
This commit is contained in:
parent
5ce4feaf89
commit
1d4479e5d2
@ -30,11 +30,6 @@ var DOM = (function(){
|
||||
*/
|
||||
fcls: (cls, parent) => (parent || document).getElementsByClassName(cls)[0],
|
||||
|
||||
/*
|
||||
* Returns the first child element that has the specified tag. Parent defaults to the entire document.
|
||||
*/
|
||||
ftag: (tag, parent) => (parent || document).getElementsByTagName(tag)[0],
|
||||
|
||||
/*
|
||||
* Creates an element, adds it to the DOM, and returns it.
|
||||
*/
|
||||
|
@ -32,10 +32,9 @@ var GUI = (function(){
|
||||
// -------------
|
||||
|
||||
var showSettingsModal = function(){
|
||||
showModal(560, [
|
||||
"<label><input id='dht-cfg-imgpreviews' type='checkbox'> Image Previews</label><br>",
|
||||
"<label><input id='dht-cfg-formatting' type='checkbox'> Message Formatting</label><br>"
|
||||
].join(""));
|
||||
showModal(560, `
|
||||
<label><input id='dht-cfg-imgpreviews' type='checkbox'> Image Previews</label><br>
|
||||
<label><input id='dht-cfg-formatting' type='checkbox'> Message Formatting</label><br>`);
|
||||
|
||||
var setupCheckBox = function(id, settingName){
|
||||
var ele = DOM.id(id);
|
||||
@ -50,16 +49,11 @@ var GUI = (function(){
|
||||
var showInfoModal = function(){
|
||||
var linkGH = "https://github.com/chylex/Discord-History-Tracker";
|
||||
|
||||
showModal(560, [
|
||||
"<p>Discord History Tracker is developed by <a href='https://chylex.com'>chylex</a> as an <a href='"+linkGH+"/blob/master/LICENSE.md'>open source</a> project.</p>",
|
||||
"<sub>BETA v.7, released 16 Feb 2018</sub>",
|
||||
"<p>Please, report any issues and suggestions to the <a href='"+linkGH+"/issues'>tracker</a>. If you want to support the development, please spread the word and consider <a href='https://www.patreon.com/chylex'>becoming a patron</a>. Any support is appreciated!</p>",
|
||||
"<p>",
|
||||
"<a href='"+linkGH+"/issues'>Issue Tracker</a> — ",
|
||||
"<a href='"+linkGH+"'>GitHub Repository</a> — ",
|
||||
"<a href='https://twitter.com/chylexmc'>Developer's Twitter</a>",
|
||||
"</p>"
|
||||
].join(""));
|
||||
showModal(560, `
|
||||
<p>Discord History Tracker is developed by <a href='https://chylex.com'>chylex</a> as an <a href='${linkGH}/blob/master/LICENSE.md'>open source</a> project.</p>
|
||||
<sub>BETA v.7, released 16 Feb 2018</sub>
|
||||
<p>Please, report any issues and suggestions to the <a href='${linkGH}/issues'>tracker</a>. If you want to support the development, please spread the word and consider <ref='https://www.patreon.com/chylex'>becoming a patron</a>. Any support is appreciated!</p>
|
||||
<p><a href='${linkGH}/issues'>Issue Tracker</a> — <a href='${linkGH}'>GitHub Repository</a> — <a href='https://twitter.com/chylexmc'>Developer's Twitter</a></p>`);
|
||||
};
|
||||
|
||||
return {
|
||||
@ -269,4 +263,4 @@ var GUI = (function(){
|
||||
DOM.id("messages").scrollTop = 0;
|
||||
}
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -1,5 +1,4 @@
|
||||
var PROCESSOR = function(messageObject){
|
||||
};
|
||||
var PROCESSOR = {};
|
||||
|
||||
// ------------------------
|
||||
// Global filter generators
|
||||
|
@ -1,47 +1,49 @@
|
||||
var SAVEFILE = function(parsedObj){
|
||||
var me = this;
|
||||
|
||||
me.meta = parsedObj.meta;
|
||||
me.meta.users = me.meta.users || {};
|
||||
me.meta.userindex = me.meta.userindex || [];
|
||||
me.meta.servers = me.meta.servers || [];
|
||||
me.meta.channels = me.meta.channels || {};
|
||||
|
||||
me.data = parsedObj.data;
|
||||
};
|
||||
class SAVEFILE{
|
||||
constructor(parsedObj){
|
||||
var me = this;
|
||||
|
||||
me.meta = parsedObj.meta;
|
||||
me.data = parsedObj.data;
|
||||
|
||||
me.meta.users = me.meta.users || {};
|
||||
me.meta.userindex = me.meta.userindex || [];
|
||||
me.meta.servers = me.meta.servers || [];
|
||||
me.meta.channels = me.meta.channels || {};
|
||||
};
|
||||
|
||||
SAVEFILE.isValid = function(parsedObj){
|
||||
return parsedObj && typeof parsedObj.meta === "object" && typeof parsedObj.data === "object";
|
||||
};
|
||||
static isValid(parsedObj){
|
||||
return parsedObj && typeof parsedObj.meta === "object" && typeof parsedObj.data === "object";
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.getServer = function(index){
|
||||
return this.meta.servers[index] || { "name": "<unknown>", "type": "ERROR" };
|
||||
};
|
||||
getServer(index){
|
||||
return this.meta.servers[index] || { "name": "<unknown>", "type": "ERROR" };
|
||||
}
|
||||
|
||||
SAVEFILE.prototype.getChannels = function(){
|
||||
return this.meta.channels;
|
||||
};
|
||||
getChannels(){
|
||||
return this.meta.channels;
|
||||
}
|
||||
|
||||
SAVEFILE.prototype.getChannelById = function(channel){
|
||||
return this.meta.channels[channel] || { "id": channel, "name": channel };
|
||||
};
|
||||
getChannelById(channel){
|
||||
return this.meta.channels[channel] || { "id": channel, "name": channel };
|
||||
}
|
||||
|
||||
SAVEFILE.prototype.getUsers = function(){
|
||||
return this.meta.users;
|
||||
};
|
||||
getUsers(){
|
||||
return this.meta.users;
|
||||
}
|
||||
|
||||
SAVEFILE.prototype.getUser = function(index){
|
||||
return this.meta.users[this.meta.userindex[index]] || { "name": "<unknown>" };
|
||||
};
|
||||
getUser(index){
|
||||
return this.meta.users[this.meta.userindex[index]] || { "name": "<unknown>" };
|
||||
}
|
||||
|
||||
SAVEFILE.prototype.getUserById = function(user){
|
||||
return this.meta.users[user] || { "name": user };
|
||||
};
|
||||
getUserById(user){
|
||||
return this.meta.users[user] || { "name": user };
|
||||
}
|
||||
|
||||
SAVEFILE.prototype.getUserIndex = function(user){
|
||||
return this.meta.userindex.indexOf(user);
|
||||
};
|
||||
getUserIndex(user){
|
||||
return this.meta.userindex.indexOf(user);
|
||||
}
|
||||
|
||||
SAVEFILE.prototype.getMessages = function(channel){
|
||||
return this.data[channel] || {};
|
||||
};
|
||||
getMessages(channel){
|
||||
return this.data[channel] || {};
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,20 @@
|
||||
var TEMPLATE_REGEX = /{([^{}]+?)}/g;
|
||||
|
||||
var TEMPLATE = function(contents){
|
||||
this.contents = contents;
|
||||
};
|
||||
class TEMPLATE{
|
||||
constructor(contents){
|
||||
this.contents = contents;
|
||||
};
|
||||
|
||||
TEMPLATE.prototype.apply = function(obj, processor){
|
||||
return this.contents.replace(TEMPLATE_REGEX, (full, match) => {
|
||||
var value = match.split(".").reduce((o, property) => o[property], obj);
|
||||
|
||||
if (processor){
|
||||
var updated = processor(match, value);
|
||||
return typeof updated === "undefined" ? DOM.escapeHTML(value) : updated;
|
||||
}
|
||||
|
||||
return DOM.escapeHTML(value);
|
||||
});
|
||||
};
|
||||
apply(obj, processor){
|
||||
return this.contents.replace(TEMPLATE_REGEX, (full, match) => {
|
||||
var value = match.split(".").reduce((o, property) => o[property], obj);
|
||||
|
||||
if (processor){
|
||||
var updated = processor(match, value);
|
||||
return typeof updated === "undefined" ? DOM.escapeHTML(value) : updated;
|
||||
}
|
||||
|
||||
return DOM.escapeHTML(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user