-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77f0d6f
commit c18e452
Showing
1 changed file
with
105 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,125 @@ | ||
// Name: Sweet Alert | ||
// ID: sweetalert | ||
// Description: It allows you to send modern alerts using the Sweet Alert library. | ||
// By: XmerOriginals | ||
// Description: It allows you to send modern alerts using the Sweet Alert library. 'https://cdn.jsdelivr.net/npm/sweetalert2@11' | ||
// By: XmerOriginals <https://scratch.mit.edu/users/XmerOriginals/> | ||
// License: MPL-2.0 | ||
|
||
class SweetAlert { | ||
(function (Scratch) { | ||
"use strict"; | ||
|
||
getInfo() { | ||
return { | ||
id: 'sweetalert', | ||
name: 'Sweet Alert', | ||
color1: '#425436', | ||
blocks: [ | ||
{ | ||
opcode: 'showAlert', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'show sweet alert with title [TITLE] and text [TEXT] of type [TYPE]', | ||
arguments: { | ||
TITLE: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'Title', | ||
}, | ||
TEXT: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'This is a modern alert!', | ||
}, | ||
TYPE: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'alertTypes', | ||
defaultValue: 'success', | ||
|
||
class SweetAlert { | ||
getInfo() { | ||
return { | ||
id: 'sweetalert', | ||
name: 'Sweet Alert', | ||
color1: '#425436', | ||
blocks: [ | ||
{ | ||
opcode: 'showAlert', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'show sweet alert with title [TITLE] and text [TEXT] of type [TYPE] button text [BTEXT]', | ||
arguments: { | ||
TITLE: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'Title', | ||
}, | ||
TEXT: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'This is a modern alert!', | ||
}, | ||
BTEXT: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'OK', | ||
}, | ||
TYPE: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'alertTypes', | ||
defaultValue: 'success', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
opcode: 'showInputAlert', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'ask [QUESTION] with default [DEFAULT_TEXT] of type [TYPE]', | ||
arguments: { | ||
QUESTION: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'What is your name?', | ||
}, | ||
DEFAULT_TEXT: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'Enter your name here...', | ||
}, | ||
TYPE: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'alertTypes', | ||
defaultValue: 'question', | ||
{ | ||
opcode: 'showInputAlert', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'ask [QUESTION] with default [DEFAULT_TEXT] of type [TYPE] empty text warn [EMTEXT]', | ||
arguments: { | ||
QUESTION: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'What is your name?', | ||
}, | ||
DEFAULT_TEXT: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'Enter your name here...', | ||
}, | ||
EMTEXT: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'You need to enter something!', | ||
}, | ||
TYPE: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'alertTypes', | ||
defaultValue: 'question', | ||
}, | ||
}, | ||
}, | ||
], | ||
menus: { | ||
alertTypes: { | ||
acceptReporters: true, | ||
items: ['success', 'error', 'warning', 'info', 'question'], | ||
}, | ||
}, | ||
], | ||
menus: { | ||
alertTypes: { | ||
acceptReporters: true, | ||
items: ['success', 'error', 'warning', 'info', 'question'], | ||
}, | ||
}, | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
showAlert(args) { | ||
const title = args.TITLE; | ||
const text = args.TEXT; | ||
const type = args.TYPE; | ||
showAlert(args) { | ||
const title = args.TITLE; | ||
const text = args.TEXT; | ||
const btext = args.BTEXT; | ||
const type = args.TYPE; | ||
|
||
Swal.fire({ | ||
title: title, | ||
text: text, | ||
icon: type, | ||
confirmButtonText: 'OK', | ||
}); | ||
} | ||
|
||
showInputAlert(args) { | ||
const question = args.QUESTION; | ||
const defaultText = args.DEFAULT_TEXT; | ||
const type = args.TYPE; | ||
|
||
return new Promise((resolve) => { | ||
Swal.fire({ | ||
title: question, | ||
input: 'text', | ||
inputPlaceholder: defaultText, | ||
title: title, | ||
text: text, | ||
icon: type, | ||
showCancelButton: true, | ||
inputValidator: (value) => { | ||
if (!value) { | ||
return 'You need to enter something!'; | ||
confirmButtonText: btext, | ||
}); | ||
} | ||
|
||
showInputAlert(args) { | ||
const question = args.QUESTION; | ||
const defaultText = args.DEFAULT_TEXT; | ||
const emtext = args.EMTEXT; | ||
const type = args.TYPE; | ||
|
||
return new Promise((resolve) => { | ||
Swal.fire({ | ||
title: question, | ||
input: 'text', | ||
inputPlaceholder: defaultText, | ||
icon: type, | ||
showCancelButton: true, | ||
inputValidator: (value) => { | ||
if (!value) { | ||
return emtext; | ||
} | ||
}, | ||
}).then((result) => { | ||
if (result.isConfirmed && result.value) { | ||
resolve(result.value); | ||
} else { | ||
resolve(null); | ||
} | ||
}, | ||
}).then((result) => { | ||
if (result.isConfirmed && result.value) { | ||
resolve(result.value); | ||
} else { | ||
resolve(null); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
const script = document.createElement('script'); | ||
script.src = 'https://cdn.jsdelivr.net/npm/sweetalert2@11'; | ||
document.head.appendChild(script); | ||
const script = document.createElement('script'); | ||
script.src = 'https://cdn.jsdelivr.net/npm/sweetalert2@11'; | ||
script.onload = () => { | ||
Scratch.extensions.register(new SweetAlert()); | ||
}; | ||
document.head.appendChild(script); | ||
|
||
Scratch.extensions.register(new SweetAlert()); | ||
})(Scratch); |