-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4ndyQuestionUtilities.js
More file actions
128 lines (115 loc) · 3.73 KB
/
4ndyQuestionUtilities.js
File metadata and controls
128 lines (115 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
class FourndyNotificationSystem {
constructor() {
this.activeNotifications = [];
this.lastAnswer = 'No answer';
}
getInfo() {
return {
id: '4ndyQuestionUtilities',
name: '4ndyQuestionUtilities',
blocks: [
{
opcode: 'askQuestion',
blockType: Scratch.BlockType.COMMAND,
text: 'Ask a question with [MESSAGE]',
arguments: {
MESSAGE: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'What is your name?'
}
}
},
{
opcode: 'askTimedQuestion',
blockType: Scratch.BlockType.COMMAND,
text: 'Ask a timed question with [MESSAGE] for [SECONDS] seconds',
arguments: {
MESSAGE: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'What is your name?'
},
SECONDS: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 5
}
}
},
{
opcode: 'getLastAnswer',
blockType: Scratch.BlockType.REPORTER,
text: 'Last answer',
arguments: {}
},
{
opcode: 'getLastQuestion',
blockType: Scratch.BlockType.REPORTER,
text: 'Last question asked',
arguments: {}
}
]
};
}
askQuestion(args) {
this.displayMessageToBeAnswered(args.MESSAGE);
}
askTimedQuestion(args) {
this.displayMessageToBeAnswered(args.MESSAGE, args.SECONDS);
}
getLastAnswer() {
return this.lastAnswer;
}
getLastQuestion() {
return this.activeNotifications.length > 0 ? this.activeNotifications[this.activeNotifications.length - 1] : 'No questions asked';
}
displayMessageToBeAnswered(message, timeout) {
const modal = document.createElement('div');
modal.className = 'notification-modal';
modal.style.position = 'fixed';
modal.style.top = '50%';
modal.style.left = '50%';
modal.style.transform = 'translate(-50%, -50%)';
modal.style.backgroundColor = '#333333';
modal.style.padding = '20px';
modal.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.7)';
modal.style.zIndex = '9999';
modal.style.maxWidth = '300px';
modal.style.borderRadius = '10px';
modal.style.border = '3px solid #880000';
const messageElement = document.createElement('p');
messageElement.textContent = message;
messageElement.style.color = '#FFCCCC';
modal.appendChild(messageElement);
const inputElement = document.createElement('input');
inputElement.type = 'text';
inputElement.placeholder = 'Type your answer...';
inputElement.style.backgroundColor = '#444444';
inputElement.style.color = '#FFFFFF';
inputElement.style.border = '1px solid #880000';
inputElement.style.padding = '5px';
modal.appendChild(inputElement);
const submitButton = document.createElement('button');
submitButton.textContent = 'Submit';
submitButton.style.marginTop = '10px';
submitButton.style.backgroundColor = '#990000';
submitButton.style.color = 'white';
submitButton.style.border = 'none';
submitButton.style.padding = '10px';
submitButton.style.cursor = 'pointer';
submitButton.onclick = () => {
this.lastAnswer = inputElement.value || 'No answer';
this.activeNotifications.push(message);
document.body.removeChild(modal);
};
modal.appendChild(submitButton);
document.body.appendChild(modal);
if (timeout) {
setTimeout(() => {
if (document.body.contains(modal)) {
document.body.removeChild(modal);
this.lastAnswer = 'No answer';
}
}, timeout * 1000);
}
}
}
Scratch.extensions.register(new FourndyNotificationSystem());