-
Notifications
You must be signed in to change notification settings - Fork 60
inital boilerplate for sharing sockets to make this effecient #249
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// ==UserScript== | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a new userscript? Can't we conjoin the two quite easily? Instead of raising an event, inject a script. We also have to think about the non-userscript scenario, the bookmarklet. From personal experience it's yet to fail me, but given that the userscript sometimes fails, maybe the bookmarklet sometimes fails too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the plan.
I just want to have @rlemon test it and make sure it works -_- |
||
// @name SO-Chat-Socket-Saver | ||
// @namespace http://awal.js.org/ | ||
// @version 0.1 | ||
// @description i dunno what to put this is a template lmao | ||
// @author awal | ||
// @match *://chat.stackoverflow.com/rooms/* | ||
// @match *://meta.chat.stackexchange.com/rooms/* | ||
// @match *://chat.stackexchange.com/rooms/* | ||
// @grant none | ||
// @run-at document-start | ||
// ==/UserScript== | ||
|
||
if (document.body) { | ||
console.warn('Socket Saver: Not properly running at document-start, setup shit properly FFS!'); | ||
} else { | ||
// we are running at document-start properly. yipee!! | ||
Object.defineProperty(WebSocket.prototype, 'onopen', { | ||
set: function (val) { | ||
if (this.url.startsWith('wss://chat.sockets.stackexchange.com')) { | ||
console.info('Socket Saver: socket saved properly, use it with window.__stackexchange_chat_saved_socket'); | ||
window.__stackexchangeChatSavedSocket = this; | ||
window.dispatchEvent(new CustomEvent('stackexchange-socket-saved')); | ||
} | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openSocket
is called (eventually) from/join
to, well, join a room. That's why there's thediscard
option...So we either fix up
/join
to do something else or changeopenSocket
or its caller to match the new behaviour.