Spaces:
Running
Running
Update src/addons/addons/save-to-google/userscript.js
Browse files
src/addons/addons/save-to-google/userscript.js
CHANGED
@@ -1,49 +1,62 @@
|
|
1 |
export default async ({ addon, console, msg }) => {
|
2 |
while (true) {
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
});
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
});
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
backdrop.addEventListener("click", remove);
|
23 |
-
closeButton.addEventListener("click", remove);
|
24 |
-
};
|
25 |
-
|
26 |
-
if (!document.querySelector(".custom-menu")) {
|
27 |
-
const menuContainer = document.createElement("div");
|
28 |
-
menuContainer.className = "custom-menu " + elem.className;
|
29 |
-
|
30 |
-
// オプションボタン
|
31 |
-
const optionButton = document.createElement("div");
|
32 |
-
optionButton.textContent = "オプション";
|
33 |
-
optionButton.className = "custom-button";
|
34 |
-
optionButton.addEventListener("click", createModal);
|
35 |
-
menuContainer.appendChild(optionButton);
|
36 |
-
|
37 |
-
// Googleドライブに保存ボタン
|
38 |
-
const saveButton = document.createElement("div");
|
39 |
-
saveButton.textContent = "Googleドライブに保存";
|
40 |
-
saveButton.className = "custom-button";
|
41 |
-
saveButton.addEventListener("click", () => {
|
42 |
-
console.log("Googleドライブに保存処理をここに追加");
|
43 |
});
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
};
|
|
|
1 |
export default async ({ addon, console, msg }) => {
|
2 |
while (true) {
|
3 |
+
// 既存のメニューバーの最後の要素を取得(カスタムボタンが重複しないようにする)
|
4 |
+
const elem = await addon.tab.waitForElement(
|
5 |
+
'div[class*="menu-bar_file-group"] > div:last-child:not(.custom-menu)',
|
6 |
+
{
|
7 |
+
markAsSeen: true,
|
8 |
+
reduxEvents: [
|
9 |
+
"scratch-gui/mode/SET_PLAYER",
|
10 |
+
"fontsLoaded/SET_FONTS_LOADED",
|
11 |
+
"scratch-gui/locales/SELECT_LOCALE"
|
12 |
+
],
|
13 |
+
}
|
14 |
+
);
|
15 |
+
|
16 |
+
// カスタムメニューバーのボタンを作成
|
17 |
+
const menuBarButton = Object.assign(document.createElement("div"), {
|
18 |
+
className: "custom-menu " + elem.className,
|
19 |
+
textContent: msg("menu-button") || "メニュー",
|
20 |
});
|
21 |
+
|
22 |
+
// ボタンクリックでモーダルを表示
|
23 |
+
menuBarButton.addEventListener("click", () => {
|
24 |
+
// モーダル作成(addon.tab.createModal を利用)
|
25 |
+
const { backdrop, container, content, closeButton, remove } = addon.tab.createModal(
|
26 |
+
msg("menu-title") || "メニュー",
|
27 |
+
{
|
28 |
+
isOpen: true,
|
29 |
+
useEditorClasses: true,
|
30 |
+
}
|
31 |
+
);
|
32 |
+
|
33 |
+
// モーダル内に説明用のHTML要素を追加
|
34 |
+
const description = Object.assign(document.createElement("p"), {
|
35 |
+
textContent: msg("menu-description") || "ここに任意のHTML内容を記述できます。"
|
36 |
});
|
37 |
+
content.appendChild(description);
|
38 |
+
|
39 |
+
// 「Googleドライブに保存」ボタンを追加
|
40 |
+
const googleDriveButton = document.createElement("button");
|
41 |
+
googleDriveButton.textContent = "Googleドライブに保存";
|
42 |
+
googleDriveButton.addEventListener("click", () => {
|
43 |
+
// Googleドライブへの保存処理をここに記述
|
44 |
+
console.log("Googleドライブに保存ボタンがクリックされました");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
});
|
46 |
+
content.appendChild(googleDriveButton);
|
47 |
+
|
48 |
+
// 閉じるボタンを追加
|
49 |
+
const closeBtn = document.createElement("button");
|
50 |
+
closeBtn.textContent = msg("close") || "閉じる";
|
51 |
+
closeBtn.addEventListener("click", () => remove());
|
52 |
+
content.appendChild(closeBtn);
|
53 |
+
|
54 |
+
// backdropクリックでモーダルを閉じる
|
55 |
+
backdrop.addEventListener("click", () => remove());
|
56 |
+
closeButton.addEventListener("click", () => remove());
|
57 |
+
});
|
58 |
+
|
59 |
+
// カスタムボタンをメニューバーに追加
|
60 |
+
elem.parentElement.appendChild(menuBarButton);
|
61 |
}
|
62 |
};
|