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 9
  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. let people = [];
  16.  
  17. //Part made by KKosty4ka
  18. var chat_upper = document.getElementById("chat_upper");
  19. chat_upper.appendChild(document.createElement("br"));
  20. var typing_display = chat_upper.appendChild(document.createElement("span"));
  21. typing_display.style.display = "flex";
  22. typing_display.style.justifyContent = "center";
  23. typing_display.style.alignItems = "center";
  24. //Part made by KKosty4ka
  25.  
  26. menu.addCheckboxOption('Online Offline warning', function(){
  27. warn = true;
  28. }, function(){
  29. warn = false;
  30. }, true);
  31.  
  32. w.broadcastReceive(true);
  33. w.on('cmd', function(e){
  34. if(!e.username || !warn) return;
  35. if(e.data.startsWith('online')){
  36. clientChatResponse(e.username + " is online!");
  37. }
  38. else if(e.data.startsWith('offline')){
  39. clientChatResponse(e.username + " is now offline.");
  40. }
  41. else if(e.data.startsWith('back')){
  42. clientChatResponse(e.username + " is back.");
  43. }
  44. else if(e.data.startsWith('afk')){
  45. clientChatResponse(e.username + " is AFK. (Idle)");
  46. }
  47. else if(e.data.startsWith('typing')){
  48. if(people.indexOf(e.username) == -1) people.push(e.username);
  49. typing_display.innerText = people.join(" and ") + " " + (people.length > 1 ? "are" : "is") + " typing...";
  50. }
  51. else if(e.data.startsWith('untyping')){
  52. people = people.filter((x, i)=>i != people.indexOf(e.username))
  53. typing_display.innerText = people.length ? people.join(" and ") + " " + (people.length > 1 ? "are" : "is") + " typing..." : "Currently, no one is typing";
  54. };
  55. });
  56.  
  57. setTimeout(function(){
  58. w.broadcastCommand('online', true);
  59. }, 1000);
  60.  
  61. window.addEventListener('beforeunload', function(){
  62. w.broadcastCommand('offline', true)
  63. });
  64.  
  65. window.onblur = function(){w.broadcastCommand('afk', true)};
  66.  
  67. window.onfocus = function(){w.broadcastCommand('back', true)};
  68.  
  69. elm.chatbar.oninput = function(e){
  70. counter = 0;
  71. amityping = !!elm.chatbar.value.length;
  72. if(amityping) w.broadcastCommand('typing', true)
  73. else w.broadcastCommand('untyping', true);
  74. };
  75.  
  76. setInterval(function(){
  77. counter += 100;
  78. if((counter >= 5000 && amityping) || !elm.chatbar.value.length){
  79. w.broadcastCommand('untyping', true);
  80. amityping = false;
  81. };
  82. }, 100);