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