mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-14 23:50:33 +03:00
Reimplement uglifyjs prop mangling
This commit is contained in:
parent
c2f0134cf8
commit
ed68136e25
12
build.py
12
build.py
@ -7,13 +7,17 @@ import sys
|
||||
import os
|
||||
|
||||
|
||||
# TODO readd mangle: --mangle --mangle-props --reserve-domprops --reserved-file reserve.txt
|
||||
EXEC_UGLIFYJS = "{2}/lib/uglifyjs.cmd --parse bare_returns --compress --output \"{1}\" \"{0}\""
|
||||
EXEC_UGLIFYJS = "{2}/lib/uglifyjs.cmd --parse bare_returns --compress --mangle toplevel --mangle-props keep_quoted,reserved=[{3}] --output \"{1}\" \"{0}\""
|
||||
EXEC_YUI = "java -jar lib/yuicompressor-2.4.8.jar --charset utf-8 --line-break 160 --type css -o \"{1}\" \"{0}\""
|
||||
|
||||
USE_UGLIFYJS = "--nominify" not in sys.argv
|
||||
USE_JAVA = shutil.which("java") is not None and "--nominify" not in sys.argv
|
||||
|
||||
WORKING_DIR = os.getcwd()
|
||||
|
||||
with open("reserve.txt", "r") as reserved:
|
||||
RESERVED_PROPS = ",".join(line.strip() for line in reserved.readlines())
|
||||
|
||||
|
||||
def combine_files(input_pattern, output_file):
|
||||
with fileinput.input(sorted(glob.glob(input_pattern))) as stream:
|
||||
@ -38,7 +42,7 @@ def build_tracker():
|
||||
out.write("})()")
|
||||
|
||||
if USE_UGLIFYJS:
|
||||
os.system(EXEC_UGLIFYJS.format(output_file_raw, output_file_tmp, os.getcwd()))
|
||||
os.system(EXEC_UGLIFYJS.format(output_file_raw, output_file_tmp, WORKING_DIR, RESERVED_PROPS))
|
||||
|
||||
with open(output_file_raw, "w") as out:
|
||||
out.write("javascript:(function(){")
|
||||
@ -85,7 +89,7 @@ def build_renderer():
|
||||
combine_files(input_js_pattern, out)
|
||||
|
||||
if USE_UGLIFYJS:
|
||||
os.system(EXEC_UGLIFYJS.format(tmp_js_file_combined, tmp_js_file_minified, os.getcwd()))
|
||||
os.system(EXEC_UGLIFYJS.format(tmp_js_file_combined, tmp_js_file_minified, WORKING_DIR, RESERVED_PROPS))
|
||||
else:
|
||||
shutil.copyfile(tmp_js_file_combined, tmp_js_file_minified)
|
||||
|
||||
|
63
reserve.txt
63
reserve.txt
@ -1,40 +1,23 @@
|
||||
{
|
||||
"vars": [],
|
||||
"props": [
|
||||
"autoscroll",
|
||||
"_autoscroll",
|
||||
"afterFirstMsg",
|
||||
"_afterFirstMsg",
|
||||
"afterSavedMsg",
|
||||
"_afterSavedMsg",
|
||||
"enableImagePreviews",
|
||||
"_enableImagePreviews",
|
||||
"enableFormatting",
|
||||
"_enableFormatting",
|
||||
"meta",
|
||||
"data",
|
||||
"users",
|
||||
"userindex",
|
||||
"servers",
|
||||
"channels",
|
||||
"name",
|
||||
"type",
|
||||
"server",
|
||||
"u",
|
||||
"t",
|
||||
"m",
|
||||
"f",
|
||||
"e",
|
||||
"a",
|
||||
"id",
|
||||
"user",
|
||||
"msgcount",
|
||||
"timestamp",
|
||||
"contents",
|
||||
"&",
|
||||
"<",
|
||||
">",
|
||||
"'",
|
||||
"\""
|
||||
]
|
||||
}
|
||||
autoscroll
|
||||
_autoscroll
|
||||
afterFirstMsg
|
||||
_afterFirstMsg
|
||||
afterSavedMsg
|
||||
_afterSavedMsg
|
||||
enableImagePreviews
|
||||
_enableImagePreviews
|
||||
enableFormatting
|
||||
_enableFormatting
|
||||
DHT_LOADED
|
||||
meta
|
||||
data
|
||||
users
|
||||
userindex
|
||||
servers
|
||||
channels
|
||||
u
|
||||
t
|
||||
m
|
||||
f
|
||||
e
|
||||
a
|
@ -126,8 +126,8 @@ var DISCORD = (function(){
|
||||
var sliced = attachment.url.split("/");
|
||||
|
||||
return templateEmbedDownload.apply({
|
||||
url: attachment.url,
|
||||
filename: sliced[sliced.length-1]
|
||||
"url": attachment.url,
|
||||
"filename": sliced[sliced.length-1]
|
||||
});
|
||||
}
|
||||
}).join("");
|
||||
|
@ -13,7 +13,7 @@ SAVEFILE.isValid = function(parsedObj){
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.getServer = function(index){
|
||||
return this.meta.servers[index] || { name: "<unknown>", type: "ERROR" };
|
||||
return this.meta.servers[index] || { "name": "<unknown>", "type": "ERROR" };
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.getChannels = function(){
|
||||
@ -21,15 +21,15 @@ SAVEFILE.prototype.getChannels = function(){
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.getChannelById = function(channel){
|
||||
return this.meta.channels[channel] || { id: channel, name: channel };
|
||||
return this.meta.channels[channel] || { "id": channel, "name": channel };
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.getUser = function(index){
|
||||
return this.meta.users[this.meta.userindex[index]] || { name: "<unknown>" };
|
||||
return this.meta.users[this.meta.userindex[index]] || { "name": "<unknown>" };
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.getUserById = function(user){
|
||||
return this.meta.users[user] || { name: user };
|
||||
return this.meta.users[user] || { "name": user };
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.getMessageCount = function(channel){
|
||||
|
@ -67,11 +67,11 @@ var STATE = (function(){
|
||||
ROOT.getChannelList = function(){
|
||||
var channels = FILE.getChannels();
|
||||
|
||||
return Object.keys(channels).map(key => ({ // reserve.txt
|
||||
id: key,
|
||||
name: channels[key].name,
|
||||
server: FILE.getServer(channels[key].server),
|
||||
msgcount: FILE.getMessageCount(key)
|
||||
return Object.keys(channels).map(key => ({
|
||||
"id": key,
|
||||
"name": channels[key].name,
|
||||
"server": FILE.getServer(channels[key].server),
|
||||
"msgcount": FILE.getMessageCount(key)
|
||||
}));
|
||||
};
|
||||
|
||||
@ -102,13 +102,13 @@ var STATE = (function(){
|
||||
return MSGS.slice(startIndex, !messagesPerPage ? undefined : startIndex+messagesPerPage).map(key => {
|
||||
var message = messages[key];
|
||||
|
||||
return { // reserve.txt
|
||||
user: FILE.getUser(message.u),
|
||||
timestamp: message.t,
|
||||
contents: message.m,
|
||||
embeds: message.e,
|
||||
attachments: message.a,
|
||||
edited: (message.f&1) === 1
|
||||
return {
|
||||
"user": FILE.getUser(message.u),
|
||||
"timestamp": message.t,
|
||||
"contents": message.m,
|
||||
"embeds": message.e,
|
||||
"attachments": message.a,
|
||||
"edited": (message.f&1) === 1
|
||||
};
|
||||
});
|
||||
};
|
||||
@ -167,7 +167,6 @@ var STATE = (function(){
|
||||
ROOT.settings[name] = defaultValue;
|
||||
}
|
||||
|
||||
// reserve.txt
|
||||
defineSettingProperty("enableImagePreviews", true);
|
||||
defineSettingProperty("enableFormatting", true);
|
||||
|
||||
|
@ -39,11 +39,11 @@ var DISCORD = (function(){
|
||||
var linkSplit = DOM.tag("a", channel)[0].getAttribute("href").split("/");
|
||||
var name = [].find.call(DOM.cls("channel-name", channel)[0].childNodes, node => node.nodeType === Node.TEXT_NODE).nodeValue;
|
||||
|
||||
obj = { // reserve.txt
|
||||
server: name,
|
||||
channel: name,
|
||||
id: linkSplit[linkSplit.length-1],
|
||||
type: DOM.cls("status", channel).length ? "DM" : "GROUP"
|
||||
obj = {
|
||||
"server": name,
|
||||
"channel": name,
|
||||
"id": linkSplit[linkSplit.length-1],
|
||||
"type": DOM.cls("status", channel).length ? "DM" : "GROUP"
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -58,10 +58,10 @@ var DISCORD = (function(){
|
||||
var linkSplit = DOM.tag("a", channel)[0].getAttribute("href").split("/");
|
||||
|
||||
obj = {
|
||||
server: DOM.tag("span", DOM.cls("guild-header")[0])[0].innerHTML,
|
||||
channel: DOM.cls("channel-name", DOM.cls("selected", channelListEle)[0])[0].innerHTML,
|
||||
id: linkSplit[linkSplit.length-1],
|
||||
type: "SERVER"
|
||||
"server": DOM.tag("span", DOM.cls("guild-header")[0])[0].innerHTML,
|
||||
"channel": DOM.cls("channel-name", DOM.cls("selected", channelListEle)[0])[0].innerHTML,
|
||||
"id": linkSplit[linkSplit.length-1],
|
||||
"type": "SERVER"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ var DOM = (function(){
|
||||
* Triggers a UTF-8 text file download.
|
||||
*/
|
||||
downloadTextFile: function(fileName, fileContents){
|
||||
var blob = new Blob([fileContents], { type: "octet/stream" });
|
||||
var blob = new Blob([fileContents], { "type": "octet/stream" });
|
||||
var url = window.URL.createObjectURL(blob);
|
||||
|
||||
var ele = document.createElement("a");
|
||||
|
@ -98,7 +98,7 @@ SAVEFILE.isValid = function(parsedObj){
|
||||
SAVEFILE.prototype.findOrRegisterUser = function(userId, userName){
|
||||
if (!(userId in this.meta.users)){
|
||||
this.meta.users[userId] = {
|
||||
name: userName
|
||||
"name": userName
|
||||
};
|
||||
|
||||
this.meta.userindex.push(userId);
|
||||
@ -116,9 +116,9 @@ SAVEFILE.prototype.findOrRegisterServer = function(serverName, serverType){
|
||||
var index = this.meta.servers.findIndex(server => server.name === serverName && server.type === serverType);
|
||||
|
||||
if (index === -1){
|
||||
this.meta.servers.push({ // reserve.txt
|
||||
name: serverName,
|
||||
type: serverType
|
||||
this.meta.servers.push({
|
||||
"name": serverName,
|
||||
"type": serverType
|
||||
});
|
||||
|
||||
return this.meta.servers.length-1;
|
||||
@ -136,9 +136,9 @@ SAVEFILE.prototype.tryRegisterChannel = function(serverIndex, channelId, channel
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
this.meta.channels[channelId] = { // reserve.txt
|
||||
server: serverIndex,
|
||||
name: channelName
|
||||
this.meta.channels[channelId] = {
|
||||
"server": serverIndex,
|
||||
"name": channelName
|
||||
};
|
||||
|
||||
this.tmp.channelkeys.add(channelId);
|
||||
@ -155,7 +155,7 @@ SAVEFILE.prototype.addMessage = function(channelId, messageId, messageObject){
|
||||
return !wasPresent;
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.convertToMessageObject = function(discordMessage){ // reserve.txt
|
||||
SAVEFILE.prototype.convertToMessageObject = function(discordMessage){
|
||||
var obj = {
|
||||
u: this.findOrRegisterUser(discordMessage.author.id, discordMessage.author.username),
|
||||
t: +Date.parse(discordMessage.timestamp),
|
||||
@ -180,14 +180,14 @@ SAVEFILE.prototype.convertToMessageObject = function(discordMessage){ // reserve
|
||||
|
||||
if (discordMessage.embeds.length > 0){
|
||||
obj.e = discordMessage.embeds.map(embed => ({
|
||||
url: embed.url,
|
||||
type: embed.type
|
||||
"url": embed.url,
|
||||
"type": embed.type
|
||||
}));
|
||||
}
|
||||
|
||||
if (discordMessage.attachments.length > 0){
|
||||
obj.a = discordMessage.attachments.map(attachment => ({
|
||||
url: attachment.url
|
||||
"url": attachment.url
|
||||
}));
|
||||
}
|
||||
|
||||
@ -231,8 +231,8 @@ SAVEFILE.prototype.combineWith = function(obj){
|
||||
};
|
||||
|
||||
SAVEFILE.prototype.toJson = function(){
|
||||
return JSON.stringify({ // reserve.txt
|
||||
meta: this.meta,
|
||||
data: this.data
|
||||
return JSON.stringify({
|
||||
"meta": this.meta,
|
||||
"data": this.data
|
||||
});
|
||||
};
|
||||
|
@ -28,7 +28,7 @@ var STATE = (function(){
|
||||
/*
|
||||
* Internal settings class constructor.
|
||||
*/
|
||||
var SETTINGS = function(){ // reserve.txt
|
||||
var SETTINGS = function(){
|
||||
defineTriggeringProperty(this, "setting", "autoscroll");
|
||||
defineTriggeringProperty(this, "setting", "afterFirstMsg");
|
||||
defineTriggeringProperty(this, "setting", "afterSavedMsg");
|
||||
|
@ -56,8 +56,8 @@ DISCORD.setupMessageRequestHook((channel, messages) => {
|
||||
++untrackedRequests;
|
||||
|
||||
cachedRequest = {
|
||||
channel: channel,
|
||||
messages: messages
|
||||
"channel": channel,
|
||||
"messages": messages
|
||||
};
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user