Skip to content

Commit

Permalink
Create nfcwarp.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Alestore committed Jun 23, 2023
1 parent f76fab4 commit 4004fd9
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions extensions/nfcwarp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const blocksIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAYAAADFeBvrAAAACXBIWXMAAAsTAAALEwEAmpwYAAADkklEQVR4nNWaz0tVQRTHbxaBUhjhLihBWkWrohaG6zTCMPthRQXmD1AzMDPBnf9CLVw8dFNQWhsrWyRF+Q9Yu35Y7SqTFgW+tPzE0XnxvM68O/Pu+N71u3xvzpnzeWfO3Hl3ThBoBOwA2oHHwCcgTXz9AB4CrUCZYd4KYNxgn1axSExtEqPOR9jhJqAbmGN99Q3oBbZoYtgKvLLw8R24KjGbYMqAsQgns/jVJLBNE0slMG/pYxQo1WUmCkaUAgbwqydAiQbqloOP+6sypZaZjVJqfD9+1akBqnL00ZW9Acy5ACm7Pvzpi9SOBmrawYfUVHmgdjNcgdSEUti+dEYDNOjoozVQazgvIDVpD340qfFd5+jjkRh9jgOkJr4GLBFPv8O7FSu7nYtmAseHphYoa2OJC3Uk5LME+OVgnxYjfACpALpiQt3Q+Hzj4sArkAqgIwbUHY2/qaICqSBagL+464XG19OCAQGHgeMGqCt5QL3X+BkrJFCNOnPVesrUfPiwCYwUGgi1U9YZoJodoXaG7FPFAMo8R+oNUE3AH8s5diUFKArqLLBItKqSBJSBOhEDal/SgEQLOaBOR0AdSCJQVKZy1VR1UoEymWowQJ0yZKomSUBvNb98Lijd8ksU0JCh8AWq0QA1nGigYOXzRg2UZO6cBmgo8UBZUAsaqPPBRgQSAScNUBc2JJANVNKBhrO/t4BqSjrQomzFBqgGA9S7JAOtqZHQ+GMWL2WKClRtGLe8nAxQ9epYlEiggznGCtRFA1RtjkwVFWh/xHiBupQDaj5pQHstbOTv92UHqKIC7ba0k/d07QaooyGoogJVONhKppoNUHVZNVVQoBHNzV/aEaolYvkVFGhUE8iMow9Zfm05lt+hQgJNaIJ4ibuWdNeQBsjUegJNaSa8S34SqI5iA73WTHiT/LX0/7LXI1DaYfxPzbvnqBclNlDdnoDSYvDRMYA9oQlLI85mtur3APQhUL0zLlrzUh54jh/1xAQaD1QjkIsGNZPKHzVf6o0B1JJpvJCmBVtNGxqOvuJPfXkAzS43Xigj6Wpy0aobgqwLY59arikHoM7wEUa6mmx1WwMkV/AT+NWAJdC9NW1mareSriYbyZmrUgO1HXiGX81awKxuLwtlqsuypqYMDUebgeueawqNBFRaCPQNgKGgylUrpbRLyuHT9PCVLb/C4EMaCuXS+IFqz4wriUFikZjE78oGENI/OGAeDDqI5HgAAAAASUVORK5CYII="

Check failure on line 1 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

All extension code must be within (function (Scratch) { ... })(Scratch);

Check warning on line 1 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Missing semicolon

class NFCWarp {

Check failure on line 3 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

All extension code must be within (function (Scratch) { ... })(Scratch);
getInfo() {
return {
id: 'nfcwarp',
name: 'NFCWarp',
color1: '#ff0000',

Check warning on line 8 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Unexpected tab character

Check failure on line 8 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Mixed spaces and tabs
color2: '#800000',
color3: '#990033',
docsURI: 'https://docs.turbowarp.org/development/extensions/nfcwarp',

Check warning on line 11 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Unexpected tab character

Check failure on line 11 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Mixed spaces and tabs
menuIconURI: blocksIcon,

Check warning on line 12 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Unexpected tab character

Check failure on line 12 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Mixed spaces and tabs
blockIconURI: blocksIcon,
blocks: [
{

Check warning on line 15 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Unexpected tab character

Check failure on line 15 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Mixed spaces and tabs

Check warning on line 15 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Unexpected tab character
blockType: Scratch.BlockType.LABEL,

Check warning on line 16 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Unexpected tab character

Check failure on line 16 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Mixed spaces and tabs
text: "Read"

Check warning on line 17 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Unexpected tab character

Check failure on line 17 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Mixed spaces and tabs
},

Check warning on line 18 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Unexpected tab character

Check warning on line 19 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
{
opcode: 'nfcRead',
blockType: Scratch.BlockType.REPORTER,
text: 'Read NFC Tag',
disableMonitor: true

Check failure on line 24 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

Mixed spaces and tabs
}
]
};
}

nfcRead() {
return new Promise((resolve, reject) => {
console.log("Approach NFC Tag");
const ndef = new NDEFReader();

Check failure on line 33 in extensions/nfcwarp.js

View workflow job for this annotation

GitHub Actions / build

'NDEFReader' is not defined
ndef.scan()
.then(() => {
ndef.onreadingerror = err => {
console.log("Read failed");
reject(err);
};
ndef.onreading = evt => {
const decoder = new TextDecoder();
for (let record of evt.message.records) {
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));
return;
}
};
})
.catch(err => {
console.log("Read error - " + err.message);
reject(err);
});
});
}
}

Scratch.extensions.register(new NFCWarp());

0 comments on commit 4004fd9

Please sign in to comment.