質問編集履歴

1

deepl code blockerのコードを追記しました。

2022/11/17 16:27

投稿

Nico
Nico

スコア0

test CHANGED
File without changes
test CHANGED
@@ -7,4 +7,74 @@
7
7
 
8
8
  DeepLやGoogle翻訳から特定の単語群を翻訳させないようなアプローチは具体的にはどのように行えばいいでしょうか。私はTypeScriptやJavaScriptはあまり詳しくありません。
9
9
 
10
+ deeple code blockerで動いているスクリプト
11
+ ```javascript
12
+ (() => {
13
+ "use strict";
14
+ class e {
15
+ static isElement(e) {
16
+ return 1 === e.nodeType;
17
+ }
18
+ }
19
+ const t = (e, t) => {
20
+ const n = [...e.childNodes];
21
+ for (; n.length; ) {
22
+ const e = n.shift();
23
+ if (!e) break;
24
+ if (t(e)) return !0;
25
+ n.concat(e.childNodes ? [...e.childNodes] : []);
26
+ }
27
+ return !1;
28
+ };
29
+ [
30
+ ...[...document.getElementsByTagName("code")].filter(
31
+ (n) => !t(n, (t) => e.isElement(t) && "PRE" === t.tagName)
32
+ ),
33
+ ...[...document.getElementsByTagName("pre")].filter(
34
+ (n) => !t(n, (t) => e.isElement(t) && "CODE" === t.tagName)
35
+ ),
36
+ ].forEach((e) =>
37
+ ((e) => {
38
+ ((e) => {
39
+ const t = (e) => {
40
+ const t = window.getComputedStyle(e);
41
+ [
42
+ "background-color",
43
+ "display",
44
+ "color",
45
+ "letter-spacing",
46
+ "line-height",
47
+ "content-wrap",
48
+ "font-size",
49
+ "font-weight",
50
+ "font",
51
+ ].forEach((n) => {
52
+ e.style.setProperty(n, t.getPropertyValue(n));
53
+ });
54
+ },
55
+ n = [{ element: e, visited: !1 }];
56
+ for (; n.length; ) {
57
+ const e = n.pop();
58
+ if (!e) continue;
59
+ const o = [...e.element.children].flatMap((e) =>
60
+ e instanceof HTMLElement ? [e] : []
61
+ );
62
+ if (e.visited || !o.length) t(e.element);
63
+ else {
64
+ const t = [
65
+ { element: e.element, visited: !0 },
66
+ ...o.map((e) => ({ element: e, visited: !1 })),
67
+ ];
68
+ n.push(...t);
69
+ }
70
+ }
71
+ })(e);
72
+ const t = document.createElement("div");
73
+ (t.style.display = window.getComputedStyle(e).display),
74
+ (t.attachShadow({ mode: "closed" }).innerHTML = e.outerHTML),
75
+ e.replaceWith(t);
76
+ })(e)
77
+ );
78
+ })();
10
79
 
80
+ ```