Greasy Fork is available in English.

UserScript Automated Button Text Notifier

This script is intended to work with @require only. Provides class AutomatedButtonTextNotifier

Tính đến 19-01-2022. Xem phiên bản mới nhất.

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greatest.deepsurf.us/scripts/438801/1010216/UserScript%20Automated%20Button%20Text%20Notifier.js

  1. // ==UserScript==
  2. // @namespace Xortrox/UserScripts/AutomatedButtonTextNotifier
  3. // @name UserScript Automated Button Text Notifier
  4. // @version 0.1
  5. // @description This script is intended to work with @require only. Provides class AutomatedButtonTextNotifier
  6. // @author Xortrox,
  7. // @match *
  8. // @esversion: 6
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. class AutomatedButtonTextNotifier {
  13. constructor(options) {
  14. this.icon = options.icon || '';
  15. this.title = options.title || 'No Title Specified';
  16.  
  17. /** Looks for this pattern: <button class="button"><label></label></button */
  18. this.selector = options.selector;
  19.  
  20. /** How frequently to scan for changes on the website (in milliseconds) */
  21. this.notificationInterval = options.interval;
  22. this.scanConfiguration = options.config;
  23.  
  24. if (!this.selector) {
  25. this.error('Error: No selector specified for AutomatedButtonTextNotifier');
  26. }
  27. }
  28.  
  29. async init() {
  30. await window.UserScript.Notifications.askPermission();
  31.  
  32. this.interval = setInterval(this.scan, this.notificationInterval);
  33. }
  34.  
  35. scan() {
  36. const notificationElements = document.querySelectorAll(buttonSelector);
  37.  
  38. /** We send notification only once if any adventures are claimable */
  39. if (notificationElements && notificationElements.length > 0) {
  40. for (let element of notificationElements) {
  41. const text = element.innerText;
  42.  
  43. const textLower = text.toLowerCase();
  44.  
  45. for (const config of this.scanConfiguration) {
  46. let includesText = false;
  47. let excludesText = false;
  48.  
  49. for (const includeText of config.includes) {
  50. if (textLower.includes[includeText]) {
  51. includesText = true;
  52. break;
  53. }
  54. }
  55.  
  56. if (config.excludes?.length > 0) {
  57. for (const excludeText of config.includes) {
  58. if (!textLower.includes[excludeText]) {
  59. excludesText = true;
  60. break;
  61. }
  62. }
  63. }
  64.  
  65. let canShowNotification = includesText;
  66.  
  67. if (config.excludes?.length > 0) {
  68. canShowNotification = canShowNotification && excludesText;
  69. }
  70.  
  71. if (canShowNotification) {
  72. window.UserScript.Notifications.notify(this.title, config.notificationText, this.icon);
  73. break;
  74. }
  75. }
  76. }
  77. }
  78. }
  79.  
  80. error(error) {
  81. alert(error);
  82. console.error(new Error(error));
  83. }
  84. }