New Old Notifications - Neopets

Displays notifications on the new layout's nav bar. Based on the script by JustDownloadin

  1. // ==UserScript==
  2. // @name New Old Notifications - Neopets
  3. // @namespace https://greasyfork.org/en/scripts/512519-new-old-notifications-neopets
  4. // @version 1.1.1
  5. // @description Displays notifications on the new layout's nav bar. Based on the script by JustDownloadin
  6. // @author GrarrlMunch
  7. // @match *://*.neopets.com/*
  8. // @icon https://files.catbox.moe/rciqco.png
  9. // @grant none
  10. // @license GNU GPLv3
  11. // ==/UserScript==
  12.  
  13. /*
  14. Based on the "Neopets - Old Notifications" script
  15. by JustDownloadin: https://greasyfork.org/en/scripts/503653-neopets-old-notifications
  16. This script was developed with permission from the original developer
  17. */
  18.  
  19. /* globals jQuery, $, waitForKeyElements */
  20.  
  21. var index = 0;
  22. var elementsArray = Array.from(document.querySelectorAll('#alerts li'));
  23. var closeList = Array.from(document.querySelectorAll('#alertstab__2020 ul .alert-x'));
  24. var notFired = true;
  25.  
  26. function displayBarEl () { setTimeout(() => { notifBarEl(); }, 1000); }
  27.  
  28. function notifBarEl() {
  29. const iconEl = elementsArray[index].querySelector(':scope > a > div');
  30. const alertsTabComputedStyle = document.querySelector('#alertstab__2020 ul li');
  31. const alertsh4ComputedStyle = document.querySelector('#alertstab__2020 h4');
  32. const alertspComputedStyle = document.querySelector('#alertstab__2020 p');
  33. const aEle = document.querySelector('a');
  34.  
  35.  
  36. const HTMLEl = `
  37. <div class="navBarNotif">
  38. <style>
  39. @media screen and (max-width: 1569px) {
  40. .navBarNotif {
  41. width: 260px;
  42. }
  43. }
  44. @media screen and (min-width: 1570px) {
  45. .navBarNotif {
  46. width: 320px;
  47. }
  48. }
  49. @media screen and (min-width: 1570px) {
  50. .navBarNotif {
  51. width: 435px;
  52. }
  53. }
  54. @media screen and (min-width: 1860px) {
  55. .navBarNotif {
  56. width: 600px;
  57. }
  58. }
  59. .navBarNotif {
  60. box-sizing: content-box;
  61. position: absolute;
  62. left: 210px;
  63. z-index: 99;
  64. height: 60px;
  65. padding: 0 10px;
  66. font-family: 'MuseoSansRounded700', 'Arial', sans-serif;
  67. border: ${window.getComputedStyle(alertsTabComputedStyle).getPropertyValue('border')};
  68. border-radius: 10px;
  69. box-shadow: ${window.getComputedStyle(alertsTabComputedStyle).getPropertyValue('box-shadow')};
  70. -webkit-box-shadow: ${window.getComputedStyle(alertsTabComputedStyle).getPropertyValue('box-shadow')};
  71. -moz-box-shadow: ${window.getComputedStyle(alertsTabComputedStyle).getPropertyValue('box-shadow')};
  72. background-color: ${window.getComputedStyle(alertsTabComputedStyle).getPropertyValue('background-color')};
  73. }
  74. .navBarNotif h4 {
  75. color: ${window.getComputedStyle(alertsh4ComputedStyle).getPropertyValue('color')};
  76. margin-top: 3px;
  77. margin-bottom: 0;
  78. }
  79. .navBarNotif h5 {
  80. margin: 0;
  81. }
  82. .navBarNotif p {
  83. color: ${window.getComputedStyle(alertspComputedStyle).getPropertyValue('color')};
  84. margin: 2px 15px 5px auto;
  85. max-width: 555px;
  86. max-height: 15px;
  87. font-size: 10pt;
  88. overflow: hidden;
  89. white-space: nowrap;
  90. text-overflow: "...";
  91. }
  92. .navBarNotif .alert-x {
  93. position: absolute;
  94. top: 5px;
  95. right: 5px;
  96. width: 15px;
  97. height: 15px;
  98. background: url(https://images.neopets.com/themes/h5/basic/images/x-icon.svg) center center no-repeat;
  99. background-size: auto;
  100. background-size: 100%;
  101. cursor: pointer;
  102. }
  103. .navBarNotif > a > div {
  104. float: left;
  105. width: 50px;
  106. height: 50px;
  107. margin: 5px 10px 5px 0;
  108. background-image: ${window.getComputedStyle(iconEl).getPropertyValue('background-image')};
  109. background-size: 100%;
  110. background-repeat: no-repeat;
  111. background-position: center;
  112. cursor: pointer;
  113. }
  114. .hideIfSmall {
  115. cursor: pointer;
  116. color: ${window.getComputedStyle(aEle).getPropertyValue('color')};
  117. }
  118. </style>
  119. ${elementsArray[index].innerHTML}
  120. </div>
  121. `;
  122.  
  123. const seeAllAlerts = `<b> - <span class="hideIfSmall">See all alerts</span></b>`;
  124.  
  125. /*Leaving the function as-is just in case I want to re-use it...*/
  126. $.fn.extend({
  127. toggleText: function(a, b){
  128. return this.text(this.text() == b ? a : b);
  129. }
  130. });
  131.  
  132. $('.nav-top-grid__2020').prepend(HTMLEl);
  133. $('.navBarNotif h5').append(seeAllAlerts);
  134. $('.hideIfSmall').click(function(e){
  135. $('.nav-bell-icon__2020').click();
  136. $('.hideIfSmall').toggleText('See all alerts', 'Hide all alerts');
  137. e.stopPropagation();
  138. });
  139. document.querySelector('.navBarNotif .alert-x').addEventListener('click', function () {
  140. closeList[index].click();
  141. });
  142.  
  143. closeList[index].addEventListener('click', function() {
  144. $('.navBarNotif').remove();
  145. index = index + 1;
  146. ((elementsArray[index] !== undefined) && notFired) && (displayBarEl());
  147. });
  148. };
  149.  
  150. $(document).ready(function () {
  151. const viewAllComputedStyle = document.querySelector('.alerts-tab-viewall__2020');
  152.  
  153. const DelHTML = `
  154. <style type="text/css">
  155. .alerts-tab-deleteall__2020 {
  156. position: relative;
  157. width: 100%;
  158. height: 40px;
  159. background: ${window.getComputedStyle(viewAllComputedStyle).getPropertyValue('background')};
  160. }
  161. </style>
  162. <div class="alerts-tab-deleteall__2020">
  163. <div class="alerts-tab-viewclick__2020">
  164. <div class="alerts-tab-icon__2020" style="background-image: url(https://images.neopets.com/themes/046_ff_sep2017/events/warning.png);"></div>
  165. <div id="DelAllButton" class="news-dropdown-text__2020">Delete All</div>
  166. </div>
  167. </div>`;
  168.  
  169. $(DelHTML).insertBefore($('#alerts'));
  170.  
  171. document.getElementById('DelAllButton').addEventListener('click', function () {
  172. let delAllEle = document.getElementById('DelAllButton');
  173. if ((elementsArray[index] !== undefined) && notFired) {
  174. notFired = false;
  175. delAllEle.innerHTML = "Deleting...";
  176. for (let i = 0; i < closeList.length; i++) {
  177. setTimeout (() => {
  178. closeList[i].click();
  179. console.log("Closed alert " + (i + 1) + "/" + closeList.length)
  180. }, 1000 * i);
  181. var timeOutExternal = (1000 * i) + 1000;
  182. }
  183. setTimeout(() => {
  184. delAllEle.innerHTML = "Deleted!";
  185. document.querySelector('.alerts-none__2020').style.display = '';
  186. setTimeout (() => { delAllEle.innerHTML = "Delete All" }, 2500);
  187. }, timeOutExternal);
  188. } else {
  189. delAllEle.innerHTML = "No alerts to delete!";
  190. setTimeout (() => { delAllEle.innerHTML = "Delete All" }, 2500);
  191. }
  192. });
  193. });
  194.  
  195. ((elementsArray[index] !== undefined) && notFired) && (displayBarEl());