-
Notifications
You must be signed in to change notification settings - Fork 173
Add Quantum Randomness extension for Scratch #513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DashDevmationsDash
wants to merge
5
commits into
PenguinMod:main
Choose a base branch
from
DashDevmationsDash:patch-4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
698e685
Add Quantum Randomness extension for Scratch
DashDevmationsDash 3e7b949
Its Now Serialization Based Yay
DashDevmationsDash f4c00e1
Handle fetch timeout with warning and default return
DashDevmationsDash 75e3cf3
Refactor apikey handling in Quantum Randomness.js
DashDevmationsDash 75e0e86
Fix timeout handling in Quantum Randomness.js
DashDevmationsDash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,104 @@ | ||
| (function (Scratch) { | ||
| 'use strict'; | ||
| class Extension { | ||
| constructor() { | ||
| let apikey = '' | ||
| } | ||
| serialize() { | ||
| return { | ||
| apikey: apikey | ||
| }; | ||
| } | ||
| deserialize(data) { | ||
| apikey = data?.apikey || ''; | ||
| } | ||
| getInfo() { | ||
| return { | ||
| id: 'anuqrngisfreakingawesome', | ||
| name: 'Quantum Randomness', | ||
| color1: '#21ab61', | ||
| blocks: [ | ||
| { | ||
| opcode: 'how2getapikey', | ||
DashDevmationsDash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| text: 'How To Get An Api Key', | ||
| blockType: Scratch.BlockType.BUTTON | ||
| }, | ||
| { | ||
| opcode: 'setapikey', | ||
| text: 'Set Api Key', | ||
| blockType: Scratch.BlockType.BUTTON | ||
| }, | ||
| { | ||
| opcode: 'nrandomnumbers', | ||
| text: 'Get Random Number Inbetween [MIN] To [MAX]', | ||
| blockType: Scratch.BlockType.REPORTER, | ||
| arguments: { | ||
| MIN: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 1 | ||
| }, | ||
| MAX: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 10 | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
|
|
||
| how2getapikey() { | ||
| alert( | ||
| "How To Get An Api Key(100% Clickbait)(Cops Called)(At 3 Am)Works In 2026\n\n" + | ||
| "1. Go to https://quantumnumbers.anu.edu.au/\n\n" + | ||
| "2. Create an account or log in.\n\n" + | ||
| "3. Open your Dashboard or Account page.\n\n" + | ||
| "4. Locate your API Key section.\n\n" + | ||
| "5. Copy your Free API Key.\n\n" + | ||
| "6. Click On 'Set API Key' Button.\n\n" + | ||
| "7. Paste Your Api Key.\n\n" + | ||
| "8. Click On Ok" | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| async nrandomnumbers(args) { | ||
| let min = Number(args.MIN); | ||
| let max = Number(args.MAX); | ||
| if (min > max) [min, max] = [max, min]; | ||
| if (min === max) return min; | ||
| try { | ||
| const controller = new AbortController(); | ||
| const timeout = setTimeout(() => { | ||
| controller.abort(); | ||
| console.warn('[INSERT TIMEOUT ERRROR]'); | ||
| }, 3000); | ||
|
|
||
| const response = await fetch( | ||
| 'https://api.quantumnumbers.anu.edu.au?length=1&type=uint8', | ||
| { | ||
| headers: { | ||
| 'x-api-key': this.apikey | ||
| }, | ||
| signal: controller.signal | ||
| } | ||
| ); | ||
| clearTimeout(timeout); | ||
| const json = await response.json(); | ||
| const quantumValue = json.data[0] / 255; | ||
|
|
||
| return Math.floor(min + quantumValue * (max - min + 1)); | ||
|
|
||
| } catch (error) { | ||
| clearTimeout(timeout); | ||
| console.warn("Quantum API failed, Error:", error); | ||
| } | ||
DashDevmationsDash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| setapikey() { | ||
| apikey = prompt('Insert Api Key'); | ||
| } | ||
| } | ||
|
|
||
| Scratch.extensions.register(new Extension()); | ||
| })(Scratch); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.