Skip to content

Commit

Permalink
New extension: Close Control (#1384)
Browse files Browse the repository at this point in the history
Co-authored-by: Muffin <muffin@muffin.ink>
  • Loading branch information
xmeroriginals and GarboMuffin authored May 11, 2024
1 parent 1dd08d8 commit 0f8d972
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
69 changes: 69 additions & 0 deletions extensions/XmerOriginals/closecontrol.js
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);
1 change: 1 addition & 0 deletions extensions/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"CubesterYT/WindowControls",
"veggiecan/browserfullscreen",
"shreder95ua/resolution",
"XmerOriginals/closecontrol",
"navigator",
"battery",
"TheShovel/CustomStyles",
Expand Down
Loading

0 comments on commit 0f8d972

Please sign in to comment.