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