1
0
mirror of https://github.com/chylex/Discord-History-Tracker.git synced 2024-10-17 17:42:51 +02:00

Compare commits

...

3 Commits

Author SHA1 Message Date
3cca167793
Release v.31d 2022-06-19 10:34:20 +02:00
18f1ea15fa
Improve error handling and reporting when extracting message data 2022-06-19 10:24:07 +02:00
21e196f4fe
Fix not seeing messages after a Discord update
Closes #192
2022-06-19 10:20:56 +02:00
5 changed files with 59 additions and 31 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
// ==UserScript==
// @name Discord History Tracker
// @version v.31c
// @version v.31d
// @license MIT
// @namespace https://chylex.com
// @homepageURL https://dht.chylex.com/
@ -37,14 +37,24 @@ var DISCORD = (function(){
return key ? ele[key] : null;
};
var tryGetReactProps = function(ele) {
try {
return this.getReactProps(ele);
} catch (ignore) {
return null;
}
};
var getMessageElementProps = function(ele) {
const props = getReactProps(ele);
if (props.children && props.children.length >= 4) {
const childProps = props.children[3].props;
if ("message" in childProps && "channel" in childProps) {
return childProps;
if (props.children && props.children.length) {
for (let i = 3; i < props.children.length; i++) {
const childProps = props.children[i].props;
if (childProps && "message" in childProps && "channel" in childProps) {
return childProps;
}
}
}
@ -58,18 +68,22 @@ var DISCORD = (function(){
var getMessages = function() {
try {
const messages = [];
for (const ele of getMessageElements()) {
const props = getMessageElementProps(ele);
try {
const props = getMessageElementProps(ele);
if (props != null) {
messages.push(props.message);
if (props != null) {
messages.push(props.message);
}
} catch (e) {
console.error("[DHT] Error extracing message data, skipping it.", e, ele, tryGetReactProps(ele));
}
}
return messages;
} catch (e) {
console.error(e);
console.error("[DHT] Error retrieving messages.", e);
return [];
}
};
@ -637,7 +651,7 @@ ${radio("asm", "pause", "Pause Tracking")}
${radio("asm", "switch", "Switch to Next Channel")}
<p id='dht-cfg-note'>
It is recommended to disable link and image previews to avoid putting unnecessary strain on your browser.<br><br>
<sub>v.31c, released 19 May 2022</sub>
<sub>v.31d, released 19 June 2022</sub>
</p>`);
// elements

File diff suppressed because one or more lines are too long

View File

@ -8,8 +8,8 @@ import os
import re
import distutils.dir_util
VERSION_SHORT = "v.31c"
VERSION_FULL = VERSION_SHORT + ", released 19 May 2022"
VERSION_SHORT = "v.31d"
VERSION_FULL = VERSION_SHORT + ", released 19 June 2022"
EXEC_UGLIFYJS_WIN = "{2}/lib/uglifyjs.cmd --parse bare_returns --compress --mangle toplevel --mangle-props keep_quoted,reserved=[{3}] --output \"{1}\" \"{0}\""
EXEC_UGLIFYJS_AUTO = "uglifyjs --parse bare_returns --compress --mangle toplevel --mangle-props keep_quoted,reserved=[{3}] --output \"{1}\" \"{0}\""

View File

@ -23,14 +23,24 @@ var DISCORD = (function(){
return key ? ele[key] : null;
};
var tryGetReactProps = function(ele) {
try {
return this.getReactProps(ele);
} catch (ignore) {
return null;
}
};
var getMessageElementProps = function(ele) {
const props = getReactProps(ele);
if (props.children && props.children.length >= 4) {
const childProps = props.children[3].props;
if ("message" in childProps && "channel" in childProps) {
return childProps;
if (props.children && props.children.length) {
for (let i = 3; i < props.children.length; i++) {
const childProps = props.children[i].props;
if (childProps && "message" in childProps && "channel" in childProps) {
return childProps;
}
}
}
@ -44,18 +54,22 @@ var DISCORD = (function(){
var getMessages = function() {
try {
const messages = [];
for (const ele of getMessageElements()) {
const props = getMessageElementProps(ele);
try {
const props = getMessageElementProps(ele);
if (props != null) {
messages.push(props.message);
if (props != null) {
messages.push(props.message);
}
} catch (e) {
console.error("[DHT] Error extracing message data, skipping it.", e, ele, tryGetReactProps(ele));
}
}
return messages;
} catch (e) {
console.error(e);
console.error("[DHT] Error retrieving messages.", e);
return [];
}
};