Fix 24 hour and add react instance stuff
This commit is contained in:
parent
43f99ac617
commit
28174e59c9
|
@ -194,7 +194,7 @@
|
|||
"OMGG",
|
||||
"OMGGG",
|
||||
"OneShot",
|
||||
"OPieOP",
|
||||
"OPieOP",
|
||||
"osu!",
|
||||
"Overlord",
|
||||
"OVERWATCH",
|
||||
|
@ -279,6 +279,7 @@
|
|||
"Twink",
|
||||
"Tyrael",
|
||||
"Uhhh",
|
||||
"Ulgrim",
|
||||
"Vayne",
|
||||
"vogel",
|
||||
"Voli",
|
||||
|
|
44
js/main.js
44
js/main.js
|
@ -369,6 +369,25 @@ Core.prototype.initObserver = function () {
|
|||
Core.prototype.inject24Hour = function(node) {
|
||||
if (!settingsCookie["bda-gs-6"]) return;
|
||||
|
||||
node.querySelectorAll('.timestamp').forEach(elem => {
|
||||
if (elem.getAttribute("data-24")) return;
|
||||
elem.setAttribute("data-24", true);
|
||||
let text = elem.innerText || elem.textContent;
|
||||
let matches = /([^0-9]*)([0-9]?[0-9]:[0-9][0-9])([^0-9]*)/.exec(text);
|
||||
if(matches == null) return;
|
||||
if(matches.length < 4) return;
|
||||
|
||||
let time = utils.getReactProperty(elem, "return.return.return.return.memoizedProps.message.timestamp._d");
|
||||
let hours = ("0" + time.getHours()).slice(-2);
|
||||
let minutes = ("0" + time.getMinutes()).slice(-2);
|
||||
|
||||
elem.innerText = matches[1] + hours + ":" + minutes + matches[3];
|
||||
});
|
||||
};
|
||||
|
||||
Core.prototype.inject24HourOld = function(node) {
|
||||
if (!settingsCookie["bda-gs-6"]) return;
|
||||
|
||||
node.querySelectorAll('.timestamp').forEach(elem => {
|
||||
if (elem.getAttribute("data-24")) return;
|
||||
elem.setAttribute("data-24", true);
|
||||
|
@ -1067,6 +1086,21 @@ Utils.prototype.err = function (message, error) {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// Edited version of getReactInstance by noodlebox/samogot
|
||||
Utils.prototype.getReactInstance = function(node) {
|
||||
if (!(node instanceof jQuery) && !(node instanceof Element)) return undefined;
|
||||
var domNode = node instanceof jQuery ? node[0] : node;
|
||||
return domNode[Object.keys(domNode).find(key => key.startsWith("__reactInternalInstance"))];
|
||||
};
|
||||
|
||||
Utils.prototype.getReactProperty = function(node, path) {
|
||||
var value = path.split(/\s?\.\s?/).reduce(function(obj, prop) {
|
||||
return obj && obj[prop];
|
||||
}, this.getReactInstance(node));
|
||||
return value;
|
||||
};
|
||||
|
||||
/* BetterDiscordApp VoiceMode JavaScript
|
||||
* Version: 1.0
|
||||
* Author: Jiiks | http://jiiks.net
|
||||
|
@ -1369,6 +1403,16 @@ BdApi.showToast = function(content, options = {}) {
|
|||
mainCore.showToast(content, options);
|
||||
};
|
||||
|
||||
//Gets the react instance of an element
|
||||
BdApi.getReactInstance = function(element) {
|
||||
return utils.getReactInstance(element);
|
||||
};
|
||||
|
||||
//Gets a react property safely avoiding accessing properties of undefined
|
||||
BdApi.getReactProperty = function(element, propertyPath) {
|
||||
return utils.getReactProperty(element, propertyPath);
|
||||
};
|
||||
|
||||
/* BetterDiscordApp DevMode JavaScript
|
||||
* Version: 1.0
|
||||
* Author: Jiiks | http://jiiks.net
|
||||
|
|
Loading…
Reference in New Issue