Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions extensions/Jeandongjun/SweetAlert2/SweetAlert2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
(function() {
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/sweetalert2@11';
document.head.appendChild(script);
Comment on lines +2 to +4

@BenPaoDeXiaoZhi BenPaoDeXiaoZhi Jun 30, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccw估计不会允许全局lib污染,建议把官方的build import进来


script.onload = function() {
class SweetAlert2Extension {
constructor(runtime) {
this.runtime = runtime;
}

getInfo() {
return {
id: 'sweetalert2',
name: 'SweetAlert2',
blocks: [
{
opcode: 'showAlert',
blockType: Scratch.BlockType.COMMAND,
text: '显示 [ICON] 提示框 标题 [TITLE] 内容 [SUBTITLE] 按钮一 [BUTTON1TEXT] 颜色 [BUTTON1COLOR] 按钮二 [BUTTON2TEXT] 颜色 [BUTTON2COLOR]',
arguments: {
ICON: {
type: Scratch.ArgumentType.STRING,
menu: 'iconMenu',
defaultValue: 'info'
},
TITLE: {
type: Scratch.ArgumentType.STRING,
defaultValue: '标题'
},
SUBTITLE: {
type: Scratch.ArgumentType.STRING,
defaultValue: '内容'
},
BUTTON1TEXT: {
type: Scratch.ArgumentType.STRING,
defaultValue: '确定'
},
BUTTON1COLOR: {
type: Scratch.ArgumentType.STRING,
defaultValue: '' // No default color
},
BUTTON2TEXT: {
type: Scratch.ArgumentType.STRING,
defaultValue: ''
},
BUTTON2COLOR: {
type: Scratch.ArgumentType.STRING,
defaultValue: '' // No default color
}
}
}
],
menus: {
iconMenu: {
acceptReporters: false,
items: ['warning', 'error', 'success', 'info', 'question']
}
}
};
}

showAlert(args) {
const swalIcons = {
warning: 'warning',
error: 'error',
success: 'success',
info: 'info',
question: 'question'
};
const buttons = [
{
text: args.BUTTON1TEXT,
value: args.BUTTON1TEXT,
visible: true,
className: 'swal-button--custom',
style: args.BUTTON1COLOR ? `background-color: ${args.BUTTON1COLOR};` : ''
}
];

if (args.BUTTON2TEXT) {
buttons.push({
text: args.BUTTON2TEXT,
value: args.BUTTON2TEXT,
visible: true,
className: 'swal-button--custom',
style: args.BUTTON2COLOR ? `background-color: ${args.BUTTON2COLOR};` : ''
});
}

Swal.fire({
icon: swalIcons[args.ICON],
title: args.TITLE,
text: args.SUBTITLE,
confirmButtonText: args.BUTTON1TEXT,
confirmButtonColor: args.BUTTON1COLOR,
showCancelButton: args.BUTTON2TEXT !== '',
cancelButtonText: args.BUTTON2TEXT,
cancelButtonColor: args.BUTTON2COLOR,
buttons: buttons
});
}
}

Scratch.extensions.register(new SweetAlert2Extension());
};
})();