mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-15 16:10:32 +03:00
Remove unused functions and delete scr.utils.js
This commit is contained in:
parent
35183fd270
commit
226b3702de
@ -4,14 +4,29 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
GUI.onFileUploaded(files => {
|
||||
if (files.length === 1){
|
||||
UTILS.readJsonFile(files[0], (obj, file) => {
|
||||
var file = files[0];
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function(){
|
||||
var obj;
|
||||
|
||||
try{
|
||||
obj = JSON.parse(reader.result);
|
||||
}catch(e){
|
||||
console.error(e);
|
||||
alert("Could not parse '"+file.name+"', see console for details.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (SAVEFILE.isValid(obj)){
|
||||
STATE.uploadFile(new SAVEFILE(obj));
|
||||
}
|
||||
else{
|
||||
alert((obj ? "File '{}' has an invalid format." : "Could not parse '{}', see console for details.").replace("{}", file.name));
|
||||
alert("File '"+file.name+"' has an invalid format.");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
reader.readAsText(file, "UTF-8");
|
||||
}
|
||||
else{
|
||||
alert("Please, select only one file.");
|
||||
|
@ -38,14 +38,6 @@ SAVEFILE.prototype.getUserById = function(user){
|
||||
return this.meta.users[user] || { "name": user };
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.getAllMessages = function(){
|
||||
var messages = {};
|
||||
|
||||
UTILS.forEachValue(this.data, messageObject => {
|
||||
UTILS.combineObjects(messages, messageObject);
|
||||
});
|
||||
|
||||
return messages;
|
||||
SAVEFILE.prototype.getUserIndex = function(user){
|
||||
return this.meta.userindex.indexOf(user);
|
||||
};
|
||||
|
@ -8,10 +8,10 @@ var STATE = (function(){
|
||||
var FILE;
|
||||
var MSGS;
|
||||
|
||||
var filterFunction;
|
||||
var selectedChannel;
|
||||
var currentPage;
|
||||
var messagesPerPage;
|
||||
var filterFunction;
|
||||
|
||||
// ----------------------------------
|
||||
// Channel and message refresh events
|
||||
@ -66,10 +66,6 @@ var STATE = (function(){
|
||||
ROOT.getUserName = function(user){
|
||||
return FILE.getUserById(user).name;
|
||||
};
|
||||
|
||||
ROOT.getRawMessages = function(channel){
|
||||
return channel ? FILE.getMessages(channel) : FILE.getAllMessages();
|
||||
};
|
||||
|
||||
// --------------------------
|
||||
// Channel list and selection
|
||||
|
@ -1,51 +0,0 @@
|
||||
var UTILS = {
|
||||
/*
|
||||
* Reads a file object and converts the JSON-formatted contents to a JS object. The callback accepts the parsed object (or null on failure), and the original file object.
|
||||
*/
|
||||
readJsonFile: function(file, callback){
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function(){
|
||||
var obj;
|
||||
|
||||
try{
|
||||
obj = JSON.parse(reader.result);
|
||||
}catch(e){
|
||||
console.error(e);
|
||||
callback(null, file);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(obj, file);
|
||||
};
|
||||
|
||||
reader.readAsText(file, "UTF-8");
|
||||
},
|
||||
|
||||
/*
|
||||
* Runs the callback with a key and value for each entry in an object.
|
||||
*/
|
||||
forEachEntry: function(object, callback){
|
||||
for(var key of Object.keys(object)){
|
||||
callback(key, object[key]);
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Runs the callback for each value in an object.
|
||||
*/
|
||||
forEachValue: function(object, callback){
|
||||
for(var key of Object.keys(object)){
|
||||
callback(object[key]);
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Adds all entries from the source object to the target object.
|
||||
*/
|
||||
combineObjects: function(target, source){
|
||||
for(var key of Object.keys(source)){
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user