Diep.io Join Notifier

Notifies when people join,leave,respawn or die using the inbuilt diep.io player list.

  1. // ==UserScript==
  2. // @name Diep.io Join Notifier
  3. // @namespace *
  4. // @version 1.1.6
  5. // @description Notifies when people join,leave,respawn or die using the inbuilt diep.io player list.
  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. let times = {};
  27. function toMin(millis) {
  28. var minutes = Math.floor(millis / 60000);
  29. var seconds = ((millis % 60000) / 1000).toFixed(0);
  30. return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
  31. }
  32. function check() {
  33. let players = window.ui.players;
  34. let players2 = {};
  35. players.forEach(player=>{
  36. players2[player.identityId] = player;
  37. })
  38. if (players) {
  39. bef = old;
  40. oldPlayers = {};
  41. bef.forEach(player=>{
  42. oldPlayers[player.identityId] = player;
  43. })
  44. old = players;
  45. if (bef===old) changed = false;
  46. if (bef!==old) changed = true;
  47. if (changed === true) {
  48. for (let player of players) {
  49. if (!oldPlayers[player.identityId]) {
  50. if (joinNotifications) notification(`${player.name} joined`);
  51. times[player.identityId] = {};
  52. }
  53. if (oldPlayers[player.identityId]) {
  54. if (oldPlayers[player.identityId].name !== ' (dead)' && player.name === ' (dead)') {
  55. oldNames[player.identityId] = oldPlayers[player.identityId].name;
  56. if (dieNotifications && times[player.identityId].spawnTime) notification(`${oldPlayers[player.identityId].name} died (${toMin(new Date().getTime()-times[player.identityId].spawnTime)})`)
  57. if (dieNotifications && !times[player.identityId].spawnTime) notification(`${oldPlayers[player.identityId].name} died`)
  58. }
  59. if (oldPlayers[player.identityId].name === ' (dead)' && player.name !== ' (dead)') {
  60. if (player.name === oldNames[player.identityId]) {
  61. if (respawnNotifications) notification(`${player.name} respawned`);
  62. }
  63. else if (player.name !== oldNames[player.identityId] && oldNames[player.identityId] !== undefined) {
  64. if (respawnNotifications) notification(`${player.name} (${oldNames[player.identityId]}) respawned`); //if they changed username
  65. }
  66. times[player.identityId] = {};
  67. times[player.identityId].spawnTime = new Date().getTime();
  68. oldNames[player.identityId] = player.name;
  69. }
  70. }
  71. }
  72. Object.values(oldPlayers).forEach(playr=>{
  73. if (!players2[playr.identityId] && oldNames[playr.identityId] !== undefined) if (leaveNotifications) notification(`${oldNames[playr.identityId]} left`);
  74. if (!players2[playr.identityId] && oldNames[playr.identityId] === undefined) if (leaveNotifications) notification(`${playr.name} left`);
  75. })
  76. }
  77. }
  78. }
  79. setInterval(check,100);
  80. //Modified notification code from DiepBox
  81. let notificationBody = document.body.appendChild(document.createElement('div'));
  82. notificationBody.style.pointerEvents = 'none';
  83. notificationBody.style.position = 'fixed';
  84. notificationBody.style.left = `50%`;
  85. notificationBody.style.top = `1.9%`;
  86. notificationBody.style.opacity = '0.70';
  87.  
  88. function notification(text, duration = 3500) {
  89. const button = document.createElement('button');
  90. button.innerHTML = `&nbsp;${text}&nbsp;`;
  91. button.style['background-color'] = '#E8B18B';
  92. button.style.display = 'block';
  93. button.style.height = '35px';
  94. button.style.border = 'none';
  95. button.style.color = 'white';
  96. button.style.fontSize = '26px';
  97. button.style.transform = 'translate(-50%, -1.9%)';
  98. button.addEventListener('contextmenu', (e) => e.preventDefault());
  99.  
  100. notificationBody.appendChild(button);
  101. setTimeout(()=>{
  102. button.style.transition = "opacity 250ms";
  103. button.style.opacity = "0";
  104.  
  105. setTimeout(() => button.remove(), 250);
  106. },duration);
  107. }
  108. // made by king rbest