-
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.
Add NexusKitten/controlcontrols extension (#883)
- Loading branch information
1 parent
c3cca77
commit d7c46eb
Showing
2 changed files
with
158 additions
and
1 deletion.
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,156 @@ | ||
// Name: Control Controls | ||
// ID: nkcontrols | ||
// Description: Show and hide the project's controls. | ||
// By: NamelessCat <https://scratch.mit.edu/users/NexusKitten/> | ||
|
||
(function (Scratch) { | ||
'use strict'; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('Control Controls must run unsandboxed'); | ||
} | ||
|
||
var fullScreen; | ||
var greenFlag; | ||
var pauseButton; | ||
var stopButton; | ||
|
||
const getButtons = () => { | ||
fullScreen = undefined; | ||
greenFlag = undefined; | ||
pauseButton = undefined; | ||
stopButton = undefined; | ||
|
||
const rightButtons = document.querySelectorAll('[class*="stage-header_stage-button_"]'); | ||
fullScreen = rightButtons[rightButtons.length - 1]; | ||
if (!fullScreen) { | ||
fullScreen = document.querySelector('.fullscreen-button') || document.querySelector('.standalone-fullscreen-button'); | ||
} | ||
|
||
greenFlag = document.querySelector('[class*="green-flag_green-flag_"]') || document.querySelector('.green-flag-button'); | ||
pauseButton = document.querySelector('.pause-btn') || document.querySelector('.pause-button'); | ||
stopButton = document.querySelector('[class*="stop-all_stop-all_"]') || document.querySelector('.stop-all-button'); | ||
}; | ||
|
||
class controlcontrols { | ||
getInfo() { | ||
return { | ||
id: 'nkcontrols', | ||
name: 'Control Controls', | ||
color1: '#ffab19', | ||
color2: '#ec9c13', | ||
color3: '#b87d17', | ||
blocks: [ | ||
{ | ||
opcode: 'showOption', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'show [OPTION]', | ||
arguments: { | ||
OPTION: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'OPTION' | ||
} | ||
} | ||
}, | ||
{ | ||
opcode: 'hideOption', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'hide [OPTION]', | ||
arguments: { | ||
OPTION: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'OPTION' | ||
} | ||
} | ||
}, | ||
'---', | ||
{ | ||
opcode: 'optionShown', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: '[OPTION] shown?', | ||
arguments: { | ||
OPTION: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'OPTION' | ||
} | ||
} | ||
}, | ||
'---', | ||
{ | ||
opcode: 'optionExists', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: '[OPTION] exists?', | ||
arguments: { | ||
OPTION: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'OPTION' | ||
} | ||
} | ||
}, | ||
], | ||
menus: { | ||
OPTION: { | ||
acceptReporters: true, | ||
items: ['green flag', 'pause', 'stop', 'fullscreen'] | ||
} | ||
} | ||
}; | ||
} | ||
|
||
showOption(args) { | ||
getButtons(); | ||
if (args.OPTION === "green flag" && greenFlag) { | ||
greenFlag.style.display = 'block'; | ||
} else if (args.OPTION === "pause" && pauseButton) { | ||
pauseButton.style.display = 'block'; | ||
} else if (args.OPTION === "stop" && stopButton) { | ||
stopButton.style.display = 'block'; | ||
} else if (args.OPTION === "fullscreen" && fullScreen) { | ||
fullScreen.style.display = 'block'; | ||
} | ||
} | ||
|
||
hideOption(args) { | ||
getButtons(); | ||
if (args.OPTION === "green flag" && greenFlag) { | ||
greenFlag.style.display = 'none'; | ||
} else if (args.OPTION === "pause" && pauseButton) { | ||
pauseButton.style.display = 'none'; | ||
} else if (args.OPTION === "stop" && stopButton) { | ||
stopButton.style.display = 'none'; | ||
} else if (args.OPTION === "fullscreen" && fullScreen) { | ||
fullScreen.style.display = 'none'; | ||
} | ||
} | ||
|
||
optionShown(args) { | ||
getButtons(); | ||
if (args.OPTION === "green flag" && greenFlag) { | ||
return greenFlag.style.display !== 'none'; | ||
} else if (args.OPTION === "pause" && pauseButton) { | ||
return pauseButton.style.display !== 'none'; | ||
} else if (args.OPTION === "stop" && stopButton) { | ||
return stopButton.style.display !== 'none'; | ||
} else if (args.OPTION === "fullscreen" && fullScreen) { | ||
return fullScreen.style.display !== 'none'; | ||
} | ||
return false; | ||
} | ||
|
||
optionExists(args) { | ||
getButtons(); | ||
if (args.OPTION === "green flag" && greenFlag) { | ||
return true; | ||
} else if (args.OPTION === "pause" && pauseButton) { | ||
return true; | ||
} else if (args.OPTION === "stop" && stopButton) { | ||
return true; | ||
} else if (args.OPTION === "fullscreen" && fullScreen) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} | ||
Scratch.extensions.register(new controlcontrols()); | ||
})(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