Fix DM tracking broken by a recent update

Closes #45
This commit is contained in:
chylex 2018-09-19 14:33:42 +02:00
parent aec0c93f25
commit 3ca345b26f

View File

@ -71,35 +71,35 @@ var DISCORD = (function(){
getSelectedChannel: function(){ getSelectedChannel: function(){
try{ try{
var obj; var obj;
var channelListEle = document.querySelector("[class|='privateChannels']");
var channelListEle = DOM.fcls("private-channels");
var channel;
if (channelListEle){ if (channelListEle){
channel = DOM.fcls("selected", channelListEle); var channel = DOM.queryReactClass("selected", channelListEle);
if (!channel.classList.contains("private")){ if (!channel){
return null; return null;
} }
var linkSplit = DOM.ftag("a", channel).href.split("/"); var linkSplit = channel.querySelector("a[href*='/@me/']").href.split("/");
var name = [].find.call(DOM.fcls("channel-name", channel).childNodes, node => node.nodeType === Node.TEXT_NODE).nodeValue; var link = linkSplit[linkSplit.length-1];
if (!name){ if (!(/^\d+$/.test(link))){
return null; return null;
} }
var name = [].find.call(channel.querySelector("[class|='name']").childNodes, node => node.nodeType === Node.TEXT_NODE).nodeValue;
obj = { obj = {
"server": name, "server": name,
"channel": name, "channel": name,
"id": linkSplit[linkSplit.length-1], "id": link,
"type": !!DOM.fcls("status", channel) ? "DM" : "GROUP" "type": !!DOM.queryReactClass("status", channel) ? "DM" : "GROUP"
}; };
} }
else{ else{
channelListEle = document.querySelector("[class|='channels']"); channelListEle = document.querySelector("[class|='channels']");
channel = channelListEle.querySelector("[class|='wrapperSelectedText']").parentElement;
var channel = channelListEle.querySelector("[class|='wrapperSelectedText']").parentElement;
var props = DISCORD.getReactProps(channel); var props = DISCORD.getReactProps(channel);
if (!props){ if (!props){
@ -171,17 +171,17 @@ var DISCORD = (function(){
* Selects the next text channel and returns true, otherwise returns false if there are no more channels. * Selects the next text channel and returns true, otherwise returns false if there are no more channels.
*/ */
selectNextTextChannel: function(){ selectNextTextChannel: function(){
var dms = DOM.fcls("private-channels"); var dms = document.querySelector("[class|='privateChannels']");
if (dms){ if (dms){
var nextChannel = DOM.fcls("selected", dms).nextElementSibling; var nextChannel = DOM.queryReactClass("selected", dms).nextElementSibling;
var classes = nextChannel && nextChannel.classList; var nextLink = nextChannel && nextChannel.querySelector("a[href*='/@me/']");
if (nextChannel === null || !classes.contains("channel") || !classes.contains("private")){ if (!nextChannel || !nextLink || !nextChannel.getAttribute("class").includes("channel-")){
return false; return false;
} }
else{ else{
DOM.ftag("a", nextChannel).click(); nextLink.click();
return true; return true;
} }
} }