Greasy Fork镜像 支持简体中文。

Browser Notification Filter

Filter out browser notifications by title or body of the notification. Edit script configuration before use, and backup script before updating.

  1. // ==UserScript==
  2. // @name Browser Notification Filter
  3. // @namespace https://gf.qytechs.cn/en/users/85671-jcunews
  4. // @version 1.0.2
  5. // @license GNU AGPLv3
  6. // @author jcunews
  7. // @description Filter out browser notifications by title or body of the notification. Edit script configuration before use, and backup script before updating.
  8. // @match *://*/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. ((orgNotif, whitelistMode, keywordBlacklist, keywordWhitelist) => {
  14.  
  15. //===== CONFIGURATION BEGIN =====
  16.  
  17. //If whitelistMode is false, keywords is a list of blacklisted words. i.e. block only if matched
  18. //If whitelistMode is true, keywords is a list of whitelisted words. i.e. allow only if matched
  19. whitelistMode = false;
  20.  
  21. keywordsTitle = /badtitle|badcategory/i;
  22. keywordsBody = /unwanted|badword/i;
  23.  
  24. //===== CONFIGURATION END =====
  25.  
  26. function dummy(){}
  27. window.fakeNotif = function(title, opts) {
  28. this.title = title;
  29. if (opts) Object.keys(opts).forEach(function(k) {
  30. this[k] = opts[k];
  31. }, this);
  32. if (!this.timestamp) this.timestamp = (new Date()).getTime();
  33. };
  34. fakeNotif.prototype.close = dummy;
  35. fakeNotif.prototype.addEventListener = dummy;
  36. fakeNotif.prototype.removeEventListener = dummy;
  37. orgNotif = Notification;
  38. Notification = function(title, opts) {
  39. var matched;
  40. if (opts) {
  41. matched = keywordsTitle.test(title) || keywordsBody.test(opts.body);
  42. } else matched = keywordsTitle.test(title);
  43. if ((matched && !whitelistMode) || (!matched && whitelistMode)) return new fakeNotif(title, opts);
  44. return new orgNotif(title, opts);
  45. };
  46. Object.defineProperty(Notification, "permission", {
  47. get: function() {
  48. return orgNotif.permission;
  49. }
  50. });
  51. Notification.requestPermission = orgNotif.requestPermission;
  52. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址