Diep.io Join Notifier

Notifies when people join,leave,respawn or die using the inbuilt diep.io player list. (note: if it says {not updated} as name, they left while dead before we saw real name)

目前為 2024-03-01 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Diep.io Join Notifier
  3. // @namespace *
  4. // @version 1.1.3
  5. // @description Notifies when people join,leave,respawn or die using the inbuilt diep.io player list. (note: if it says {not updated} as name, they left while dead before we saw real name)
  6. // @author rbest
  7. // @match https://diep.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=diep.io
  9. // @license rbest
  10. // @grant none
  11. // ==/UserScript==
  12. // made by king rbest
  13. // made by king rbest
  14. // made by king rbest
  15. //toggle which notifications you want
  16. let joinNotifications = true;
  17. let dieNotifications = true;
  18. let respawnNotifications = true;
  19. let leaveNotifications = true;
  20. //dont touch this;
  21. let old = [];
  22. let bef = [];
  23. let changed = false;
  24. let oldPlayers = {};
  25. let oldNames = {};
  26. function check() {
  27. let players = window.ui.players;
  28. let players2 = {};
  29. players.forEach(player=>{
  30. players2[player.identityId] = player;
  31. })
  32. if (players) {
  33. bef = old;
  34. oldPlayers = {};
  35. bef.forEach(player=>{
  36. oldPlayers[player.identityId] = player;
  37. })
  38. old = players;
  39. if (bef===old) changed = false;
  40. if (bef!==old) changed = true;
  41. if (changed === true) {
  42. for (let player of players) {
  43. if (!oldPlayers[player.identityId]) {
  44. if (joinNotifications) notification(`${player.name} joined`);
  45. }
  46. if (oldPlayers[player.identityId]) {
  47. if (oldPlayers[player.identityId].name !== ' (dead)' && player.name === ' (dead)') {
  48. oldNames[player.identityId] = oldPlayers[player.identityId].name;
  49. if (dieNotifications) notification(`${oldPlayers[player.identityId].name} died`)
  50. }
  51. if (oldPlayers[player.identityId].name === ' (dead)' && player.name !== ' (dead)') {
  52. if (player.name === oldNames[player.identityId]) {
  53. if (respawnNotifications) notification(`${player.name} respawned`);
  54. }
  55. else if (player.name !== oldNames[player.identityId] && oldNames[player.identityId] !== undefined) {
  56. if (respawnNotifications) notification(`${player.name} (${oldNames[player.identityId]}) respawned`); //if they changed username
  57. }
  58. oldNames[player.identityId] = player.name;
  59. }
  60. }
  61. }
  62. Object.values(oldPlayers).forEach(playr=>{
  63. if (!players2[playr.identityId] && oldNames[playr.identityId] !== undefined) if (leaveNotifications) notification(`${oldNames[playr.identityId]} left`);
  64. if (!players2[playr.identityId] && oldNames[playr.identityId] === undefined) if (leaveNotifications) notification('{not updated} left');
  65. })
  66. }
  67. }
  68. }
  69. setInterval(check,100);
  70. //Modified notification code from DiepBox
  71. let notificationBody = document.body.appendChild(document.createElement('div'));
  72. notificationBody.style.pointerEvents = 'none';
  73. notificationBody.style.position = 'fixed';
  74. notificationBody.style.left = `50%`;
  75. notificationBody.style.top = `1.9%`;
  76. notificationBody.style.opacity = '0.70';
  77.  
  78. function notification(text, duration = 3500) {
  79. const button = document.createElement('button');
  80. button.innerHTML = ` ${text} `;
  81. button.style['background-color'] = '#E8B18B';
  82. button.style.display = 'block';
  83. button.style.height = '35px';
  84. button.style.border = 'none';
  85. button.style.color = 'white';
  86. button.style.fontSize = '26.2px';
  87. button.style.transform = 'translate(-50%, -1.9%)'
  88. button.addEventListener('contextmenu', (e) => e.preventDefault());
  89.  
  90. notificationBody.appendChild(button);
  91. setTimeout(() => button.remove(), duration);
  92. }
  93. // made by king rbest