gateway.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Gateway Connector</title>
  6. </head>
  7. <body>
  8. <h1>Use this to connect to the gateway.</h1>
  9. <p>
  10. Once you put in your token, and click connect, it will connect, and then let you know when you can close the
  11. browser. After that, you should be good to go.
  12. </p>
  13. <form id="form">
  14. <input type="text" name="token" placeholder="token" id="token"/>
  15. <input type="submit" value="Connect"/>
  16. </form>
  17. <script type="application/javascript">
  18. var element = document.getElementById('form');
  19. element.addEventListener('submit', function(event) {
  20. event.preventDefault();
  21. submitForm();
  22. return false;
  23. });
  24. function submitForm() {
  25. var TOKEN = document.getElementById('token').value;
  26. var ws = new WebSocket("wss://gateway.discord.gg/?encoding=json&v=6");
  27. ws.onopen = function() {return console.log("OPEN!")};
  28. ws.onerror = console.error.bind(console);
  29. ws.onclose = console.error.bind(console);
  30. ws.onmessage = function(a) {
  31. try {
  32. var b = JSON.parse(a.data);
  33. if (0 === b.op) {
  34. return;
  35. }
  36. if (b.op === 10) {
  37. ws.send(JSON.stringify({
  38. op: 2,
  39. d: {
  40. token: TOKEN,
  41. properties: {$browser: "Restcord Gateway Connect"}
  42. }
  43. }));
  44. alert('You can close this tab/window now.');
  45. ws.close();
  46. }
  47. } catch (a) {console.error(a)}
  48. };
  49. }
  50. </script>
  51. </body>
  52. </html>