mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-22 08:13:53 +00:00
update webapp
This commit is contained in:
parent
6922a6d667
commit
48d1077ce4
@ -15,7 +15,10 @@ import kotlinx.coroutines.*
|
||||
import kotlinx.dom.appendElement
|
||||
import kotlinx.dom.appendText
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.w3c.dom.HTMLButtonElement
|
||||
import org.w3c.dom.HTMLElement
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.nextUBytes
|
||||
|
||||
fun HTMLElement.log(text: String) {
|
||||
appendText(text)
|
||||
@ -70,6 +73,9 @@ fun main() {
|
||||
appendText("Exit button")
|
||||
} ?: window.alert("Unable to load body")
|
||||
|
||||
document.body ?.appendElement("p", {})
|
||||
document.body ?.appendText("Allow to write in private messages: ${webApp.initDataUnsafe.user ?.allowsWriteToPM ?: "User unavailable"}")
|
||||
|
||||
document.body ?.appendElement("p", {})
|
||||
document.body ?.appendText("Alerts:")
|
||||
|
||||
@ -166,6 +172,19 @@ fun main() {
|
||||
updateText()
|
||||
} ?: window.alert("Unable to load body")
|
||||
|
||||
document.body ?.appendElement("button") {
|
||||
fun updateHeaderColor() {
|
||||
val (r, g, b) = Random.nextUBytes(3)
|
||||
val hex = Color.Hex("#${r.toString(16)}${g.toString(16)}${b.toString(16)}")
|
||||
webApp.setHeaderColor(hex)
|
||||
(this as? HTMLButtonElement) ?.style ?.backgroundColor = hex.value
|
||||
}
|
||||
addEventListener("click", {
|
||||
updateHeaderColor()
|
||||
})
|
||||
updateHeaderColor()
|
||||
} ?: window.alert("Unable to load body")
|
||||
|
||||
document.body ?.appendElement("p", {})
|
||||
|
||||
webApp.apply {
|
||||
|
Loading…
Reference in New Issue
Block a user