Detect Watermark

Detect invisible watermark on the page to avoid track

当前为 2022-09-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Detect Watermark
  3. // @version 0.1
  4. // @description Detect invisible watermark on the page to avoid track
  5. // @author You
  6. // @match https://*/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/474693
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. function isWatermarkElement(el) {
  15. const style = getComputedStyle(el);
  16. return (style.pointerEvents === "none" &&
  17. style.position === "fixed" &&
  18. style.backgroundImage.toLowerCase().includes("data:"));
  19. }
  20.  
  21. const LANG = {
  22. "zh-CN": {
  23. warn: "⚠️ 当前页面可能含有水印,请注意保护个人信息!",
  24. dismiss: "知道了",
  25. },
  26. };
  27. function getText(key) {
  28. const text = LANG[navigator.language] ?? LANG["zh-CN"];
  29. return text[key];
  30. }
  31.  
  32. async function detect() {
  33. return new Promise((resolve) => {
  34. const elements = document.querySelectorAll("*");
  35. let cursor = 0;
  36. const run = ({ didTimeout }) => {
  37. for (; cursor < elements.length; cursor++) {
  38. const element = elements[cursor];
  39. if (isWatermarkElement(element)) {
  40. resolve(element);
  41. }
  42. if (didTimeout) {
  43. requestIdleCallback(run);
  44. return;
  45. }
  46. }
  47. resolve();
  48. };
  49. requestIdleCallback(run);
  50. });
  51. }
  52. function report(el) {
  53. const shadowHost = document.createElement("div");
  54. const shadowRoot = shadowHost.attachShadow({ mode: 'closed' });
  55. document.body.appendChild(shadowHost);
  56. const notice = document.createElement('div');
  57. notice.setAttribute("style", [
  58. "position: fixed",
  59. "z-index: 99999",
  60. "top: 10px",
  61. "right: 10px",
  62. "left: 10px",
  63. "display: flex",
  64. "justify-content: space-between",
  65. "align-items: center",
  66. "color: white",
  67. "background: red",
  68. "border-radius: 8px",
  69. "padding: 8px",
  70. ].join(";"));
  71. notice.innerText = getText("warn");
  72. const button = document.createElement("button");
  73. button.innerText = getText("dismiss");
  74. button.addEventListener("click", () => {
  75. document.body.removeChild(shadowHost);
  76. });
  77. notice.appendChild(button);
  78. shadowRoot.appendChild(notice);
  79. }
  80. (async () => {
  81. const watermarkEl = await detect();
  82. if (watermarkEl == null)
  83. return;
  84. report();
  85. })();
  86.  
  87. })();