Open xDashh opened 8 years ago
Basically this is about bbdgg-ifying the backlog for now.
I was testing a bit, and it seems like everything we need is in place. The only thing I can't figure out is when exactly the addon is loaded. If I hook into the onMSG function, only messages are intercepted that are sent after the backlog is loaded, even though messages in the backlog are put into chat via the same function. Is it possible that the addon loads only after chat has connected?
For reference, here the backlog is loaded https://github.com/destinygg/website/blob/master/static/chat/js/chat.js#L135 and rendered via the onMSG
, onMUTE
, onXXX
functions.
Sample code here intercepts only messages that are sent after this is already done.
var fnBack = destiny.chat.onMSG;
destiny.chat.onMSG = function(line){
console.error(line);
return fnBack.apply(this, arguments);
};
Any ideas @BryceMatthes @KenanY ?
@xDashh Currently (on Chrome at least),
the browser chooses a time to inject scripts between "document_end" and immediately after the
window.onload
event fires. The exact moment of injection depends on how complex the document is and how long it is taking to load, and is optimized for page load speed.https://developer.chrome.com/extensions/content_scripts#registration
Seems indeterministic, but what's probably happening is that our addon is loading shortly after the backlog has already been rendered. One solution to this is to load the addon before any other script is executed:
index c177257..fe08519 100755
--- a/chrome/manifest.json
+++ b/chrome/manifest.json
@@ -28,7 +28,8 @@
"matches": ["*://*.destiny.gg/embed/chat*"],
"css": ["betterdgg.css"],
"js": ["betterdgg.js","lib/panscroll.js"],
- "all_frames":true
+ "all_frames":true,
+ "run_at": "document_start"
}
],
But this might cause problems because destiny.chat
won't even exist yet so it's just gonna override all of our new functions anyways. Furthermore, since we would now be running before the DOM is loaded, we will be unable to change anything on the page, like adding the Aslan icon, until after the page is done rendering (this will require new code to be written to ensure that we do not attempt page modifications like this before page has loaded).
An ideal solution would be one wherein the addon executes after DOM is loaded (so that we can safely make changes to it as we do now and so that destiny.chat.onMSG
exists and can be overwritten) but before backlog is dispatched, but I can't see any way of accomplishing that.
Thanks for the explanation! I agree that what you described last would be ideal, but probably not (easily, or at all) doable.
An acceptable "workaround" might be to retroactively modify the lines in the chatlog, which I will look into now, if noone else has any better ideas.
Now with #70 the last step would be to take a look at each "/"-command and menu-checkbox and apply their effects immediately as well (good example is passivestalk). Should be doable pretty easily in most cases.
When (re-)loading the chat, betterdgg "effects"/changes are not applied to anything in the history (anything above the line that says "Connecting..."). For example, put an emote in chat, reload, and you will only see the text in the place of the emote. This applies to betterdgg emotes only.
A similar problem goes for e.g. (un)ticking the "hide all flairs" option. It will only be applied to new, incoming messages.
Both problems could probably be addressed by a "general" rewrite of how messages are handled. All those effects should be applied on the chat itself instead of hooking into the handle function of incoming messages, if possible.