Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
xmeroriginals authored Sep 22, 2024
1 parent 77f0d6f commit c18e452
Showing 1 changed file with 105 additions and 92 deletions.
197 changes: 105 additions & 92 deletions extensions/XmerOriginals/sweetalert.js
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({

Check failure on line 81 in extensions/XmerOriginals/sweetalert.js

View workflow job for this annotation

GitHub Actions / lint

'Swal' is not defined
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({

Check failure on line 96 in extensions/XmerOriginals/sweetalert.js

View workflow job for this annotation

GitHub Actions / lint

'Swal' is not defined
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);

0 comments on commit c18e452

Please sign in to comment.