-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
370 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,10 @@ | ||
# LINEJS in Browser | ||
|
||
In a browser, you cannot use the Fetch API to send requests to the LINE endpoint | ||
because of CORS. | ||
|
||
The best option is to set a proxy server to the LINE endpoint. | ||
|
||
However, you can get around this issue by calling LINEJS from a bookmarklet on a | ||
page such as https://legy-jp.line-apps.com/sn. (An example of this can be found | ||
in [browser-init.js](browser-init.js)) |
This file contains 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,90 @@ | ||
(function () { | ||
const script = document.createElement("script"); | ||
script.innerHTML = ` | ||
import * as LINEJS from "https://esm.sh/v135/@jsr/[email protected]/es2022/evex__linejs.mjs"; | ||
document.body.innerHTML = ""; | ||
class LocalStorage { | ||
prefix = "linejs:"; | ||
set( | ||
key, | ||
value, | ||
) { | ||
localStorage.setItem(this.prefix + key, JSON.stringify(value)); | ||
} | ||
get( | ||
key, | ||
) { | ||
try { | ||
return JSON.parse( | ||
localStorage.getItem(this.prefix + key) || "null", | ||
); | ||
} catch (_) { | ||
} | ||
} | ||
delete(key) { | ||
localStorage.removeItem(this.prefix + key); | ||
} | ||
clear() { | ||
localStorage.clear(); | ||
} | ||
migrate(storage) { | ||
for (let index = 0; index < localStorage.length; index++) { | ||
const k = localStorage.key(index); | ||
if (k) { | ||
storage.set( | ||
k.replace(this.prefix, ""), | ||
localStorage.getItem(k), | ||
); | ||
} else { | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
function log(message) { | ||
const p = document.createElement("p"); | ||
p.innerText = message; | ||
document.body.appendChild(p); | ||
} | ||
globalThis.LINEJS = LINEJS; | ||
const client = new LINEJS.Client({ device: prompt("device?", "IOSIPAD"), storage: new LocalStorage(), endpoint: location.hostname }); | ||
client.fetch = window.fetch.bind(window); | ||
client.on("log", (p) => console.log(p)); | ||
client.on("qrcall", (q) => { | ||
const div = document.createElement("div"); | ||
div.innerText = "read qrcode: "; | ||
const img = document.createElement("img"); | ||
img.src = \`https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=\${encodeURIComponent(q)}\`; | ||
div.appendChild(img); | ||
document.body.appendChild(div); | ||
}); | ||
client.on("pincall", (pincode) => { | ||
log(\`enter pincode: \${pincode}\`); | ||
}); | ||
client.on("update:authtoken", (authToken) => { | ||
localStorage.setItem("lastAuthToken", authToken); | ||
}); | ||
client.on("ready", async (user) => { | ||
log(\`Logged is as \${user.displayName} (\${user.mid})\`); | ||
console.log(client); | ||
}); | ||
const authToken = prompt("authToken", localStorage.getItem("lastAuthToken") || ""); | ||
if (authToken) { | ||
client.login({ authToken }); | ||
} else { | ||
const email = prompt("email", localStorage.getItem("lastEmail") || ""); | ||
if (email) { | ||
localStorage.setItem("lastEmail", email); | ||
const password = prompt("password", localStorage.getItem("lastPw") || ""); | ||
localStorage.setItem("lastPw", password); | ||
client.login({ password, email }); | ||
} else { | ||
client.login(); | ||
} | ||
} | ||
globalThis.client = client; | ||
`; | ||
script.type = "module"; | ||
document.body.appendChild(script); | ||
})() |
This file contains 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,33 @@ | ||
import { Client } from "@evex/linejs"; | ||
import { FileStorage } from "@evex/linejs/storage"; | ||
|
||
const client = new Client({ | ||
device: "IOSIPAD", | ||
storage: new FileStorage("storage.json"), | ||
}); | ||
|
||
client.on("log", (d) => { | ||
try { | ||
// console.log(d.type, d.data); // for debug | ||
} catch {} | ||
}); | ||
client.on("square:message", async (message) => { | ||
console.log(message.text); | ||
if (message.text === "!ping") { | ||
await message.react("NICE"); | ||
await message.reply("pong!"); | ||
} | ||
}); | ||
client.on("pincall", (p) => console.log("enter pincode:", p)); | ||
client.on("qrcall", (q) => console.log("qrcode:", q)); | ||
client.on("update:authtoken", (a) => console.log("AuthToken:", a)); | ||
client.on("ready", (user) => { | ||
console.log(`Logged in as ${user.displayName} (${user.mid})`); | ||
}); | ||
|
||
await client.login({ | ||
email: "email", | ||
password: "pass", | ||
}); | ||
|
||
client.polling(["square"]); // polling square |
This file contains 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,32 @@ | ||
import { Client } from "@evex/linejs"; | ||
import { FileStorage } from "@evex/linejs/storage"; | ||
|
||
const client = new Client({ | ||
device: "IOSIPAD", | ||
storage: new FileStorage("storage.json"), | ||
}); | ||
|
||
client.on("log", (d) => { | ||
try { | ||
// console.log(d.type, d.data); // for debug | ||
} catch {} | ||
}); | ||
client.on("pincall", (p) => console.log("enter pincode:", p)); | ||
client.on("qrcall", (q) => console.log("qrcode:", q)); | ||
client.on("update:authtoken", (a) => console.log("AuthToken:", a)); | ||
client.on("ready", (user) => { | ||
console.log(`Logged in as ${user.displayName} (${user.mid})`); | ||
}); | ||
|
||
await client.login({ | ||
email: "email", | ||
password: "pass", | ||
}); | ||
|
||
const chat = await client.getSquareChat("m..."); // your squareChatMid | ||
|
||
chat.on("message", async (message) => { | ||
await message.react("NICE"); | ||
}); | ||
|
||
chat.polling(); |
This file contains 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,33 @@ | ||
import { Client } from "@evex/linejs"; | ||
import { FileStorage } from "@evex/linejs/storage"; | ||
|
||
const client = new Client({ | ||
device: "IOSIPAD", | ||
storage: new FileStorage("storage.json"), | ||
}); | ||
|
||
client.on("log", (d) => { | ||
try { | ||
// console.log(d.type, d.data); // for debug | ||
} catch {} | ||
}); | ||
client.on("message", async (message) => { | ||
console.log(message.text); | ||
if (message.text === "!ping") { | ||
await message.react("NICE"); | ||
await message.reply("pong!"); | ||
} | ||
}); | ||
client.on("pincall", (p) => console.log("enter pincode:", p)); | ||
client.on("qrcall", (q) => console.log("qrcode:", q)); | ||
client.on("update:authtoken", (a) => console.log("AuthToken:", a)); | ||
client.on("ready", (user) => { | ||
console.log(`Logged in as ${user.displayName} (${user.mid})`); | ||
}); | ||
|
||
await client.login({ | ||
email: "email", | ||
password: "pass", | ||
}); | ||
|
||
client.polling(["talk"]); // polling talk |
Oops, something went wrong.