AoG Notifications

Notification script for Arena of Glory

目前为 2022-01-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name AoG Notifications
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Notification script for Arena of Glory
  6. // @author Xortrox
  7. // @match https://play.arenaofglory.io/*
  8. // @icon https://play.arenaofglory.io/favicon.ico
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (async function() {
  14. const icon = 'https://play.arenaofglory.io/favicon.ico';
  15. const gameTitle = 'Arena of Glory';
  16.  
  17. /** How frequently to scan for changes on the website (in milliseconds) */
  18. const notifyTimerInterval = 60000;
  19.  
  20. await hasPermission();
  21.  
  22. setInterval(() => {
  23. const notificationElements = document.querySelectorAll('.adventure-done-component .go-button-wrapper .button label');
  24.  
  25. /** We send notification only once if any adventures are claimable */
  26. if (notificationElements && notificationElements.length > 0) {
  27. for (let element of notificationElements) {
  28. const text = element.innerText;
  29.  
  30. const textLower = text.toLowerCase();
  31. if (textLower.includes('claim') && !textLower.includes('claimed')) {
  32. notify('You have at least one adventure to claim');
  33. }
  34. break;
  35. }
  36. }
  37. }, notifyTimerInterval);
  38.  
  39. function notify(text) {
  40. hasPermission().then(function (result) {
  41. if (result === true) {
  42. let popup = new window.Notification(gameTitle, { body: text, icon: icon });
  43. popup.onclick = function () {
  44. window.focus();
  45. }
  46. }
  47. });
  48. }
  49.  
  50. function hasPermission() {
  51. return new Promise(function (resolve) {
  52. if ('Notification' in window) {
  53. if (window.Notification.permission === 'granted') {
  54. resolve(true);
  55. } else {
  56. window.Notification.requestPermission().then(function (permission) {
  57. if (permission === 'granted') {
  58. resolve(true);
  59. } else {
  60. resolve(false);
  61. }
  62. });
  63. }
  64. } else {
  65. resolve(true);
  66. }
  67. });
  68. }
  69. })();