-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New extension: Close Control (#1384)
Co-authored-by: Muffin <[email protected]>
- Loading branch information
1 parent
1dd08d8
commit 0f8d972
Showing
3 changed files
with
97 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Name: Close Control | ||
// ID: xmerclosecontrol | ||
// Description: Ask before closing the tab. | ||
// By: XmerOriginals | ||
// License: MPL-2.0 | ||
|
||
(function (Scratch) { | ||
"use strict"; | ||
|
||
let enabled = false; | ||
|
||
window.addEventListener("beforeunload", (e) => { | ||
if (enabled) { | ||
e.preventDefault(); | ||
} | ||
}); | ||
|
||
class CloseControl { | ||
getInfo() { | ||
return { | ||
id: "xmerclosecontrol", | ||
name: Scratch.translate("Close Control"), | ||
blocks: [ | ||
{ | ||
opcode: "setControl", | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: Scratch.translate("set ask before closing tab to [OPTION]"), | ||
arguments: { | ||
OPTION: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: "option", | ||
}, | ||
}, | ||
}, | ||
{ | ||
opcode: "getControl", | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: Scratch.translate("is close control enabled?"), | ||
}, | ||
], | ||
menus: { | ||
option: { | ||
acceptReporters: true, | ||
items: [ | ||
{ | ||
text: Scratch.translate("enabled"), | ||
value: "true", | ||
}, | ||
{ | ||
text: Scratch.translate("disabled"), | ||
value: "false", | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
setControl({ OPTION }) { | ||
enabled = Scratch.Cast.toBoolean(OPTION); | ||
} | ||
|
||
getControl() { | ||
return enabled; | ||
} | ||
} | ||
|
||
Scratch.extensions.register(new CloseControl()); | ||
})(Scratch); |
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
Oops, something went wrong.