Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita00bd44

Browse files
committed
Update webnfc
1 parent4fb92a7 commita00bd44

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

‎webnfc.js‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function log(msg) {
55

66
log("WebNFC available: "+("NDEFReader"inwindow));
77

8-
constmyUrl="https://rbyers.github.io/webnfc.html";
8+
constmimeType="application/x-rbyerstest";
99

1010
letabortController=null;
1111
abortController.signal.onabort=event=>{
@@ -25,8 +25,8 @@ document.getElementById('init').addEventListener("click", async () => {
2525
try{
2626
constndef=newNDEFReader();
2727
awaitndef.write({records:[
28-
{recordType:"url",data:myUrl},
29-
{recordType:"text",data:"0"}]});
28+
{recordType:"mime",mediaType:mimeType,data:"0"}
29+
]});
3030
log("Card initialized, duration: "+(newDate()-start)+"ms");
3131
}catch(error){
3232
log("Error: "+error);
@@ -50,35 +50,37 @@ document.getElementById('scan').addEventListener("click", async () => {
5050
letreadTime=newDate();
5151
log(`Found card,${readTime-start}ms.`);
5252
log(` Serial Number:${serialNumber}`);
53-
lettext="";
54-
letmatchedUrl=false;
5553
for(constrecordofmessage.records){
5654
log(" Record type: "+record.recordType);
5755
log(" MIME type: "+record.mediaType);
5856
log(" Record id: "+record.id);
5957
log(" Encoding: "+record.encoding);
6058
switch(record.recordType){
6159
case"text":
62-
text=newTextDecoder().decode(record.data);
60+
consttext=newTextDecoder().decode(record.data);
6361
log(` Text:${text} (${record.lang})`);
6462
break;
6563
case"url":
6664
consturl=newTextDecoder().decode(record.data);
6765
log(" Url: "+url);
68-
if(url==myUrl)matchedUrl=true;
66+
break;
67+
case"mime":
68+
if(record.mediaType==mimeType){
69+
consttext=newTextDecoder().decode(record.data);
70+
letcount=parseInt(text);
71+
count++;
72+
log(" Updating count to: "+count);
73+
awaitndef.write({signal:abortController.signal,records:[
74+
{recordType:"mime",mediaType:mimeType,data:"0"}
75+
]});
76+
log(` Update complete, duration:${newDate()-readTime}ms`);
77+
}
6978
break;
7079
default:
7180
log(" Unknown record type");
7281
}
7382
}
7483
if(matchedUrl){
75-
letcount=parseInt(text);
76-
count++;
77-
log(" Updating count to: "+count);
78-
awaitndef.write({signal:abortController.signal,records:[
79-
{recordType:"url",data:myUrl},
80-
{recordType:"text",data:count.toString()}]});
81-
log(` Update complete, duration:${newDate()-readTime}ms`);
8284
}
8385
}catch(error){
8486
log("Error: "+error);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp