OWoT online and offline

Tells if someone goes online or offline (if they have this script).

当前为 2023-03-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name OWoT online and offline
  3. // @namespace https://greasyfork.org/scripts/458537-owot-online-and-offline
  4. // @version 8
  5. // @description Tells if someone goes online or offline (if they have this script).
  6. // @author e_g.
  7. // @match https://ourworldoftext.com/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. let warn = true;
  13. let counter = 0;
  14. let amityping = false;
  15.  
  16. //Part made by KKosty4ka
  17. var chat_upper = document.getElementById("chat_upper");
  18. chat_upper.appendChild(document.createElement("br"));
  19. var typing_display = chat_upper.appendChild(document.createElement("span"));
  20. //Part made by KKosty4ka
  21.  
  22. menu.addCheckboxOption('Online Offline warning', function(){
  23. warn = true;
  24. }, function(){
  25. warn = false;
  26. }, true);
  27.  
  28. w.broadcastReceive(true);
  29. w.on('cmd', function(e){
  30. if(!e.username || !warn) return;
  31. if(e.data.startsWith('online')){
  32. clientChatResponse(e.username + " is online!");
  33. }
  34. else if(e.data.startsWith('offline')){
  35. clientChatResponse(e.username + " is now offline.");
  36. }
  37. else if(e.data.startsWith('back')){
  38. clientChatResponse(e.username + " is back.");
  39. }
  40. else if(e.data.startsWith('afk')){
  41. clientChatResponse(e.username + " is AFK. (Idle)");
  42. }
  43. else if(e.data.startsWith('typing')){
  44. typing_display.innerText = e.username + " is typing...";
  45. }
  46. else if(e.data.startsWith('untyping')){
  47. typing_display.innerText = "Currently, no one is typing";
  48. console.log(e.username)
  49. };
  50. });
  51.  
  52. setTimeout(function(){
  53. w.broadcastCommand('online', true);
  54. }, 1000);
  55.  
  56. window.addEventListener('beforeunload', function(){
  57. w.broadcastCommand('offline', true)
  58. });
  59.  
  60. window.onblur = function(){w.broadcastCommand('afk', true)};
  61.  
  62. window.onfocus = function(){w.broadcastCommand('back', true)};
  63.  
  64. elm.chatbar.oninput = function(){
  65. counter = 0;
  66. amityping = !!elm.chatbar.value.length;
  67. if(amityping) w.broadcastCommand('typing', true);
  68. };
  69.  
  70. setInterval(function(){
  71. counter += 100;
  72. if(counter >= 5000 && amityping){
  73. w.broadcastCommand('untyping', true);
  74. amityping = false;
  75. };
  76. }, 100);