Spaces:
Build error
Build error
Update src/addons/addons/save-to-google/userscript.js
Browse files
src/addons/addons/save-to-google/userscript.js
CHANGED
@@ -13,9 +13,11 @@ export default async ({ addon, console, msg }) => {
|
|
13 |
const SCOPES = "https://www.googleapis.com/auth/drive.file";
|
14 |
const PROXY_URL = "https://soiz1-drive-proxy.hf.space/?file_id=";
|
15 |
const SHORT_URL = "https://s4.rf.gd/";
|
|
|
16 |
|
17 |
let accessToken = localStorage.getItem('googleDriveAccessToken') || null;
|
18 |
let currentAccountEmail = localStorage.getItem('googleDriveAccountEmail') || null;
|
|
|
19 |
|
20 |
while (true) {
|
21 |
const targetElem = await addon.tab.waitForElement(
|
@@ -50,7 +52,7 @@ export default async ({ addon, console, msg }) => {
|
|
50 |
<h1 style="font-size: 1.5rem; margin-bottom: 1rem;">Googleドライブに接続</h1>
|
51 |
${accessToken ? `
|
52 |
<div style="margin-bottom: 1rem; display: flex; justify-content: space-between; align-items: center;">
|
53 |
-
<div>ログイン中: ${currentAccountEmail || 'Googleアカウント'}</div>
|
54 |
<button id="change-account-button" class="button" style="padding: 0.25rem 0.5rem; font-size: 0.9rem;">アカウントを変更</button>
|
55 |
</div>
|
56 |
` : `
|
@@ -59,7 +61,7 @@ export default async ({ addon, console, msg }) => {
|
|
59 |
`}
|
60 |
<div id="file-list-container" style="margin-top: 1rem; ${accessToken ? '' : 'display: none;'}">
|
61 |
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
|
62 |
-
<h2 style="margin: 0; font-size: 1.2rem;">プロジェクト: <span id="project-title" style="cursor: pointer; border-bottom: 1px dashed #000;">${window.vm.runtime.projectName || "無題"}</span></h2>
|
63 |
<button id="new-file-button" class="button">新規保存</button>
|
64 |
</div>
|
65 |
<div id="file-list" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; margin-top: 1rem;"></div>
|
@@ -108,8 +110,10 @@ export default async ({ addon, console, msg }) => {
|
|
108 |
changeAccountButton.addEventListener("click", () => {
|
109 |
accessToken = null;
|
110 |
currentAccountEmail = null;
|
|
|
111 |
localStorage.removeItem('googleDriveAccessToken');
|
112 |
localStorage.removeItem('googleDriveAccountEmail');
|
|
|
113 |
showMainModal(addon);
|
114 |
modal.remove();
|
115 |
});
|
@@ -146,11 +150,15 @@ export default async ({ addon, console, msg }) => {
|
|
146 |
window.removeEventListener("message", messageListener);
|
147 |
accessToken = event.data.token;
|
148 |
currentAccountEmail = event.data.email || null;
|
|
|
149 |
|
150 |
localStorage.setItem('googleDriveAccessToken', accessToken);
|
151 |
if (currentAccountEmail) {
|
152 |
localStorage.setItem('googleDriveAccountEmail', currentAccountEmail);
|
153 |
}
|
|
|
|
|
|
|
154 |
|
155 |
showMainModal(addon);
|
156 |
modal.remove();
|
@@ -248,63 +256,64 @@ export default async ({ addon, console, msg }) => {
|
|
248 |
fileName.style.fontSize = "1rem";
|
249 |
fileName.style.textAlign = "center";
|
250 |
fileName.style.fontWeight = "bold";
|
|
|
251 |
fileItem.appendChild(fileName);
|
252 |
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
const copyButton = document.createElement("button");
|
285 |
-
copyButton.textContent = "コピー";
|
286 |
-
copyButton.className = "button";
|
287 |
-
copyButton.style.fontSize = "0.8em";
|
288 |
-
copyButton.style.padding = "0.2rem 0.5rem";
|
289 |
-
copyButton.style.whiteSpace = "nowrap";
|
290 |
-
|
291 |
-
copyButton.addEventListener("click", (e) => {
|
292 |
-
e.stopPropagation();
|
293 |
-
navigator.clipboard.writeText(`${SHORT_URL}${project.id}`)
|
294 |
-
.then(() => showAlert(addon, "success", "リンクをクリップボードにコピーしました"))
|
295 |
-
.catch(() => showAlert(addon, "error", "リンクのコピーに失敗しました"));
|
296 |
-
});
|
297 |
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
const loadButton = document.createElement("button");
|
310 |
loadButton.textContent = "読み込む";
|
@@ -339,11 +348,22 @@ buttonContainer.style.gap = "0.5rem";
|
|
339 |
}
|
340 |
});
|
341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
const deleteButton = document.createElement("button");
|
343 |
deleteButton.textContent = "削除";
|
344 |
deleteButton.className = "button";
|
345 |
deleteButton.style.width = "100%";
|
346 |
-
deleteButton.style.gridColumn = "1 / -1";
|
347 |
deleteButton.style.backgroundColor = "#ff4444";
|
348 |
deleteButton.style.color = "white";
|
349 |
|
@@ -375,22 +395,10 @@ buttonContainer.style.gap = "0.5rem";
|
|
375 |
}
|
376 |
});
|
377 |
|
378 |
-
|
379 |
-
|
380 |
-
shareButton
|
381 |
-
|
382 |
-
shareButton.style.backgroundColor = "#4CAF50";
|
383 |
-
shareButton.style.color = "white";
|
384 |
-
|
385 |
-
shareButton.addEventListener("click", (e) => {
|
386 |
-
e.stopPropagation();
|
387 |
-
window.open(`https://scratch-school.ct.ws/upload.php?id=${project.id}`, "_blank");
|
388 |
-
});
|
389 |
-
|
390 |
-
buttonContainer.appendChild(loadButton);
|
391 |
-
buttonContainer.appendChild(replaceButton);
|
392 |
-
buttonContainer.appendChild(shareButton);
|
393 |
-
buttonContainer.appendChild(deleteButton);
|
394 |
fileItem.appendChild(buttonContainer);
|
395 |
|
396 |
fileList.appendChild(fileItem);
|
|
|
13 |
const SCOPES = "https://www.googleapis.com/auth/drive.file";
|
14 |
const PROXY_URL = "https://soiz1-drive-proxy.hf.space/?file_id=";
|
15 |
const SHORT_URL = "https://s4.rf.gd/";
|
16 |
+
const SHARE_URL = "https://soiz1-penguin-upload.hf.space/upload?id=";
|
17 |
|
18 |
let accessToken = localStorage.getItem('googleDriveAccessToken') || null;
|
19 |
let currentAccountEmail = localStorage.getItem('googleDriveAccountEmail') || null;
|
20 |
+
let currentAccountName = localStorage.getItem('googleDriveAccountName') || null;
|
21 |
|
22 |
while (true) {
|
23 |
const targetElem = await addon.tab.waitForElement(
|
|
|
52 |
<h1 style="font-size: 1.5rem; margin-bottom: 1rem;">Googleドライブに接続</h1>
|
53 |
${accessToken ? `
|
54 |
<div style="margin-bottom: 1rem; display: flex; justify-content: space-between; align-items: center;">
|
55 |
+
<div>ログイン中: ${currentAccountName || currentAccountEmail || 'Googleアカウント'}</div>
|
56 |
<button id="change-account-button" class="button" style="padding: 0.25rem 0.5rem; font-size: 0.9rem;">アカウントを変更</button>
|
57 |
</div>
|
58 |
` : `
|
|
|
61 |
`}
|
62 |
<div id="file-list-container" style="margin-top: 1rem; ${accessToken ? '' : 'display: none;'}">
|
63 |
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
|
64 |
+
<h2 style="margin: 0; font-size: 1.2rem;">プロジェクト: <span id="project-title" style="cursor: pointer; border-bottom: 1px dashed #000; color: #333;">${window.vm.runtime.projectName || "無題"}</span></h2>
|
65 |
<button id="new-file-button" class="button">新規保存</button>
|
66 |
</div>
|
67 |
<div id="file-list" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; margin-top: 1rem;"></div>
|
|
|
110 |
changeAccountButton.addEventListener("click", () => {
|
111 |
accessToken = null;
|
112 |
currentAccountEmail = null;
|
113 |
+
currentAccountName = null;
|
114 |
localStorage.removeItem('googleDriveAccessToken');
|
115 |
localStorage.removeItem('googleDriveAccountEmail');
|
116 |
+
localStorage.removeItem('googleDriveAccountName');
|
117 |
showMainModal(addon);
|
118 |
modal.remove();
|
119 |
});
|
|
|
150 |
window.removeEventListener("message", messageListener);
|
151 |
accessToken = event.data.token;
|
152 |
currentAccountEmail = event.data.email || null;
|
153 |
+
currentAccountName = event.data.name || null;
|
154 |
|
155 |
localStorage.setItem('googleDriveAccessToken', accessToken);
|
156 |
if (currentAccountEmail) {
|
157 |
localStorage.setItem('googleDriveAccountEmail', currentAccountEmail);
|
158 |
}
|
159 |
+
if (currentAccountName) {
|
160 |
+
localStorage.setItem('googleDriveAccountName', currentAccountName);
|
161 |
+
}
|
162 |
|
163 |
showMainModal(addon);
|
164 |
modal.remove();
|
|
|
256 |
fileName.style.fontSize = "1rem";
|
257 |
fileName.style.textAlign = "center";
|
258 |
fileName.style.fontWeight = "bold";
|
259 |
+
fileName.style.color = "#333";
|
260 |
fileItem.appendChild(fileName);
|
261 |
|
262 |
+
// 共有リンク
|
263 |
+
const linkContainer = document.createElement("div");
|
264 |
+
linkContainer.style.display = "flex";
|
265 |
+
linkContainer.style.flexDirection = "column";
|
266 |
+
linkContainer.style.gap = "0.25rem";
|
267 |
+
linkContainer.style.marginBottom = "0.5rem";
|
268 |
+
|
269 |
+
const linkHeader = document.createElement("div");
|
270 |
+
linkHeader.style.display = "flex";
|
271 |
+
linkHeader.style.justifyContent = "space-between";
|
272 |
+
linkHeader.style.alignItems = "center";
|
273 |
+
|
274 |
+
const linkLabel = document.createElement("span");
|
275 |
+
linkLabel.textContent = "共有リンク:";
|
276 |
+
linkLabel.style.fontSize = "0.8em";
|
277 |
+
linkLabel.style.color = "#555";
|
278 |
+
|
279 |
+
const copyButton = document.createElement("button");
|
280 |
+
copyButton.textContent = "コピー";
|
281 |
+
copyButton.className = "button";
|
282 |
+
copyButton.style.fontSize = "0.8em";
|
283 |
+
copyButton.style.padding = "0.1rem 0.3rem";
|
284 |
+
copyButton.style.backgroundColor = "#e9e9e9";
|
285 |
+
copyButton.style.color = "#333";
|
286 |
+
|
287 |
+
copyButton.addEventListener("click", (e) => {
|
288 |
+
e.stopPropagation();
|
289 |
+
navigator.clipboard.writeText(`${SHORT_URL}${project.id}`)
|
290 |
+
.then(() => showAlert(addon, "success", "リンクをクリップボードにコピーしました"))
|
291 |
+
.catch(() => showAlert(addon, "error", "リンクのコピーに失敗しました"));
|
292 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
+
linkHeader.appendChild(linkLabel);
|
295 |
+
linkHeader.appendChild(copyButton);
|
296 |
+
linkContainer.appendChild(linkHeader);
|
297 |
|
298 |
+
const linkUrl = document.createElement("a");
|
299 |
+
linkUrl.href = `${SHORT_URL}${project.id}`;
|
300 |
+
linkUrl.textContent = `${SHORT_URL}${project.id}`;
|
301 |
+
linkUrl.target = "_blank";
|
302 |
+
linkUrl.rel = "noopener noreferrer";
|
303 |
+
linkUrl.style.fontSize = "0.9em";
|
304 |
+
linkUrl.style.wordBreak = "break-all";
|
305 |
+
linkUrl.style.color = "#1155cc";
|
306 |
+
linkUrl.style.textDecoration = "none";
|
307 |
+
linkUrl.style.borderBottom = "1px solid #1155cc";
|
308 |
+
linkContainer.appendChild(linkUrl);
|
309 |
+
|
310 |
+
fileItem.appendChild(linkContainer);
|
311 |
|
312 |
+
// 操作ボタン
|
313 |
+
const buttonContainer = document.createElement("div");
|
314 |
+
buttonContainer.style.display = "grid";
|
315 |
+
buttonContainer.style.gridTemplateColumns = "1fr 1fr";
|
316 |
+
buttonContainer.style.gap = "0.5rem";
|
317 |
|
318 |
const loadButton = document.createElement("button");
|
319 |
loadButton.textContent = "読み込む";
|
|
|
348 |
}
|
349 |
});
|
350 |
|
351 |
+
const shareButton = document.createElement("button");
|
352 |
+
shareButton.textContent = "共有";
|
353 |
+
shareButton.className = "button";
|
354 |
+
shareButton.style.width = "100%";
|
355 |
+
shareButton.style.backgroundColor = "#4CAF50";
|
356 |
+
shareButton.style.color = "white";
|
357 |
+
|
358 |
+
shareButton.addEventListener("click", (e) => {
|
359 |
+
e.stopPropagation();
|
360 |
+
window.open(`${SHARE_URL}${project.id}`, "_blank");
|
361 |
+
});
|
362 |
+
|
363 |
const deleteButton = document.createElement("button");
|
364 |
deleteButton.textContent = "削除";
|
365 |
deleteButton.className = "button";
|
366 |
deleteButton.style.width = "100%";
|
|
|
367 |
deleteButton.style.backgroundColor = "#ff4444";
|
368 |
deleteButton.style.color = "white";
|
369 |
|
|
|
395 |
}
|
396 |
});
|
397 |
|
398 |
+
buttonContainer.appendChild(loadButton);
|
399 |
+
buttonContainer.appendChild(replaceButton);
|
400 |
+
buttonContainer.appendChild(shareButton);
|
401 |
+
buttonContainer.appendChild(deleteButton);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
fileItem.appendChild(buttonContainer);
|
403 |
|
404 |
fileList.appendChild(fileItem);
|