soiz1 commited on
Commit
b9140e1
·
verified ·
1 Parent(s): 460f045

Update src/addons/addons/save-to-google/userscript.js

Browse files
src/addons/addons/save-to-google/userscript.js CHANGED
@@ -1,62 +1,41 @@
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
  };
 
1
  export default async ({ addon, console, msg }) => {
2
  while (true) {
3
+ const elem = await addon.tab.waitForElement('div[class*="menu-bar_file-group"] > div:last-child:not(.custom-menu)', {
4
+ markAsSeen: true,
5
+ reduxEvents: ["scratch-gui/mode/SET_PLAYER", "fontsLoaded/SET_FONTS_LOADED", "scratch-gui/locales/SELECT_LOCALE"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  });
7
+
8
+ const createModal = () => {
9
+ const { backdrop, container, content, closeButton, remove } = addon.tab.createModal("カスタムメニュー", {
10
+ isOpen: true,
11
+ useEditorClasses: true,
 
 
 
 
 
 
 
 
 
 
12
  });
13
+ container.classList.add("customModal");
14
+ content.classList.add("customModalContent");
15
+
16
+ content.innerHTML = `
17
+ <h2>カスタムメニュー</h2>
18
+ <p>ここに好きなHTMLコンテンツを追加できます。</p>
19
+ <button id="saveToDrive">Googleドライブに保存</button>
20
+ `;
21
+
22
+ document.getElementById("saveToDrive").addEventListener("click", () => {
23
+ console.log("Googleドライブに保存処理を実行(実装は省略)");
24
+ alert("Googleドライブに保存しました!(仮)");
25
  });
26
+
27
+ backdrop.addEventListener("click", remove);
28
+ closeButton.addEventListener("click", remove);
29
+ };
30
+
31
+ if (!document.querySelector(".custom-menu")) {
32
+ const menuElem = Object.assign(document.createElement("div"), {
33
+ className: "custom-menu " + elem.className,
34
+ textContent: "カスタムメニュー",
35
+ });
36
+
37
+ menuElem.addEventListener("click", createModal);
38
+ elem.parentElement.appendChild(menuElem);
39
+ }
 
40
  }
41
  };