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 7.1
  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.  
  15. menu.addCheckboxOption('Online Offline warning', function(){
  16. warn = true;
  17. }, function(){
  18. warn = false;
  19. }, true);
  20.  
  21. w.broadcastReceive(true);
  22. w.on('cmd', function(e){
  23. if(!e.username || !warn) return;
  24. if(e.data.startsWith('online')){
  25. clientChatResponse(e.username + " is online!");
  26. }
  27. else if(e.data.startsWith('offline')){
  28. clientChatResponse(e.username + " is now offline.");
  29. }
  30. else if(e.data.startsWith('back')){
  31. clientChatResponse(e.username + " is back.");
  32. }
  33. else if(e.data.startsWith('afk')){
  34. clientChatResponse(e.username + " is AFK. (Idle)");
  35. }
  36. else if(e.data.startsWith('typing')){
  37. w.doAnnounce(e.username + " is typing...");
  38. }
  39. else if(e.data.startsWith('untyping')){
  40. document.getElementsByClassName("announce_close")[0].click();
  41. };
  42. });
  43.  
  44. setTimeout(function(){
  45. w.broadcastCommand('online', true);
  46. }, 1000);
  47.  
  48. window.addEventListener('beforeunload', function(){
  49. w.broadcastCommand('offline', true)
  50. });
  51.  
  52. window.onblur = function(){w.broadcastCommand('afk', true)};
  53.  
  54. window.onfocus = function(){w.broadcastCommand('back', true)};
  55.  
  56. elm.chatbar.oninput = function(){
  57. counter = 0;
  58. };
  59.  
  60. setInterval(function(){
  61. if(elm.chatbar.value.length && counter < 5000) w.broadcastCommand('typing', true);
  62. counter += 100;
  63. if(counter >= 5000) w.broadcastCommand('untyping', true);
  64. }, 100);
  65.  
  66. w.on("chatmod", function(e){
  67. if(e.realUsername == state.userModel.username) w.broadcastCommand('untyping', true);
  68. });