Spaces:
Runtime error
Runtime error
Update src/addons/addons/debug-console/userscript.js
Browse files
src/addons/addons/debug-console/userscript.js
CHANGED
@@ -1,204 +1,204 @@
|
|
1 |
-
|
2 |
-
while (true) {
|
3 |
const targetElem = await addon.tab.waitForElement(
|
4 |
-
|
5 |
-
|
6 |
);
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
debugBtn.style.cursor = "pointer";
|
15 |
-
debugBtn.addEventListener("click", () => {
|
16 |
-
// デバッグコンソール実行スクリプト
|
17 |
-
(function () {
|
18 |
-
if (window.__injectedConsole) return;
|
19 |
-
window.__injectedConsole = true;
|
20 |
-
|
21 |
-
const style = `
|
22 |
-
#floatingConsole {
|
23 |
-
position: fixed;
|
24 |
-
bottom: 20px;
|
25 |
-
right: 20px;
|
26 |
-
width: 400px;
|
27 |
-
max-height: 60vh;
|
28 |
-
background: #111;
|
29 |
-
color: #0f0;
|
30 |
-
font-family: monospace;
|
31 |
-
font-size: 14px;
|
32 |
-
border: 1px solid #0f0;
|
33 |
-
border-radius: 8px;
|
34 |
-
box-shadow: 0 0 10px #0f0;
|
35 |
-
z-index: 999999;
|
36 |
-
display: flex;
|
37 |
-
flex-direction: column;
|
38 |
-
resize: both;
|
39 |
-
overflow: hidden;
|
40 |
-
}
|
41 |
-
#floatingConsoleHeader {
|
42 |
-
background: #222;
|
43 |
-
cursor: move;
|
44 |
-
padding: 5px 10px;
|
45 |
-
user-select: none;
|
46 |
-
display: flex;
|
47 |
-
justify-content: space-between;
|
48 |
-
align-items: center;
|
49 |
-
}
|
50 |
-
#floatingConsoleHeader button {
|
51 |
-
background: transparent;
|
52 |
-
color: #0f0;
|
53 |
-
border: none;
|
54 |
-
font-weight: bold;
|
55 |
-
margin-left: 5px;
|
56 |
-
cursor: pointer;
|
57 |
-
}
|
58 |
-
#floatingConsoleLog {
|
59 |
-
flex: 1;
|
60 |
-
overflow-y: auto;
|
61 |
-
padding: 10px;
|
62 |
-
border-top: 1px solid #0f0;
|
63 |
-
border-bottom: 1px solid #0f0;
|
64 |
-
background: #000;
|
65 |
-
}
|
66 |
-
#floatingConsoleInput {
|
67 |
-
display: flex;
|
68 |
-
border-top: 1px solid #0f0;
|
69 |
-
}
|
70 |
-
#floatingConsoleInput input {
|
71 |
-
flex: 1;
|
72 |
-
background: #000;
|
73 |
-
color: #0f0;
|
74 |
-
border: none;
|
75 |
-
padding: 10px;
|
76 |
-
font-family: monospace;
|
77 |
-
}
|
78 |
-
#floatingConsoleInput button {
|
79 |
-
background: #333;
|
80 |
-
color: #0f0;
|
81 |
-
border: none;
|
82 |
-
padding: 10px;
|
83 |
-
cursor: pointer;
|
84 |
}
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
</div>
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
log("エラー: " + e);
|
128 |
-
}
|
129 |
-
};
|
130 |
-
|
131 |
-
el.querySelector("#closeBtn").onclick = () => {
|
132 |
-
el.remove();
|
133 |
-
window.__injectedConsole = false;
|
134 |
-
};
|
135 |
-
|
136 |
-
let minimized = false;
|
137 |
-
const minBtn = el.querySelector("#minBtn");
|
138 |
-
const header = el.querySelector("#floatingConsoleHeader");
|
139 |
-
const title = el.querySelector("#consoleTitle");
|
140 |
-
|
141 |
-
minBtn.onclick = () => {
|
142 |
-
minimized = !minimized;
|
143 |
-
logBox.style.display = minimized ? "none" : "block";
|
144 |
-
el.querySelector("#floatingConsoleInput").style.display = minimized ? "none" : "flex";
|
145 |
-
title.style.display = minimized ? "none" : "inline"; // ✅ タイトル非表示
|
146 |
-
el.querySelector("#closeBtn").style.display = minimized ? "none" : "inline"; // ✅ ×ボタン非表示
|
147 |
-
minBtn.textContent = minimized ? "∨" : "∧";
|
148 |
-
|
149 |
-
if (minimized) {
|
150 |
-
el.style.width = "auto"; // ✅ 幅縮小
|
151 |
-
el.style.height = "auto"; // ✅ 高さ縮小
|
152 |
-
el.style.overflow = "visible";
|
153 |
-
} else {
|
154 |
-
el.style.width = "400px";
|
155 |
-
el.style.maxHeight = "60vh";
|
156 |
-
}
|
157 |
-
};
|
158 |
-
|
159 |
-
// ドラッグ移動
|
160 |
-
(function makeDraggable(target, handle) {
|
161 |
-
let offsetX = 0, offsetY = 0, dragging = false;
|
162 |
-
handle.addEventListener("mousedown", (e) => {
|
163 |
-
dragging = true;
|
164 |
-
offsetX = e.clientX - target.offsetLeft;
|
165 |
-
offsetY = e.clientY - target.offsetTop;
|
166 |
-
document.body.style.userSelect = "none";
|
167 |
-
});
|
168 |
-
document.addEventListener("mousemove", (e) => {
|
169 |
-
if (dragging) {
|
170 |
-
target.style.left = (e.clientX - offsetX) + "px";
|
171 |
-
target.style.top = (e.clientY - offsetY) + "px";
|
172 |
-
target.style.right = "auto";
|
173 |
-
target.style.bottom = "auto";
|
174 |
}
|
175 |
-
});
|
176 |
-
document.addEventListener("mouseup", () => {
|
177 |
-
dragging = false;
|
178 |
-
document.body.style.userSelect = "";
|
179 |
-
});
|
180 |
-
})(el, header);
|
181 |
-
|
182 |
-
// console.* フック
|
183 |
-
const hookConsole = (name) => {
|
184 |
-
const original = console[name];
|
185 |
-
console[name] = function (...args) {
|
186 |
-
original.apply(console, args);
|
187 |
-
log("[" + name + "] " + args.join(" "));
|
188 |
};
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export default async ({ addon }) => {
|
2 |
+
while (true) {
|
3 |
const targetElem = await addon.tab.waitForElement(
|
4 |
+
'div[class*="menu-bar_file-group"] > div:last-child:not(.sa-record)',
|
5 |
+
{ markAsSeen: true }
|
6 |
);
|
7 |
|
8 |
+
if (!document.querySelector('.sa-debug-modal-button')) {
|
9 |
+
const button = document.createElement("div");
|
10 |
+
button.className = "sa-debug-modal-button " + targetElem.className;
|
11 |
+
button.textContent = "デバッグ";
|
12 |
+
button.style.cursor = "pointer";
|
13 |
|
14 |
+
button.addEventListener("click", () => {
|
15 |
+
injectDebugConsole();
|
16 |
+
});
|
17 |
+
|
18 |
+
targetElem.parentElement.appendChild(button);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
+
}
|
21 |
+
|
22 |
+
// 浮動コンソールをページに挿入する関数
|
23 |
+
function injectDebugConsole() {
|
24 |
+
if (window.__injectedConsole) return;
|
25 |
+
window.__injectedConsole = true;
|
26 |
+
|
27 |
+
const style = `
|
28 |
+
#floatingConsole {
|
29 |
+
position: fixed;
|
30 |
+
bottom: 20px;
|
31 |
+
right: 20px;
|
32 |
+
width: 400px;
|
33 |
+
max-height: 60vh;
|
34 |
+
background: #111;
|
35 |
+
color: #0f0;
|
36 |
+
font-family: monospace;
|
37 |
+
font-size: 14px;
|
38 |
+
border: 1px solid #0f0;
|
39 |
+
border-radius: 8px;
|
40 |
+
box-shadow: 0 0 10px #0f0;
|
41 |
+
z-index: 999999;
|
42 |
+
display: flex;
|
43 |
+
flex-direction: column;
|
44 |
+
resize: both;
|
45 |
+
overflow: hidden;
|
46 |
+
}
|
47 |
+
#floatingConsoleHeader {
|
48 |
+
background: #222;
|
49 |
+
cursor: move;
|
50 |
+
padding: 5px 10px;
|
51 |
+
user-select: none;
|
52 |
+
display: flex;
|
53 |
+
justify-content: space-between;
|
54 |
+
align-items: center;
|
55 |
+
}
|
56 |
+
#floatingConsoleHeader button {
|
57 |
+
background: transparent;
|
58 |
+
color: #0f0;
|
59 |
+
border: none;
|
60 |
+
font-weight: bold;
|
61 |
+
margin-left: 5px;
|
62 |
+
cursor: pointer;
|
63 |
+
}
|
64 |
+
#floatingConsoleLog {
|
65 |
+
flex: 1;
|
66 |
+
overflow-y: auto;
|
67 |
+
padding: 10px;
|
68 |
+
border-top: 1px solid #0f0;
|
69 |
+
border-bottom: 1px solid #0f0;
|
70 |
+
background: #000;
|
71 |
+
}
|
72 |
+
#floatingConsoleInput {
|
73 |
+
display: flex;
|
74 |
+
border-top: 1px solid #0f0;
|
75 |
+
}
|
76 |
+
#floatingConsoleInput input {
|
77 |
+
flex: 1;
|
78 |
+
background: #000;
|
79 |
+
color: #0f0;
|
80 |
+
border: none;
|
81 |
+
padding: 10px;
|
82 |
+
font-family: monospace;
|
83 |
+
}
|
84 |
+
#floatingConsoleInput button {
|
85 |
+
background: #333;
|
86 |
+
color: #0f0;
|
87 |
+
border: none;
|
88 |
+
padding: 10px;
|
89 |
+
cursor: pointer;
|
90 |
+
}
|
91 |
+
`;
|
92 |
+
|
93 |
+
const css = document.createElement("style");
|
94 |
+
css.textContent = style;
|
95 |
+
document.head.appendChild(css);
|
96 |
+
|
97 |
+
const el = document.createElement("div");
|
98 |
+
el.id = "floatingConsole";
|
99 |
+
el.innerHTML = `
|
100 |
+
<div id="floatingConsoleHeader">
|
101 |
+
<span id="consoleTitle">🖥 Console</span>
|
102 |
+
<div>
|
103 |
+
<button id="minBtn">∧</button>
|
104 |
+
<button id="closeBtn">×</button>
|
105 |
+
</div>
|
106 |
</div>
|
107 |
+
<div id="floatingConsoleLog">[Console Ready]</div>
|
108 |
+
<div id="floatingConsoleInput">
|
109 |
+
<input id="floatingConsoleCmd" placeholder="JavaScriptを入力..." />
|
110 |
+
<button id="execBtn">実行</button>
|
111 |
+
</div>
|
112 |
+
`;
|
113 |
+
document.body.appendChild(el);
|
114 |
+
|
115 |
+
const logBox = el.querySelector("#floatingConsoleLog");
|
116 |
+
const input = el.querySelector("#floatingConsoleCmd");
|
117 |
+
|
118 |
+
const log = (msg) => {
|
119 |
+
const div = document.createElement("div");
|
120 |
+
div.textContent = "> " + msg;
|
121 |
+
logBox.appendChild(div);
|
122 |
+
logBox.scrollTop = logBox.scrollHeight;
|
123 |
+
};
|
124 |
+
|
125 |
+
el.querySelector("#execBtn").onclick = () => {
|
126 |
+
const code = input.value;
|
127 |
+
input.value = "";
|
128 |
+
try {
|
129 |
+
const result = eval(code);
|
130 |
+
log("結果: " + result);
|
131 |
+
} catch (e) {
|
132 |
+
log("エラー: " + e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
};
|
135 |
+
|
136 |
+
el.querySelector("#closeBtn").onclick = () => {
|
137 |
+
el.remove();
|
138 |
+
window.__injectedConsole = false;
|
139 |
+
};
|
140 |
+
|
141 |
+
let minimized = false;
|
142 |
+
const minBtn = el.querySelector("#minBtn");
|
143 |
+
const header = el.querySelector("#floatingConsoleHeader");
|
144 |
+
const title = el.querySelector("#consoleTitle");
|
145 |
+
|
146 |
+
minBtn.onclick = () => {
|
147 |
+
minimized = !minimized;
|
148 |
+
logBox.style.display = minimized ? "none" : "block";
|
149 |
+
el.querySelector("#floatingConsoleInput").style.display = minimized ? "none" : "flex";
|
150 |
+
title.style.display = minimized ? "none" : "inline";
|
151 |
+
el.querySelector("#closeBtn").style.display = minimized ? "none" : "inline";
|
152 |
+
minBtn.textContent = minimized ? "∨" : "∧";
|
153 |
+
|
154 |
+
if (minimized) {
|
155 |
+
el.style.width = "auto";
|
156 |
+
el.style.height = "auto";
|
157 |
+
el.style.overflow = "visible";
|
158 |
+
} else {
|
159 |
+
el.style.width = "400px";
|
160 |
+
el.style.maxHeight = "60vh";
|
161 |
+
}
|
162 |
+
};
|
163 |
+
|
164 |
+
// ドラッグ移動
|
165 |
+
(function makeDraggable(target, handle) {
|
166 |
+
let offsetX = 0, offsetY = 0, dragging = false;
|
167 |
+
handle.addEventListener("mousedown", (e) => {
|
168 |
+
dragging = true;
|
169 |
+
offsetX = e.clientX - target.offsetLeft;
|
170 |
+
offsetY = e.clientY - target.offsetTop;
|
171 |
+
document.body.style.userSelect = "none";
|
172 |
+
});
|
173 |
+
document.addEventListener("mousemove", (e) => {
|
174 |
+
if (dragging) {
|
175 |
+
target.style.left = (e.clientX - offsetX) + "px";
|
176 |
+
target.style.top = (e.clientY - offsetY) + "px";
|
177 |
+
target.style.right = "auto";
|
178 |
+
target.style.bottom = "auto";
|
179 |
+
}
|
180 |
+
});
|
181 |
+
document.addEventListener("mouseup", () => {
|
182 |
+
dragging = false;
|
183 |
+
document.body.style.userSelect = "";
|
184 |
+
});
|
185 |
+
})(el, header);
|
186 |
+
|
187 |
+
// console.* フック
|
188 |
+
const hookConsole = (name) => {
|
189 |
+
const original = console[name];
|
190 |
+
console[name] = function (...args) {
|
191 |
+
original.apply(console, args);
|
192 |
+
log("[" + name + "] " + args.join(" "));
|
193 |
+
};
|
194 |
+
};
|
195 |
+
["log", "warn", "error"].forEach(hookConsole);
|
196 |
+
|
197 |
+
window.onerror = (msg, src, line, col, err) => {
|
198 |
+
log("[onerror] " + msg + " @ " + line + ":" + col);
|
199 |
+
};
|
200 |
+
window.addEventListener("unhandledrejection", (e) => {
|
201 |
+
log("[unhandledrejection] " + e.reason);
|
202 |
+
});
|
203 |
+
}
|
204 |
+
};
|