diff --git a/extensions/Alestore/nfcwarp.js b/extensions/Alestore/nfcwarp.js new file mode 100644 index 0000000000..c731f04095 --- /dev/null +++ b/extensions/Alestore/nfcwarp.js @@ -0,0 +1,73 @@ +(function(Scratch) { + 'use strict'; + + /* globals NDEFReader */ + + const extIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAACXBIWXMAAAsTAAALEwEAmpwYAAACN0lEQVR4nK2WzW7TQBDHDRIVHCr6CYV+PUG5hENvlpKdfyxX6q0SanmVqo+AkKqqPAG8CAVE1RJaKYn6cSiiIO70RBnYydi4ttcJjiPtIbsz/59nPZ4Zz9MfEz1nog8MXDHAhYvoGxPtMDAvvrXaHQZeJ2ysxnsGNiL9HgR4lRK6YOB8AOAPNmZJNJaX76lf2m73XyTZwwM2ZoGBswFgLfa8W6q16bBb9zTEDEgjnWei074wgMTemKeOh9nzHO9EQOIcBHNMdNInqheJ67vOOf/pOZxjkAjU67MMdAtAe4mkusyzKQTx6uooAxN6LY+ZqOMAXSYSq/v/oDBclMRoNCblf7P5iInaOaBrm+IKOiwLskKf2Pen9GoeMHCU8THmvoIOyoMGgdXrD6sBRd+MC2bMwvAg+y0RHcewIJjW1J+OsywMF6uIaF9Egc8Ka3MYzqjwfqWgRAStGGazsFKQvZ6b19XS/eO4Hg4F6hXWaO/IJoDs+/6UZGHSZ8iIZlJZ17EVQs5WVsYZ+FgNqCfGTpjvj8WwkqBDcVpbG2Hgdw6sbRNBbBqNSREvBSLqJIrkd5cNR5EBE7YAl4noawKU1xhZV9e2kNRY4ARlGx/RL/b9u+r4sgDE0hSDYK4QpI3vnUOkpineLARBS1Q0EeWD3tqDDYfzpjhubd2OS0/xOtPvLg/0LAp3N+fwi50BtBo8kdGqP+w8M3IR7aRnu3Xb+2+8M6I3cee0Qwqw7ZoJUutKtKJI/gr8AfOqgU5hKhA4AAAAAElFTkSuQmCC'; + const blocksIcon = 'data:image/svg+xml;base64,PHN2ZyB4bW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wOCAtMzExIDUzNiAtNTI1IDc1NiAtMjIxIDIyNyAtNDQxIDM4NiAtNzM1IDUzMSAtMjY2IDEzMSAtNTM2IDIyMyAtODgzIDMwMSBsLTE1NCAzNCAtMjU5NiAtMSBjLTE0MjkgLTEgLTI2MzYgLTUgLTI2ODUgLTEweiIgZmlsbD0iI2ZmZmZmZiIvPgo8L2c+Cjwvc3ZnPg=='; + + class NFCWarp { + getInfo() { + return { + id: 'alestorenfc', + name: 'NFCWarp', + color1: '#FF4646', + color2: '#FF0000', + color3: '#990033', + menuIconURI: extIcon, + blockIconURI: blocksIcon, + blocks: [ + { + blockType: Scratch.BlockType.LABEL, + text: 'Only works in Chrome on Android' + }, + { + opcode: 'supported', + blockType: Scratch.BlockType.BOOLEAN, + text: 'NFC supported?' + }, + { + opcode: 'nfcRead', + blockType: Scratch.BlockType.REPORTER, + text: 'read NFC tag', + disableMonitor: true + } + ] + }; + } + + supported () { + return typeof NDEFReader !== 'undefined'; + } + + nfcRead() { + if (!this.supported()) { + return 'NFC not supported'; + } + return new Promise((resolve, reject) => { + const ndef = new NDEFReader(); + ndef.scan() + .then(() => { + ndef.onreadingerror = event => { + console.log('Reading error', event); + resolve('Tag not supported'); + }; + ndef.onreading = evt => { + const decoder = new TextDecoder(); + const record = evt.message.records[0]; + console.log('Record type: ' + record.recordType); + console.log('Record encoding: ' + record.encoding); + console.log('Record data: ' + decoder.decode(record.data)); + resolve(decoder.decode(record.data)); + }; + }) + .catch(error => { + console.log('Scan error', error); + resolve(`Error: ${error}`); + }); + }); + } + } + + Scratch.extensions.register(new NFCWarp()); +})(Scratch); diff --git a/website/index.ejs b/website/index.ejs index 523fbc7434..a77b6c91eb 100644 --- a/website/index.ejs +++ b/website/index.ejs @@ -698,6 +698,12 @@
Allows you to use webhooks. Created by CubesterYT.
+Allows reading data from NFC (NDEF) devices. Only works in Chrome on Android. Created by Alestore Games.
+