Spaces:
Running
Running
Update src/addons/addons/save-to-google/userscript.js
Browse files
src/addons/addons/save-to-google/userscript.js
CHANGED
@@ -31,20 +31,18 @@ export default async ({ addon, console, msg }) => {
|
|
31 |
const loginButton = modal.content.querySelector("#google-login-button");
|
32 |
if (loginButton) {
|
33 |
loginButton.addEventListener("click", () => {
|
34 |
-
// メッセージイベントリスナーを追加
|
35 |
const messageListener = (event) => {
|
36 |
if (event.origin === "https://soiz1-penguin-upload.hf.space" && event.data.token) {
|
37 |
window.removeEventListener("message", messageListener);
|
38 |
saveToGoogleDrive(event.data.token, modal.remove)
|
39 |
.catch(error => {
|
40 |
console.error("保存エラー:", error);
|
41 |
-
|
42 |
});
|
43 |
}
|
44 |
};
|
45 |
window.addEventListener("message", messageListener);
|
46 |
|
47 |
-
// OAuthポップアップを開く
|
48 |
const authUrl = `https://accounts.google.com/o/oauth2/auth?` +
|
49 |
`client_id=${CLIENT_ID}` +
|
50 |
`&redirect_uri=${encodeURIComponent(REDIRECT_URI)}` +
|
@@ -66,7 +64,7 @@ export default async ({ addon, console, msg }) => {
|
|
66 |
async function saveToGoogleDrive(accessToken, onSuccess) {
|
67 |
try {
|
68 |
const blob = await window.vm.saveProjectSb3();
|
69 |
-
const filename = window.vm.runtime.
|
70 |
|
71 |
const metadata = {
|
72 |
name: `${filename}.sb3`,
|
@@ -91,12 +89,22 @@ export default async ({ addon, console, msg }) => {
|
|
91 |
|
92 |
const data = await response.json();
|
93 |
console.log("ファイルがGoogleドライブに保存されました:", data);
|
94 |
-
|
95 |
if (onSuccess) onSuccess();
|
96 |
} catch (error) {
|
97 |
console.error("保存エラー:", error);
|
98 |
-
|
99 |
throw error;
|
100 |
}
|
101 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
};
|
|
|
31 |
const loginButton = modal.content.querySelector("#google-login-button");
|
32 |
if (loginButton) {
|
33 |
loginButton.addEventListener("click", () => {
|
|
|
34 |
const messageListener = (event) => {
|
35 |
if (event.origin === "https://soiz1-penguin-upload.hf.space" && event.data.token) {
|
36 |
window.removeEventListener("message", messageListener);
|
37 |
saveToGoogleDrive(event.data.token, modal.remove)
|
38 |
.catch(error => {
|
39 |
console.error("保存エラー:", error);
|
40 |
+
showAlert(addon, "error", "Googleドライブへの保存に失敗しました");
|
41 |
});
|
42 |
}
|
43 |
};
|
44 |
window.addEventListener("message", messageListener);
|
45 |
|
|
|
46 |
const authUrl = `https://accounts.google.com/o/oauth2/auth?` +
|
47 |
`client_id=${CLIENT_ID}` +
|
48 |
`&redirect_uri=${encodeURIComponent(REDIRECT_URI)}` +
|
|
|
64 |
async function saveToGoogleDrive(accessToken, onSuccess) {
|
65 |
try {
|
66 |
const blob = await window.vm.saveProjectSb3();
|
67 |
+
const filename = window.vm.runtime.projectName || "scratch-project";
|
68 |
|
69 |
const metadata = {
|
70 |
name: `${filename}.sb3`,
|
|
|
89 |
|
90 |
const data = await response.json();
|
91 |
console.log("ファイルがGoogleドライブに保存されました:", data);
|
92 |
+
showAlert(addon, "success", "Googleドライブに保存しました");
|
93 |
if (onSuccess) onSuccess();
|
94 |
} catch (error) {
|
95 |
console.error("保存エラー:", error);
|
96 |
+
showAlert(addon, "error", `保存に失敗しました: ${error.message}`);
|
97 |
throw error;
|
98 |
}
|
99 |
}
|
100 |
+
|
101 |
+
function showAlert(addon, type, message) {
|
102 |
+
addon.tab.redux.dispatch({
|
103 |
+
type: "scratch-gui/alerts/SHOW_ALERT",
|
104 |
+
payload: {
|
105 |
+
alertType: type,
|
106 |
+
message: message
|
107 |
+
}
|
108 |
+
});
|
109 |
+
}
|
110 |
};
|