Skip to content

Commit 314f031

Browse files
committed
feat: water mark inspect
1 parent 0a82180 commit 314f031

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

packages/copy-currency/meta.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"name": {
33
"default": "🔥🔥🔥文本选中复制(通用)🔥🔥🔥",
44
"en": "Text Copy Universal",
5-
"zh-CN": "🔥🔥🔥文本选中复制(通用)🔥🔥🔥"
5+
"zh": "🔥🔥🔥文本选中复制(通用)🔥🔥🔥"
66
},
77
"namespace": "https://github.com/WindrunnerMax/TKScript",
8-
"version": "1.1.2",
8+
"version": "1.1.3",
99
"description": {
1010
"default": "文本选中复制通用版本,适用于大多数网站",
1111
"en": "Text copy general version, suitable for most websites.",
12-
"zh-CN": "文本选中复制通用版本,适用于大多数网站"
12+
"zh": "文本选中复制通用版本,适用于大多数网站"
1313
},
1414
"author": "Czy",
1515
"match": ["http://*/*", "https://*/*"],

packages/water-mark/meta.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
{
2-
"name": "移除页面水印",
2+
"name": {
3+
"default": "🔥🔥🔥移除页面水印🔥🔥🔥",
4+
"en": "Remove Page Watermark",
5+
"zh": "🔥🔥🔥移除页面水印🔥🔥🔥"
6+
},
37
"namespace": "https://github.com/WindrunnerMax/TKScript",
4-
"version": "1.0.3",
5-
"description": "移除常见网页的水印",
8+
"version": "1.0.4",
9+
"description": {
10+
"default": "移除常见网页的水印",
11+
"en": "Remove watermarks from common web pages",
12+
"zh": "移除常见网页的水印"
13+
},
614
"author": "Czy",
715
"match": ["http://*/*", "https://*/*"],
816
"supportURL": "https://github.com/WindrunnerMax/TKScript/issues",

packages/water-mark/src/modules/common.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import type { Website } from "../types/website";
22
import { FALLBACK_CLASS, OPACITY_BACKGROUND_PROPERTY, OPACITY_PROPERTY } from "../utils/constant";
3-
import { lintWaterMarkDOM } from "../utils/dom";
3+
import { inspectWaterMarkDOM } from "../utils/dom";
44
import { injectCSSEarly } from "../utils/styles";
55

66
export const common: Website = {
77
regexp: /.*/,
88
init: () => {
99
const observer = MutationObserver.prototype.observe;
1010
MutationObserver.prototype.observe = function (target, options) {
11-
lintWaterMarkDOM(target);
12-
target.childNodes.forEach(lintWaterMarkDOM);
11+
inspectWaterMarkDOM(target);
12+
target.childNodes.forEach(inspectWaterMarkDOM);
1313
observer.call(this, target, options);
1414
};
1515
const _MutationObserver = MutationObserver;
16-
const cb = (callback: MutationCallback) => {
16+
const getMutationCallback = (callback: MutationCallback) => {
1717
return (records: MutationRecord[], observer: MutationObserver) => {
1818
let isMatchedWaterMarkDOM = false;
1919
for (const record of records) {
20-
if (lintWaterMarkDOM(record.target) && !isMatchedWaterMarkDOM) {
20+
if (inspectWaterMarkDOM(record.target) && !isMatchedWaterMarkDOM) {
2121
isMatchedWaterMarkDOM = true;
2222
}
2323
}
@@ -26,7 +26,7 @@ export const common: Website = {
2626
};
2727
unsafeWindow.MutationObserver = class extends _MutationObserver {
2828
constructor(callback: MutationCallback) {
29-
super(cb(callback));
29+
super(getMutationCallback(callback));
3030
}
3131
};
3232
const PRESET_CLASSES = [

packages/water-mark/src/utils/constant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const FALLBACK_CLASS = "_watermark";
1+
export const FALLBACK_CLASS = "__WATERMARK__";
22

33
export const OPACITY_PROPERTY = [
44
"opacity: 0 !important;",
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { FALLBACK_CLASS } from "./constant";
22

3-
export const lintWaterMarkDOM = (node: Node) => {
4-
if (node instanceof HTMLElement && node.hasAttribute("style")) {
5-
if (node.style.pointerEvents !== "none") {
6-
return false;
7-
}
8-
if (node.style.background.startsWith("url") || node.style.backgroundImage.startsWith("url")) {
9-
!node.classList.contains(FALLBACK_CLASS) && node.classList.add(FALLBACK_CLASS);
10-
return true;
11-
}
3+
export const inspectWaterMarkDOM = (node: Node) => {
4+
if (node instanceof HTMLElement === false) {
5+
return false;
6+
}
7+
if (node.classList.contains(FALLBACK_CLASS)) {
8+
return true;
9+
}
10+
if (!node.hasAttribute("style") || node.style.pointerEvents !== "none") {
11+
return false;
12+
}
13+
if (node.style.background.startsWith("url") || node.style.backgroundImage.startsWith("url")) {
14+
!node.classList.contains(FALLBACK_CLASS) && node.classList.add(FALLBACK_CLASS);
15+
return true;
1216
}
1317
return false;
1418
};

0 commit comments

Comments
 (0)