-
Notifications
You must be signed in to change notification settings - Fork 344
Create ntfyscratch.js #2375
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
xmeroriginals
wants to merge
9
commits into
TurboWarp:master
Choose a base branch
from
xmeroriginals:master
base: master
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
Create ntfyscratch.js #2375
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e113241
Create ntfyscratch.js
xmeroriginals c637655
format - lint
xmeroriginals f9b3497
Scratch used
xmeroriginals 0112127
[Automated] Format code
DangoCat 01a9c12
!format
xmeroriginals 3c38b7d
Replace "text"s to Scratch.translate("text") texts
xmeroriginals f04dc65
remove format line at top
Brackets-Coder 4541d72
[Automated] Format code
DangoCat bb128d3
Enhance "ntfyScratch" with advanced notification features
xmeroriginals 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
Some comments aren't visible on the classic Files Changed page.
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,139 @@ | ||
| // !format | ||
| // Name: ntfyScratch | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scratch is a trademark; i suggest you change this to something like turbontfy or |
||
| // ID: ntfyScratch | ||
| // Description: Send notifications from your Scratch project to your phone, tablet, or computer using ntfy.sh. Instantly receive messages, alerts, and status updates from your project in real time. | ||
| // By: XmerOriginals <https://scratch.mit.edu/users/XmerOriginals/> | ||
| // License: MPL-2.0 | ||
|
|
||
| (function (Scratch) { | ||
| 'use strict'; | ||
|
|
||
| class ntfyScratch { | ||
| getInfo() { | ||
| return { | ||
| id: 'ntfyScratch', | ||
| name: Scratch.translate("ntfyScratch"), | ||
| color1: '#55bba6', | ||
| color2: '#358876', | ||
| blocks: [ | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe use docsURI here |
||
| func: 'openDoc', | ||
| blockType: Scratch.BlockType.BUTTON, | ||
| text: Scratch.translate("Documentation") | ||
| }, | ||
| { | ||
| func: 'openDocNtfy', | ||
| blockType: Scratch.BlockType.BUTTON, | ||
| text: Scratch.translate("ntfy.sh Documentation") | ||
| }, | ||
| '---', | ||
| { | ||
| opcode: 'sendSimpleNotification', | ||
| blockType: Scratch.BlockType.COMMAND, | ||
| text: Scratch.translate("send message [MESSAGE] to topic [TOPIC]"), | ||
| arguments: { | ||
| TOPIC: { | ||
| type: Scratch.ArgumentType.STRING, | ||
| defaultValue: 'mytopic' | ||
| }, | ||
| MESSAGE: { | ||
| type: Scratch.ArgumentType.STRING, | ||
| defaultValue: 'Hello from TurboWarp!' | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| opcode: 'sendFullNotification', | ||
| blockType: Scratch.BlockType.COMMAND, | ||
| text: Scratch.translate("send notification to [TOPIC] title [TITLE] message [MESSAGE] priority [PRIORITY] tags [TAGS]"), | ||
| arguments: { | ||
| TOPIC: { | ||
| type: Scratch.ArgumentType.STRING, | ||
| defaultValue: 'mytopic' | ||
| }, | ||
| TITLE: { | ||
| type: Scratch.ArgumentType.STRING, | ||
| defaultValue: 'Alert' | ||
| }, | ||
| MESSAGE: { | ||
| type: Scratch.ArgumentType.STRING, | ||
| defaultValue: 'Project is running' | ||
| }, | ||
| PRIORITY: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 3, | ||
| menu: 'priorityMenu' | ||
| }, | ||
| TAGS: { | ||
| type: Scratch.ArgumentType.STRING, | ||
| defaultValue: 'star,computer' | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| menus: { | ||
| priorityMenu: { | ||
| acceptReporters: true, | ||
| items: [ | ||
| { text: 'Max (5)', value: '5' }, | ||
| { text: 'High (4)', value: '4' }, | ||
| { text: 'Default (3)', value: '3' }, | ||
| { text: 'Low (2)', value: '2' }, | ||
| { text: 'Min (1)', value: '1' } | ||
| ] | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| sendSimpleNotification(args) { | ||
| const topic = args.TOPIC; | ||
| const message = args.MESSAGE; | ||
|
|
||
| Scratch.fetch(`https://ntfy.sh/${topic}`, { | ||
| method: 'POST', | ||
| body: message | ||
| }).catch((err) => { | ||
| console.warn('ntfyScratch: Failed to send simple notification', err); | ||
| }); | ||
| } | ||
|
|
||
| sendFullNotification(args) { | ||
| const bodyData = { | ||
| topic: args.TOPIC, | ||
| title: args.TITLE, | ||
| message: args.MESSAGE, | ||
| priority: parseInt(args.PRIORITY), | ||
| tags: args.TAGS.split(',').map((tag) => tag.trim()) | ||
| }; | ||
|
|
||
| Scratch.fetch('https://ntfy.sh/', { | ||
| method: 'POST', | ||
| body: JSON.stringify(bodyData), | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| } | ||
| }).catch((err) => { | ||
| console.warn('ntfyScratch: Failed to send full notification', err); | ||
| }); | ||
| } | ||
|
|
||
| _openUrl(url) { | ||
| Scratch.canOpenWindow(url).then((allowed) => { | ||
| if (allowed) { | ||
| Scratch.openWindow(url, '_blank'); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| openDoc() { | ||
| this._openUrl('http://xelabs.xmeroriginals.com/docs/ntfyScratch/'); | ||
| } | ||
|
|
||
| openDocNtfy() { | ||
| this._openUrl('https://ntfy.sh/docs/'); | ||
| } | ||
| } | ||
|
|
||
| Scratch.extensions.register(new ntfyScratch()); | ||
| })(Scratch); | ||
Oops, something went wrong.
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.