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