Spaces:
Sleeping
Sleeping
File size: 50,907 Bytes
3f0377e bc3bff4 2e2335c 3f0377e 0d99f82 3f0377e 0d99f82 3f0377e 0d99f82 3f0377e 0d99f82 79df050 3f0377e 79df050 3f0377e 2e2335c 0d99f82 3f0377e 2e2335c 3f0377e 2e2335c 3f0377e 2e2335c 3f0377e 2e2335c 3f0377e 2e2335c 3f0377e 0d99f82 2e2335c 3f0377e 0d99f82 26b9faa 0d99f82 f216ef7 26b9faa f216ef7 2e2335c 79df050 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c 3f0377e 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c 3f0377e 2e2335c 3f0377e bc3bff4 3f0377e 0d99f82 3f0377e 0d99f82 bc3bff4 0d99f82 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e bc3bff4 3f0377e 0d99f82 bc3bff4 0d99f82 bc3bff4 f216ef7 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 f216ef7 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 f216ef7 0d99f82 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa 0d99f82 bc3bff4 0d99f82 bc3bff4 f216ef7 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 f216ef7 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 f216ef7 0d99f82 f216ef7 0d99f82 bc3bff4 0d99f82 bc3bff4 095a0b5 0d99f82 095a0b5 0d99f82 bc3bff4 0d99f82 f216ef7 0d99f82 f216ef7 0d99f82 f216ef7 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 f216ef7 0d99f82 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa bc3bff4 26b9faa 0d99f82 bc3bff4 0d99f82 bc3bff4 f216ef7 0d99f82 bc3bff4 0d99f82 bc3bff4 0d99f82 f216ef7 0d99f82 bc3bff4 0d99f82 f216ef7 0d99f82 f216ef7 0d99f82 f216ef7 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c bc3bff4 2e2335c 79df050 3f0377e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 |
const positions = ['pos-top-right', 'pos-top-left', 'pos-bottom-right', 'pos-bottom-left'];
let usedPositions = [];
const MAX_CARDS = 4;
const LABELS = {
zh: {
temperature: 'ๆบซๅบฆ', condition: '็ๆณ', humidity: 'ๆฟๅบฆ', wind_speed: '้ขจ้',
weather: 'ๅคฉๆฐฃ', city: 'ๅๅธ', description: 'ๆ่ฟฐ',
feels_like: '้ซๆ', pressure: 'ๆฐฃๅฃ', sunrise: 'ๆฅๅบ', sunset: 'ๆฅ่ฝ',
heart_rate: 'ๅฟ็', step_count: 'ๆญฅๆธ', oxygen_level: '่กๆฐง', respiratory_rate: 'ๅผๅธ',
sleep_analysis: '็ก็ ', record_time: '่จ้ๆ้', average: 'ๅนณๅๅผ',
no_news: '็กๆฐ่', no_data: '็กๆธๆ', unknown: 'ๆช็ฅ',
exchange_rate: 'ๅฏ็', conversion: '่ฝๆ', time: 'ๆ้',
train_type: '่ป็จฎ', origin_station: '่ตท็ซ', dest_station: '่ฟ็ซ',
departure: 'ๅบ็ผ', arrival: 'ๆต้', duration: '่ก้งๆ้',
distance: '่ท้ข', walking_time: 'ๆญฅ่กๆ้', station: '่ป็ซ',
available_bikes: 'ๅฏๅ่ป่ผ', available_spaces: 'ๅฏ้็ฉบไฝ',
bike_type: '้กๅ', service_status: 'ๆๅ็ๆ
', operating: '็้ไธญ', suspended: 'ๆซๅๆๅ',
location: 'ไฝ็ฝฎ', coordinates: 'ๅบงๆจ', origin: '่ตท้ป', destination: '็ฎ็ๅฐ',
estimated_time: '้ ไผฐๆ้', view_in_maps: 'ๅจ Google Maps ไธญๆฅ็',
line: '่ทฏ็ท', address: 'ๅฐๅ', road: '้่ทฏ', area: 'ๅๅ'
},
en: {
temperature: 'Temperature', condition: 'Condition', humidity: 'Humidity', wind_speed: 'Wind Speed',
weather: 'Weather', city: 'City', description: 'Description',
feels_like: 'Feels Like', pressure: 'Pressure', sunrise: 'Sunrise', sunset: 'Sunset',
heart_rate: 'Heart Rate', step_count: 'Steps', oxygen_level: 'Oxygen', respiratory_rate: 'Respiratory',
sleep_analysis: 'Sleep', record_time: 'Record Time', average: 'Average',
no_news: 'No News', no_data: 'No Data', unknown: 'Unknown',
exchange_rate: 'Exchange Rate', conversion: 'Conversion', time: 'Time',
train_type: 'Train Type', origin_station: 'Origin', dest_station: 'Destination',
departure: 'Departure', arrival: 'Arrival', duration: 'Duration',
distance: 'Distance', walking_time: 'Walking Time', station: 'Station',
available_bikes: 'Available Bikes', available_spaces: 'Available Spaces',
bike_type: 'Type', service_status: 'Service Status', operating: 'Operating', suspended: 'Suspended',
location: 'Location', coordinates: 'Coordinates', origin: 'Origin', destination: 'Destination',
estimated_time: 'Estimated Time', view_in_maps: 'View in Google Maps',
line: 'Line', address: 'Address', road: 'Road', area: 'Area'
},
ko: {
temperature: '์จ๋', condition: '์ํ', humidity: '์ต๋', wind_speed: 'ํ์',
weather: '๋ ์จ', city: '๋์', description: '์ค๋ช
',
feels_like: '์ฒด๊ฐ', pressure: '๊ธฐ์', sunrise: '์ผ์ถ', sunset: '์ผ๋ชฐ',
heart_rate: '์ฌ๋ฐ์', step_count: '๊ฑธ์ ์', oxygen_level: 'ํ์ค ์ฐ์', respiratory_rate: 'ํธํก',
sleep_analysis: '์๋ฉด', record_time: '๊ธฐ๋ก ์๊ฐ', average: 'ํ๊ท ',
no_news: '๋ด์ค ์์', no_data: '๋ฐ์ดํฐ ์์', unknown: '์ ์ ์์',
exchange_rate: 'ํ์จ', conversion: 'ํ์ ', time: '์๊ฐ',
train_type: '์ด์ฐจ ์ข
๋ฅ', origin_station: '์ถ๋ฐ์ญ', dest_station: '๋์ฐฉ์ญ',
departure: '์ถ๋ฐ', arrival: '๋์ฐฉ', duration: '์์ ์๊ฐ',
distance: '๊ฑฐ๋ฆฌ', walking_time: '๋๋ณด ์๊ฐ', station: '์ญ',
available_bikes: '๋์ฌ ๊ฐ๋ฅ', available_spaces: '๋ฐ๋ฉ ๊ฐ๋ฅ',
bike_type: '์ ํ', service_status: '์๋น์ค ์ํ', operating: '์ด์ ์ค', suspended: '์ผ์ ์ค๋จ',
location: '์์น', coordinates: '์ขํ', origin: '์ถ๋ฐ์ง', destination: '๋ชฉ์ ์ง',
estimated_time: '์์ ์๊ฐ', view_in_maps: 'Google Maps์์ ๋ณด๊ธฐ',
line: '๋
ธ์ ', address: '์ฃผ์', road: '๋๋ก', area: '์ง์ญ'
},
ja: {
temperature: 'ๆฐๆธฉ', condition: '็ถๆณ', humidity: 'ๆนฟๅบฆ', wind_speed: '้ขจ้',
weather: 'ๅคฉๆฐ', city: '้ฝๅธ', description: '่ชฌๆ',
feels_like: 'ไฝๆ', pressure: 'ๆฐๅง', sunrise: 'ๆฅใฎๅบ', sunset: 'ๆฅใฎๅ
ฅใ',
heart_rate: 'ๅฟๆๆฐ', step_count: 'ๆญฉๆฐ', oxygen_level: '่กไธญ้
ธ็ด ', respiratory_rate: 'ๅผๅธ',
sleep_analysis: '็ก็ ', record_time: '่จ้ฒๆๅป', average: 'ๅนณๅ',
no_news: 'ใใฅใผในใชใ', no_data: 'ใใผใฟใชใ', unknown: 'ไธๆ',
exchange_rate: '็บๆฟใฌใผใ', conversion: 'ๆ็ฎ', time: 'ๆๅป',
train_type: 'ๅ่ป็จฎๅฅ', origin_station: 'ๅบ็บ้ง
', dest_station: 'ๅฐ็้ง
',
departure: 'ๅบ็บ', arrival: 'ๅฐ็', duration: 'ๆ่ฆๆ้',
distance: '่ท้ข', walking_time: 'ๅพๆญฉๆ้', station: '้ง
',
available_bikes: 'ๅฉ็จๅฏ่ฝ', available_spaces: '่ฟๅดๅฏ่ฝ',
bike_type: 'ใฟใคใ', service_status: 'ใตใผใใน็ถๆ
', operating: '้่กไธญ', suspended: 'ไธๆๅๆญข',
location: 'ๅ ดๆ', coordinates: 'ๅบงๆจ', origin: 'ๅบ็บๅฐ', destination: '็ฎ็ๅฐ',
estimated_time: 'ไบๆณๆ้', view_in_maps: 'Google Mapsใง่ฆใ',
line: '่ทฏ็ท', address: 'ไฝๆ', road: '้่ทฏ', area: 'ใจใชใข'
},
id: {
temperature: 'Suhu', condition: 'Kondisi', humidity: 'Kelembaban', wind_speed: 'Kecepatan Angin',
weather: 'Cuaca', city: 'Kota', description: 'Deskripsi',
feels_like: 'Terasa', pressure: 'Tekanan', sunrise: 'Matahari Terbit', sunset: 'Matahari Terbenam',
heart_rate: 'Detak Jantung', step_count: 'Langkah', oxygen_level: 'Oksigen', respiratory_rate: 'Pernapasan',
sleep_analysis: 'Tidur', record_time: 'Waktu Rekam', average: 'Rata-rata',
no_news: 'Tidak Ada Berita', no_data: 'Tidak Ada Data', unknown: 'Tidak Diketahui',
exchange_rate: 'Nilai Tukar', conversion: 'Konversi', time: 'Waktu',
train_type: 'Jenis Kereta', origin_station: 'Stasiun Asal', dest_station: 'Stasiun Tujuan',
departure: 'Keberangkatan', arrival: 'Kedatangan', duration: 'Durasi',
distance: 'Jarak', walking_time: 'Waktu Jalan', station: 'Stasiun',
available_bikes: 'Sepeda Tersedia', available_spaces: 'Tempat Tersedia',
bike_type: 'Tipe', service_status: 'Status Layanan', operating: 'Beroperasi', suspended: 'Ditangguhkan',
location: 'Lokasi', coordinates: 'Koordinat', origin: 'Asal', destination: 'Tujuan',
estimated_time: 'Waktu Estimasi', view_in_maps: 'Lihat di Google Maps',
line: 'Jalur', address: 'Alamat', road: 'Jalan', area: 'Area'
},
vi: {
temperature: 'Nhiแปt ฤแป', condition: 'Tรฌnh trแบกng', humidity: 'ฤแป แบฉm', wind_speed: 'Tแปc ฤแป giรณ',
weather: 'Thแปi tiแบฟt', city: 'Thร nh phแป', description: 'Mรด tแบฃ',
feels_like: 'Cแบฃm giรกc', pressure: 'รp suแบฅt', sunrise: 'Mแบทt trแปi mแปc', sunset: 'Mแบทt trแปi lแบทn',
heart_rate: 'Nhแปp tim', step_count: 'Sแป bฦฐแปc', oxygen_level: 'Oxy', respiratory_rate: 'Hรด hแบฅp',
sleep_analysis: 'Giแบฅc ngแปง', record_time: 'Thแปi gian ghi', average: 'Trung bรฌnh',
no_news: 'Khรดng cรณ tin', no_data: 'Khรดng cรณ dแปฏ liแปu', unknown: 'Khรดng rรต',
exchange_rate: 'Tแปท giรก', conversion: 'Chuyแปn ฤแปi', time: 'Thแปi gian',
train_type: 'Loแบกi tร u', origin_station: 'Ga ฤi', dest_station: 'Ga ฤแบฟn',
departure: 'Khแปi hร nh', arrival: 'ฤแบฟn', duration: 'Thแปi gian di chuyแปn',
distance: 'Khoแบฃng cรกch', walking_time: 'Thแปi gian ฤi bแป', station: 'Ga',
available_bikes: 'Xe cรณ sแบตn', available_spaces: 'Chแป trแปng',
bike_type: 'Loแบกi', service_status: 'Trแบกng thรกi dแปch vแปฅ', operating: 'Hoแบกt ฤแปng', suspended: 'Tแบกm ngแปซng',
location: 'Vแป trรญ', coordinates: 'Tแปa ฤแป', origin: 'ฤiแปm ฤi', destination: 'ฤiแปm ฤแบฟn',
estimated_time: 'Thแปi gian ฦฐแปc tรญnh', view_in_maps: 'Xem trรชn Google Maps',
line: 'Tuyแบฟn', address: 'ฤแปa chแป', road: 'ฤฦฐแปng', area: 'Khu vแปฑc'
}
};
let currentLanguage = 'zh';
let toolDrawer = null;
let toolDrawerToggle = null;
let toolDrawerContent = null;
let toolDrawerOverlay = null;
let toolDrawerClose = null;
let isDrawerOpen = false;
function initToolDrawer() {
toolDrawer = document.getElementById('toolDrawer');
toolDrawerToggle = document.getElementById('toolDrawerToggle');
toolDrawerContent = document.getElementById('toolDrawerContent');
toolDrawerOverlay = document.getElementById('toolDrawerOverlay');
toolDrawerClose = document.getElementById('toolDrawerClose');
if (!toolDrawer || !toolDrawerToggle) {
console.warn('โ ๏ธ ๅทฅๅ
ทๆฝๅฑๅ
็ด ๆชๆพๅฐ');
return;
}
toolDrawerToggle.addEventListener('click', toggleToolDrawer);
if (toolDrawerClose) {
toolDrawerClose.addEventListener('click', hideToolDrawer);
}
if (toolDrawerOverlay) {
toolDrawerOverlay.addEventListener('click', hideToolDrawer);
}
}
function showToolDrawerToggle() {
if (toolDrawerToggle) {
toolDrawerToggle.classList.add('visible');
}
}
function hideToolDrawerToggle() {
if (toolDrawerToggle) {
toolDrawerToggle.classList.remove('visible');
toolDrawerToggle.classList.remove('open');
}
}
function toggleToolDrawer() {
if (isDrawerOpen) {
hideToolDrawer();
} else {
showToolDrawer();
}
}
function showToolDrawer() {
if (toolDrawer) {
toolDrawer.classList.add('open');
toolDrawerToggle?.classList.add('open');
toolDrawerOverlay?.classList.add('visible');
isDrawerOpen = true;
}
}
function hideToolDrawer() {
if (toolDrawer) {
toolDrawer.classList.remove('open');
toolDrawerToggle?.classList.remove('open');
toolDrawerOverlay?.classList.remove('visible');
isDrawerOpen = false;
}
}
function hideToolCards() {
hideToolDrawer();
hideToolDrawerToggle();
if (toolDrawerContent) {
toolDrawerContent.innerHTML = '';
}
clearAllCards();
}
function getNextPosition() {
if (usedPositions.length >= MAX_CARDS) {
console.warn('โ ๏ธ ๅก็ๆธ้ๅทฒ้ไธ้๏ผ4ๅผต๏ผ๏ผ่ซๅ
ๆธ
้ค็พๆๅก็');
return null;
}
for (const pos of positions) {
if (!usedPositions.includes(pos)) {
usedPositions.push(pos);
return pos;
}
}
return null;
}
function addToolCard(type) {
const position = getNextPosition();
if (!position) {
return;
}
const card = document.createElement('div');
card.className = `voice-tool-card ${position}`;
card.dataset.type = type;
if (type === 'weather') {
card.innerHTML = `
<div class="card-header">
<div class="card-icon">๐ค๏ธ</div>
<h3>ๅฐๅๅคฉๆฐฃ</h3>
</div>
<div class="card-content">
<div class="data-row">
<span class="data-label">ๆบซๅบฆ</span>
<span class="data-value">23ยฐC</span>
</div>
<div class="data-row">
<span class="data-label">็ๆณ</span>
<span class="data-value">ๆดๆ</span>
</div>
<div class="data-row">
<span class="data-label">ๆฟๅบฆ</span>
<span class="data-value">65%</span>
</div>
</div>
`;
} else if (type === 'news') {
card.innerHTML = `
<div class="card-header">
<div class="card-icon">๐ฐ</div>
<h3>ไปๆฅ็งๆๆฐ่</h3>
</div>
<div class="card-content">
<div class="data-row">
<span style="font-size: 13px; line-height: 1.6;">
โข OpenAI ็ผๅธๆฐๆจกๅ<br>
โข ่ๆๆจๅบ Vision Pro 2<br>
โข ๅฐ็ฉ้ปๅฎฃๅธ 2nm ่ฃฝ็จ
</span>
</div>
</div>
`;
} else if (type === 'health') {
card.innerHTML = `
<div class="card-header">
<div class="card-icon">โค๏ธ</div>
<h3>ๅฅๅบทๆธๆ</h3>
</div>
<div class="card-content">
<div class="data-row">
<span class="data-label">ๅฟ็</span>
<span class="data-value">72 bpm</span>
</div>
<div class="data-row">
<span class="data-label">ๆญฅๆธ</span>
<span class="data-value">8,542</span>
</div>
<div class="data-row">
<span class="data-label">่กๆฐง</span>
<span class="data-value">98%</span>
</div>
</div>
`;
}
cardsContainer.appendChild(card);
}
function clearAllCards() {
const cards = cardsContainer.querySelectorAll('.voice-tool-card');
cards.forEach(card => {
card.classList.add('exiting');
setTimeout(() => card.remove(), 300);
});
usedPositions = [];
}
function initToolCardControls() {
document.getElementById('simulate-weather').addEventListener('click', () => {
clearAllCards();
setTimeout(() => addToolCard('weather'), 100);
});
document.getElementById('simulate-news').addEventListener('click', () => {
clearAllCards();
setTimeout(() => addToolCard('news'), 100);
});
document.getElementById('simulate-health').addEventListener('click', () => {
clearAllCards();
setTimeout(() => addToolCard('health'), 100);
});
document.getElementById('simulate-next-input').addEventListener('click', () => {
clearAllCards();
transcript.textContent = '่ซ่ชช่ฉฑ...';
transcript.className = 'voice-transcript provisional';
});
}
async function syncToolMetadata() {
try {
const response = await fetch('/api/mcp/tools', {
headers: {
'Authorization': `Bearer ${localStorage.getItem('jwt_token')}`
}
});
if (response.ok) {
const data = await response.json();
if (data.success && data.tools) {
toolsMetadata = {};
data.tools.forEach(tool => {
toolsMetadata[tool.name] = tool;
});
}
}
} catch (error) {
console.error('โ ๅๆญฅๅทฅๅ
ท metadata ๅคฑๆ:', error);
}
}
function getIconForTool(toolName, category) {
const iconMap = {
'ๅฅๅบท': 'โค๏ธ',
'ๅคฉๆฐฃ': '๐ค๏ธ',
'ๆฐ่': '๐ฐ',
'ๅฏ็': '๐ฑ',
'ๆ้': 'โฐ',
'ๆ้': 'โฐ',
'ๆฅๆ': '๐
',
'้ณๆจ': '๐ต',
'ๅฐๅ': '๐บ๏ธ',
'็ฟป่ญฏ': '๐',
'่จ็ฎ': '๐ข',
'้่ทฏ้่ผธ': '๐',
'่ป้้่ผธ': '๐',
'ๅฐ็ๅฎไฝ': '๐',
'healthkit_query': 'โค๏ธ',
'weather_query': '๐ค๏ธ',
'news_query': '๐ฐ',
'exchange_rate': '๐ฑ',
'time_query': 'โฐ',
'reminder': 'โฐ',
'calendar': '๐
',
'tdx_bus_arrival': '๐',
'tdx_metro': '๐',
'reverse_geocode': '๐',
'forward_geocode': '๐',
'directions': '๐บ๏ธ',
'environment_context': '๐'
};
if (iconMap[toolName]) {
return iconMap[toolName];
}
if (category && iconMap[category]) {
return iconMap[category];
}
return '๐ง';
}
function displayMultipleToolCards(toolsArray) {
clearAllCards();
if (!toolsArray || toolsArray.length === 0) return;
if (toolDrawerContent) {
toolDrawerContent.innerHTML = '';
}
toolsArray.forEach((tool, index) => {
const toolName = tool.tool_name;
const toolData = tool.tool_data;
const toolMeta = toolsMetadata[toolName] || {};
const category = toolMeta.category || 'ๆช็ฅ';
const icon = getIconForTool(toolName, category);
const contentHTML = renderCardContent(toolName, toolData);
const card = document.createElement('div');
card.className = 'voice-tool-card';
card.dataset.type = toolName;
card.style.marginBottom = '15px';
card.style.position = 'relative';
card.innerHTML = `
<div class="card-header">
<div class="card-icon">${icon}</div>
<h3>${category}</h3>
<span style="margin-left:auto; font-size:12px; color:#888;">${index + 1}/${toolsArray.length}</span>
</div>
<div class="card-content" style="max-height: 300px; overflow-y: auto; overflow-x: hidden; padding-right: 8px;">${contentHTML}</div>
`;
if (toolDrawerContent) {
toolDrawerContent.appendChild(card);
}
});
if (toolDrawerContent) {
showToolDrawerToggle();
}
const lastTool = toolsArray[toolsArray.length - 1];
const lastToolName = lastTool.tool_name;
const lastToolData = lastTool.tool_data;
const toolMeta = toolsMetadata[lastToolName] || {};
const category = toolMeta.category || 'ๆช็ฅ';
const icon = getIconForTool(lastToolName, category);
const contentHTML = renderCardContent(lastToolName, lastToolData);
const floatingCard = document.createElement('div');
floatingCard.className = 'voice-tool-card';
floatingCard.dataset.type = lastToolName;
let extraHeaderHtml = '';
if (toolsArray.length > 1) {
extraHeaderHtml = `<button onclick="showToolDrawer()" style="margin-left:auto; background:rgba(0,100,255,0.1); color:#0066cc; border:none; padding:4px 8px; border-radius:12px; font-size:12px; font-weight:bold; cursor:pointer;">ๆฅ็ๅ
จ้จ (${toolsArray.length})</button>`;
}
floatingCard.innerHTML = `
<div class="card-header">
<div class="card-icon">${icon}</div>
<h3>${category}</h3>
${extraHeaderHtml}
</div>
<div class="card-content" style="max-height: 300px; overflow-y: auto; overflow-x: hidden; padding-right: 8px;">${contentHTML}</div>
`;
const position = getNextPosition();
if (position && cardsContainer) {
floatingCard.classList.add(position);
cardsContainer.appendChild(floatingCard);
}
}
function displayToolCard(toolName, toolData) {
clearAllCards();
const toolMeta = toolsMetadata[toolName] || {};
const category = toolMeta.category || 'ๆช็ฅ';
const icon = getIconForTool(toolName, category);
const contentHTML = renderCardContent(toolName, toolData);
const card = document.createElement('div');
card.className = 'voice-tool-card';
card.dataset.type = toolName;
card.innerHTML = `
<div class="card-header">
<div class="card-icon">${icon}</div>
<h3>${category}</h3>
</div>
<div class="card-content" style="max-height: 300px; overflow-y: auto; overflow-x: hidden; padding-right: 8px;">${contentHTML}</div>
`;
if (toolDrawerContent) {
toolDrawerContent.innerHTML = '';
toolDrawerContent.appendChild(card.cloneNode(true));
showToolDrawerToggle();
}
const position = getNextPosition();
if (position && cardsContainer) {
card.classList.add(position);
cardsContainer.appendChild(card);
}
}
function renderCardContent(toolName, toolData) {
if (!toolData) {
console.warn('โ ๏ธ toolData ็บ็ฉบ');
return '<p class="data-row">็กๆธๆ</p>';
}
const healthData = toolData.health_data || toolData.raw_data?.health_data;
if (healthData && Array.isArray(healthData)) {
return renderHealthMetrics(healthData);
}
const articlesData = toolData.articles || toolData.raw_data?.articles;
if (articlesData && Array.isArray(articlesData)) {
return renderNewsList(articlesData);
}
const weatherData = toolData.raw_data || toolData;
if (weatherData.main && weatherData.weather) {
return renderWeatherData(weatherData);
}
if (toolData.arrivals && Array.isArray(toolData.arrivals)) {
return renderBusArrivals(toolData.arrivals, toolData.route_name);
}
if (toolData.stops && Array.isArray(toolData.stops)) {
return renderNearbyStops(toolData.stops);
}
const exchangeData = toolData.raw_data || toolData;
if (exchangeData.rate !== undefined && exchangeData.from_currency !== undefined) {
return renderExchangeRate(exchangeData);
}
if (toolData.trains && Array.isArray(toolData.trains)) {
return renderTrainList(toolData.trains);
}
if (toolData.stations && Array.isArray(toolData.stations) &&
(toolName === 'tdx_youbike' || toolData.stations[0]?.available_bikes !== undefined)) {
return renderYouBikeStations(toolData.stations);
}
if (toolData.stations && Array.isArray(toolData.stations) && toolName === 'tdx_train') {
return renderTrainStations(toolData.stations);
}
if (toolData.display_name && toolData.lat && toolData.lon && toolName === 'reverse_geocode') {
return renderReverseGeocode(toolData);
}
if ((toolData.distance_m !== undefined || toolData.duration_s !== undefined) &&
(toolName === 'directions' || toolData.polyline !== undefined)) {
return renderDirections(toolData);
}
if (toolData.arrivals && Array.isArray(toolData.arrivals) && toolName === 'tdx_metro') {
return renderMetroArrivals(toolData.arrivals);
}
if (toolData.stations && Array.isArray(toolData.stations) && toolName === 'tdx_metro') {
return renderMetroStations(toolData.stations);
}
if (toolData.lat && toolData.lon && toolData.display_name && toolName === 'forward_geocode') {
return renderForwardGeocode(toolData);
}
if (toolName === 'environment_context' || (toolData.lat && toolData.lon && toolData.label)) {
return renderEnvironmentContext(toolData);
}
if (toolData.raw_data && typeof toolData.raw_data === 'object') {
return renderKeyValuePairs(toolData.raw_data);
}
console.warn('โ ๏ธ ๆชๅน้
ไปปไฝๆจกๅผ๏ผไฝฟ็จ JSON fallback');
return renderJSONFallback(toolData);
}
function renderWeatherData(data) {
const main = data.main || {};
const weather = data.weather?.[0] || {};
const wind = data.wind || {};
const sys = data.sys || {};
const labels = LABELS[currentLanguage] || LABELS.zh;
const formatTime = (timestamp) => {
if (!timestamp) return '--:--';
const date = new Date(timestamp * 1000);
return date.toLocaleTimeString('zh-TW', { hour: '2-digit', minute: '2-digit' });
};
return `
<div class="data-row">
<span class="data-label">๐ก๏ธ ${labels.temperature}</span>
<span class="data-value">${main.temp?.toFixed(1) || '--'}ยฐC</span>
</div>
<div class="data-row">
<span class="data-label">๐ค ${labels.feels_like}</span>
<span class="data-value">${main.feels_like?.toFixed(1) || '--'}ยฐC</span>
</div>
<div class="data-row">
<span class="data-label">โ๏ธ ${labels.condition}</span>
<span class="data-value">${weather.description || '--'}</span>
</div>
<div class="data-row">
<span class="data-label">๐ง ${labels.humidity}</span>
<span class="data-value">${main.humidity || '--'}%</span>
</div>
<div class="data-row">
<span class="data-label">๐ช๏ธ ${labels.wind_speed}</span>
<span class="data-value">${wind.speed?.toFixed(1) || '--'} m/s</span>
</div>
<div class="data-row">
<span class="data-label">๐ ${labels.pressure}</span>
<span class="data-value">${main.pressure || '--'} hPa</span>
</div>
<div class="data-row">
<span class="data-label">๐
${labels.sunrise}</span>
<span class="data-value">${formatTime(sys.sunrise)}</span>
</div>
<div class="data-row">
<span class="data-label">๐ ${labels.sunset}</span>
<span class="data-value">${formatTime(sys.sunset)}</span>
</div>
`;
}
function renderHealthMetrics(healthData) {
const labels = LABELS[currentLanguage] || LABELS.zh;
if (!healthData || healthData.length === 0) {
return `<p class="data-row">${labels.no_data}</p>`;
}
const metricIcons = {
heart_rate: 'โค๏ธ',
step_count: '๏ฟฝ',
oxygen_level: '๐ซ',
respiratory_rate: '๐จ',
sleep_analysis: '๐ด'
};
const grouped = {};
healthData.forEach(item => {
const metric = item.metric || item.type;
if (!grouped[metric]) {
grouped[metric] = [];
}
grouped[metric].push(item);
});
let html = '<div class="health-metrics">';
Object.entries(grouped).forEach(([metric, items], index) => {
const icon = metricIcons[metric] || '๐';
const label = labels[metric] || metric;
const latestItem = items[0]; // ๆๆฐ็ๆธๆ
const value = latestItem.value;
const unit = latestItem.unit || '';
let timeStr = '';
if (latestItem.timestamp) {
try {
const date = new Date(latestItem.timestamp);
timeStr = date.toLocaleString('zh-TW', {
month: 'numeric',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
} catch (e) {
timeStr = '';
}
}
html += `
<div class="health-metric-item" style="border-bottom: 1px solid #eee; padding: 10px 0; ${index === Object.keys(grouped).length - 1 ? 'border-bottom: none;' : ''}">
<div class="data-row">
<span class="data-label">${icon} ${label}</span>
<span class="data-value" style="font-weight: bold;">${value} ${unit}</span>
</div>
${timeStr ? `
<div class="data-row" style="opacity: 0.7;">
<span class="data-label" style="font-size: 0.85em;">${labels.record_time}</span>
<span class="data-value" style="font-size: 0.85em;">${timeStr}</span>
</div>
` : ''}
${items.length > 1 ? `
<div class="data-row" style="opacity: 0.6;">
<span class="data-label" style="font-size: 0.8em;">${labels.average}</span>
<span class="data-value" style="font-size: 0.8em;">${(items.reduce((sum, i) => sum + i.value, 0) / items.length).toFixed(1)} ${unit}</span>
</div>
` : ''}
</div>
`;
});
html += '</div>';
return html;
}
function renderNewsList(articles) {
const labels = LABELS[currentLanguage] || LABELS.zh;
let html = '';
articles.slice(0, 3).forEach(article => {
html += `
<div class="data-row" style="flex-direction: column; align-items: flex-start; margin-bottom: 10px;">
<span class="data-label" style="font-weight: bold;">${article.title || labels.unknown}</span>
<span class="data-value" style="font-size: 0.85em; opacity: 0.8;">${article.source?.name || article.source || ''}</span>
</div>
`;
});
return html || `<p>${labels.no_news}</p>`;
}
function renderKeyValuePairs(data) {
const labels = LABELS[currentLanguage] || LABELS.zh;
const keyMap = {
city: labels.city,
temp: labels.temperature,
temperature: labels.temperature,
condition: labels.condition,
weather: labels.weather,
humidity: labels.humidity,
wind_speed: labels.wind_speed,
description: labels.description
};
let html = '';
for (const [key, value] of Object.entries(data)) {
if (typeof value === 'object') continue; // ่ทณ้ๅทข็็ฉไปถ
const label = keyMap[key] || key;
let displayValue = value;
if (key.includes('temp') && typeof value === 'number') {
displayValue = `${value}ยฐC`;
}
html += `
<div class="data-row">
<span class="data-label">${label}</span>
<span class="data-value">${displayValue}</span>
</div>
`;
}
return html || '<p>็กๆธๆ</p>';
}
function renderExchangeRate(data) {
const labels = LABELS[currentLanguage] || LABELS.zh;
const currencySymbols = {
"USD": "$", "TWD": "NT$", "JPY": "ยฅ", "EUR": "โฌ",
"GBP": "ยฃ", "CNY": "ยฅ", "KRW": "โฉ", "HKD": "HK$"
};
const fromCurrency = data.from_currency || "USD";
const toCurrency = data.to_currency || "TWD";
const fromSymbol = currencySymbols[fromCurrency] || fromCurrency;
const toSymbol = currencySymbols[toCurrency] || toCurrency;
let html = '';
if (data.rate !== undefined) {
html += `
<div class="data-row">
<span class="data-label">๐ฐ ${labels.exchange_rate}</span>
<span class="data-value">1 ${fromCurrency} = ${data.rate.toFixed(4)} ${toCurrency}</span>
</div>
`;
}
if (data.amount && data.converted_amount !== undefined) {
html += `
<div class="data-row">
<span class="data-label">๐ ${labels.conversion}</span>
<span class="data-value">${fromSymbol}${data.amount.toFixed(2)} = ${toSymbol}${data.converted_amount.toFixed(2)}</span>
</div>
`;
}
if (data.raw_data?.metadata?.timestamp) {
const time = new Date(data.raw_data.metadata.timestamp).toLocaleString('zh-TW');
html += `
<div class="data-row">
<span class="data-label">โฐ ${labels.time}</span>
<span class="data-value">${time}</span>
</div>
`;
}
return html || `<p>${labels.no_data}</p>`;
}
function renderTrainList(trains) {
const labels = LABELS[currentLanguage] || LABELS.zh;
if (!trains || trains.length === 0) {
return `<p class="data-row">${labels.no_data}</p>`;
}
let html = '<div class="train-list">';
trains.forEach((train, index) => {
const trainType = train.train_type || labels.unknown;
const trainNo = train.train_no || '---';
const departTime = train.departure_time ? train.departure_time.substring(0, 5) : '--:--';
const arriveTime = train.arrival_time ? train.arrival_time.substring(0, 5) : '--:--';
const durationText = train.duration_min ? `${train.duration_min}${currentLanguage === 'zh' ? 'ๅ้' : currentLanguage === 'en' ? ' min' : currentLanguage === 'ko' ? '๋ถ' : currentLanguage === 'ja' ? 'ๅ' : currentLanguage === 'id' ? ' menit' : ' phรบt'}` : labels.unknown;
const originStation = train.origin_station || labels.unknown;
const destStation = train.destination_station || labels.unknown;
html += `
<div class="train-item" style="border-bottom: 1px solid #eee; padding: 12px 0; ${index === trains.length - 1 ? 'border-bottom: none;' : ''}">
<div class="data-row" style="margin-bottom: 8px;">
<span class="data-label" style="font-weight: bold; color: #0066cc;">๐ ${trainType} ${trainNo}</span>
</div>
<div class="data-row">
<span class="data-label">๐ ${labels.origin_station} โ ${labels.dest_station}</span>
<span class="data-value">${originStation} โ ${destStation}</span>
</div>
<div class="data-row">
<span class="data-label">โฐ ${labels.departure}</span>
<span class="data-value">${departTime}</span>
</div>
<div class="data-row">
<span class="data-label">โฑ๏ธ ${labels.arrival}</span>
<span class="data-value">${arriveTime}</span>
</div>
<div class="data-row">
<span class="data-label">๐ ${labels.duration}</span>
<span class="data-value">${durationText}</span>
</div>
</div>
`;
});
html += '</div>';
return html;
}
function renderTrainStations(stations) {
const labels = LABELS[currentLanguage] || LABELS.zh;
if (!stations || stations.length === 0) {
return `<p class="data-row">${labels.no_data}</p>`;
}
let html = '<div class="station-list">';
stations.forEach((station, index) => {
const stationName = station.station_name || station.name || labels.unknown;
const distanceUnit = currentLanguage === 'zh' ? 'ๅ
ฌๅฐบ' : currentLanguage === 'en' ? 'm' : currentLanguage === 'ko' ? '๋ฏธํฐ' : currentLanguage === 'ja' ? 'ใกใผใใซ' : currentLanguage === 'id' ? 'm' : 'm';
const distance = station.distance_m ? `${Math.round(station.distance_m)}${distanceUnit}` : '';
const walkTimeText = station.walking_time_min ? `${currentLanguage === 'zh' ? 'ๆญฅ่ก็ด' : ''}${station.walking_time_min}${currentLanguage === 'zh' ? 'ๅ้' : currentLanguage === 'en' ? ' min walk' : currentLanguage === 'ko' ? '๋ถ ๋๋ณด' : currentLanguage === 'ja' ? 'ๅ ๅพๆญฉ' : currentLanguage === 'id' ? ' menit jalan' : ' phรบt ฤi bแป'}` : '';
html += `
<div class="station-item" style="border-bottom: 1px solid #eee; padding: 12px 0; ${index === stations.length - 1 ? 'border-bottom: none;' : ''}">
<div class="data-row" style="margin-bottom: 4px;">
<span class="data-label" style="font-weight: bold; color: #0066cc;">๐ ${stationName}</span>
</div>
${distance ? `
<div class="data-row">
<span class="data-label">๐ ${labels.distance}</span>
<span class="data-value">${distance}</span>
</div>
` : ''}
${walkTimeText ? `
<div class="data-row">
<span class="data-label">๐ถ ${labels.walking_time}</span>
<span class="data-value">${walkTimeText}</span>
</div>
` : ''}
</div>
`;
});
html += '</div>';
return html;
}
function renderYouBikeStations(stations) {
const labels = LABELS[currentLanguage] || LABELS.zh;
if (!stations || stations.length === 0) {
return `<p class="data-row">${labels.no_data}</p>`;
}
let html = '<div class="youbike-list">';
stations.forEach((station, index) => {
const stationName = station.station_name || labels.unknown;
const availableBikes = station.available_bikes ?? 0;
const availableSpaces = station.available_spaces ?? 0;
const distance = station.distance_m || 0;
const walkingTime = station.walking_time_min || 0;
const bikeType = station.bike_type || 'YouBike';
const serviceStatus = station.service_status === 1 ? labels.operating : labels.suspended;
const walkText = currentLanguage === 'zh' ? `ๆญฅ่ก็ด ${walkingTime} ๅ้` : currentLanguage === 'en' ? `${walkingTime} min walk` : currentLanguage === 'ko' ? `๋๋ณด ${walkingTime}๋ถ` : currentLanguage === 'ja' ? `ๅพๆญฉ${walkingTime}ๅ` : currentLanguage === 'id' ? `${walkingTime} menit jalan` : `${walkingTime} phรบt ฤi bแป`;
const bikeUnit = currentLanguage === 'zh' ? '่ผ' : currentLanguage === 'en' ? '' : currentLanguage === 'ko' ? '๋' : currentLanguage === 'ja' ? 'ๅฐ' : currentLanguage === 'id' ? '' : '';
const spaceUnit = currentLanguage === 'zh' ? 'ๅ' : currentLanguage === 'en' ? '' : currentLanguage === 'ko' ? '๊ฐ' : currentLanguage === 'ja' ? 'ๅ' : currentLanguage === 'id' ? '' : '';
let bikeStatusColor = '#e74c3c';
let bikeStatusIcon = '๐ซ';
if (availableBikes > 3) {
bikeStatusColor = '#27ae60';
bikeStatusIcon = 'โ
';
} else if (availableBikes > 0) {
bikeStatusColor = '#f39c12';
bikeStatusIcon = 'โ ๏ธ';
}
html += `
<div class="youbike-item" style="border-bottom: 1px solid #eee; padding: 12px 0; ${index === stations.length - 1 ? 'border-bottom: none;' : ''}">
<div class="data-row" style="margin-bottom: 8px;">
<span class="data-label" style="font-weight: bold; color: #e67e22;">๐ฒ ${stationName}</span>
</div>
<div class="data-row">
<span class="data-label">๐ ${labels.distance}</span>
<span class="data-value">${distance}m (${walkText})</span>
</div>
<div class="data-row">
<span class="data-label">๐ด ${labels.available_bikes}</span>
<span class="data-value" style="color: ${bikeStatusColor}; font-weight: bold;">${bikeStatusIcon} ${availableBikes} ${bikeUnit}</span>
</div>
<div class="data-row">
<span class="data-label">๐
ฟ๏ธ ${labels.available_spaces}</span>
<span class="data-value">${availableSpaces} ${spaceUnit}</span>
</div>
<div class="data-row">
<span class="data-label">โน๏ธ ${labels.bike_type}</span>
<span class="data-value">${bikeType} (${serviceStatus})</span>
</div>
</div>
`;
});
html += '</div>';
return html;
}
function renderBusArrivals(arrivals, routeName) {
const labels = LABELS[currentLanguage] || LABELS.zh;
if (!arrivals || arrivals.length === 0) {
return `<p>${labels.no_data}</p>`;
}
let html = '';
const stopGroups = {};
arrivals.forEach(arr => {
const stopName = arr.stop_name || labels.unknown;
if (!stopGroups[stopName]) {
stopGroups[stopName] = [];
}
stopGroups[stopName].push(arr);
});
Object.entries(stopGroups).slice(0, 3).forEach(([stopName, stopArrivals], index) => {
const firstArr = stopArrivals[0];
const distance = firstArr.distance_m ? `${Math.round(firstArr.distance_m)}m` : '';
html += `
<div class="data-row" style="flex-direction: column; align-items: flex-start; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid rgba(0,0,0,0.05);">
<div style="display: flex; justify-content: space-between; width: 100%; margin-bottom: 4px;">
<span class="data-label" style="font-weight: 600;">๐ ${stopName}</span>
${distance ? `<span class="data-value" style="font-size: 0.85em; opacity: 0.7;">${distance}</span>` : ''}
</div>
`;
stopArrivals.forEach(arr => {
const directionText = arr.direction === 0 ? (currentLanguage === 'zh' ? 'ๅพ โ' : currentLanguage === 'en' ? 'To โ' : currentLanguage === 'ko' ? '๋ฐฉํฅ โ' : currentLanguage === 'ja' ? '่กใ โ' : currentLanguage === 'id' ? 'Ke โ' : 'ฤแบฟn โ') : (currentLanguage === 'zh' ? '่ฟ โ' : currentLanguage === 'en' ? 'Return โ' : currentLanguage === 'ko' ? 'ํ์ฐจ โ' : currentLanguage === 'ja' ? 'ๆปใ โ' : currentLanguage === 'id' ? 'Kembali โ' : 'Vแป โ');
const status = arr.status || labels.unknown;
html += `
<div style="display: flex; justify-content: space-between; width: 100%; padding: 2px 0;">
<span style="font-size: 0.9em; opacity: 0.8;">${directionText}</span>
<span class="data-value" style="font-size: 0.9em;">${status}</span>
</div>
`;
});
html += `</div>`;
});
return html;
}
function renderReverseGeocode(data) {
const labels = LABELS[currentLanguage] || LABELS.zh;
const displayName = data.display_name || labels.unknown;
const city = data.city || '';
const road = data.road || '';
const houseNumber = data.house_number || '';
const suburb = data.suburb || '';
const admin = data.admin || '';
const countryCode = data.country_code || '';
const lat = data.lat?.toFixed(6) || '';
const lon = data.lon?.toFixed(6) || '';
let detailedAddress = [];
if (city) detailedAddress.push(city);
if (admin && admin !== city) detailedAddress.push(admin);
if (suburb) detailedAddress.push(suburb);
if (road) detailedAddress.push(road);
if (houseNumber) detailedAddress.push(houseNumber);
const addressText = detailedAddress.length > 0 ? detailedAddress.join(', ') : displayName;
const mapsUrl = `https://www.google.com/maps?q=${lat},${lon}`;
return `
<div class="data-row">
<span class="data-label">๐ ${labels.location}</span>
<span class="data-value" style="font-weight: bold;">${displayName}</span>
</div>
${city ? `
<div class="data-row">
<span class="data-label">๐๏ธ ${labels.city}</span>
<span class="data-value">${city}</span>
</div>
` : ''}
${road ? `
<div class="data-row">
<span class="data-label">๐ฃ๏ธ ${labels.road}</span>
<span class="data-value">${road}${houseNumber ? ' ' + houseNumber : ''}</span>
</div>
` : ''}
${suburb ? `
<div class="data-row">
<span class="data-label">๐๏ธ ${labels.area}</span>
<span class="data-value">${suburb}</span>
</div>
` : ''}
<div class="data-row">
<span class="data-label">๐ ${labels.coordinates}</span>
<span class="data-value" style="font-size: 0.85em;">${lat}, ${lon}</span>
</div>
<div class="data-row" style="margin-top: 8px;">
<a href="${mapsUrl}" target="_blank" style="color: #0066cc; text-decoration: none; font-size: 0.9em;">
๐บ๏ธ ${labels.view_in_maps} โ
</a>
</div>
`;
}
function renderNearbyStops(stops) {
const labels = LABELS[currentLanguage] || LABELS.zh;
if (!stops || stops.length === 0) {
return `<p>${labels.no_data}</p>`;
}
let html = '';
stops.slice(0, 5).forEach((stop, index) => {
const stopName = stop.stop_name || labels.unknown;
const distance = stop.distance_m ? `${Math.round(stop.distance_m)}m` : '';
const walkTimeText = stop.walking_time_min ? `${currentLanguage === 'zh' ? 'ๆญฅ่ก ' : ''}${stop.walking_time_min}${currentLanguage === 'zh' ? ' ๅ' : currentLanguage === 'en' ? ' min walk' : currentLanguage === 'ko' ? '๋ถ ๋๋ณด' : currentLanguage === 'ja' ? 'ๅ ๅพๆญฉ' : currentLanguage === 'id' ? ' menit jalan' : ' phรบt ฤi bแป'}` : '';
html += `
<div class="data-row" style="margin-bottom: 8px;">
<div style="flex: 1;">
<div style="font-weight: 600; margin-bottom: 2px;">๐ ${stopName}</div>
<div style="font-size: 0.85em; opacity: 0.7;">${walkTimeText} ${distance ? `(${distance})` : ''}</div>
</div>
</div>
`;
});
return html;
}
function renderDirections(data) {
const labels = LABELS[currentLanguage] || LABELS.zh;
const originLabel = data.origin_label || labels.origin;
const destLabel = data.dest_label || labels.destination;
const distanceM = data.distance_m;
const durationS = data.duration_s;
let distanceStr = '--';
if (distanceM !== undefined) {
if (distanceM >= 1000) {
const kmUnit = currentLanguage === 'zh' ? 'ๅ
ฌ้' : currentLanguage === 'en' ? ' km' : currentLanguage === 'ko' ? 'ํฌ๋ก๋ฏธํฐ' : currentLanguage === 'ja' ? 'ใญใญ' : currentLanguage === 'id' ? ' km' : ' km';
distanceStr = `${(distanceM / 1000).toFixed(1)}${kmUnit}`;
} else {
const mUnit = currentLanguage === 'zh' ? 'ๅ
ฌๅฐบ' : currentLanguage === 'en' ? ' m' : currentLanguage === 'ko' ? '๋ฏธํฐ' : currentLanguage === 'ja' ? 'ใกใผใใซ' : currentLanguage === 'id' ? ' m' : ' m';
distanceStr = `${Math.round(distanceM)}${mUnit}`;
}
}
let durationStr = '--';
if (durationS !== undefined) {
const minutes = Math.round(durationS / 60);
if (minutes >= 60) {
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
const hourUnit = currentLanguage === 'zh' ? 'ๅฐๆ' : currentLanguage === 'en' ? ' hr' : currentLanguage === 'ko' ? '์๊ฐ' : currentLanguage === 'ja' ? 'ๆ้' : currentLanguage === 'id' ? ' jam' : ' giแป';
const minUnit = currentLanguage === 'zh' ? 'ๅ้' : currentLanguage === 'en' ? ' min' : currentLanguage === 'ko' ? '๋ถ' : currentLanguage === 'ja' ? 'ๅ' : currentLanguage === 'id' ? ' menit' : ' phรบt';
durationStr = mins > 0 ? `${hours}${hourUnit} ${mins}${minUnit}` : `${hours}${hourUnit}`;
} else {
const minUnit = currentLanguage === 'zh' ? 'ๅ้' : currentLanguage === 'en' ? ' min' : currentLanguage === 'ko' ? '๋ถ' : currentLanguage === 'ja' ? 'ๅ' : currentLanguage === 'id' ? ' menit' : ' phรบt';
durationStr = `${minutes}${minUnit}`;
}
}
let mapsLink = '';
if (data.origin_lat && data.origin_lon && data.dest_lat && data.dest_lon) {
const mapsUrl = `https://www.google.com/maps/dir/${data.origin_lat},${data.origin_lon}/${data.dest_lat},${data.dest_lon}`;
mapsLink = `
<div class="data-row" style="margin-top: 8px;">
<a href="${mapsUrl}" target="_blank" style="color: #0066cc; text-decoration: none; font-size: 0.9em;">
๐บ๏ธ ${labels.view_in_maps} โ
</a>
</div>
`;
}
return `
<div class="data-row">
<span class="data-label">๐ ${labels.origin}</span>
<span class="data-value">${originLabel}</span>
</div>
<div class="data-row">
<span class="data-label">๐ฏ ${labels.destination}</span>
<span class="data-value">${destLabel}</span>
</div>
<div class="data-row">
<span class="data-label">๐ ${labels.distance}</span>
<span class="data-value">${distanceStr}</span>
</div>
<div class="data-row">
<span class="data-label">โฑ๏ธ ${labels.estimated_time}</span>
<span class="data-value">${durationStr}</span>
</div>
${mapsLink}
`;
}
function renderMetroArrivals(arrivals) {
const labels = LABELS[currentLanguage] || LABELS.zh;
if (!arrivals || arrivals.length === 0) {
return `<p class="data-row">${labels.no_data}</p>`;
}
let html = '<div class="metro-arrivals">';
const lineGroups = {};
arrivals.forEach(arr => {
const lineName = arr.line_name || labels.unknown;
if (!lineGroups[lineName]) {
lineGroups[lineName] = [];
}
lineGroups[lineName].push(arr);
});
Object.entries(lineGroups).forEach(([lineName, lineArrivals], index) => {
html += `
<div class="metro-line" style="border-bottom: 1px solid #eee; padding: 12px 0; ${index === Object.keys(lineGroups).length - 1 ? 'border-bottom: none;' : ''}">
<div class="data-row" style="margin-bottom: 8px;">
<span class="data-label" style="font-weight: bold; color: #0066cc;">๐ ${lineName}</span>
</div>
`;
lineArrivals.slice(0, 3).forEach(arr => {
const dest = arr.destination || labels.unknown;
const timeSec = arr.arrival_time_sec;
const status = arr.train_status || labels.unknown;
let timeStr = status;
if (timeSec > 0) {
const min = Math.floor(timeSec / 60);
const sec = timeSec % 60;
const minUnit = currentLanguage === 'zh' ? 'ๅ' : currentLanguage === 'en' ? ' min' : currentLanguage === 'ko' ? '๋ถ' : currentLanguage === 'ja' ? 'ๅ' : currentLanguage === 'id' ? ' menit' : ' phรบt';
const secUnit = currentLanguage === 'zh' ? '็ง' : currentLanguage === 'en' ? ' sec' : currentLanguage === 'ko' ? '์ด' : currentLanguage === 'ja' ? '็ง' : currentLanguage === 'id' ? ' detik' : ' giรขy';
timeStr = min > 0 ? `${min}${minUnit} ${sec}${secUnit}` : `${sec}${secUnit}`;
}
html += `
<div class="data-row">
<span class="data-label">โ ${dest}</span>
<span class="data-value">${timeStr}</span>
</div>
`;
});
html += '</div>';
});
html += '</div>';
return html;
}
function renderMetroStations(stations) {
const labels = LABELS[currentLanguage] || LABELS.zh;
if (!stations || stations.length === 0) {
return `<p class="data-row">${labels.no_data}</p>`;
}
let html = '<div class="metro-stations">';
stations.forEach((station, index) => {
const stationName = station.station_name || labels.unknown;
const distanceUnit = currentLanguage === 'zh' ? 'ๅ
ฌๅฐบ' : currentLanguage === 'en' ? 'm' : currentLanguage === 'ko' ? '๋ฏธํฐ' : currentLanguage === 'ja' ? 'ใกใผใใซ' : currentLanguage === 'id' ? 'm' : 'm';
const distance = station.distance_m ? `${Math.round(station.distance_m)} ${distanceUnit}` : '';
const walkTimeText = station.walking_time_min ? `${currentLanguage === 'zh' ? 'ๆญฅ่ก็ด ' : ''}${station.walking_time_min}${currentLanguage === 'zh' ? ' ๅ้' : currentLanguage === 'en' ? ' min walk' : currentLanguage === 'ko' ? '๋ถ ๋๋ณด' : currentLanguage === 'ja' ? 'ๅ ๅพๆญฉ' : currentLanguage === 'id' ? ' menit jalan' : ' phรบt ฤi bแป'}` : '';
const address = station.address || '';
html += `
<div class="metro-station-item" style="border-bottom: 1px solid #eee; padding: 12px 0; ${index === stations.length - 1 ? 'border-bottom: none;' : ''}">
<div class="data-row" style="margin-bottom: 4px;">
<span class="data-label" style="font-weight: bold; color: #0066cc;">๐ ${stationName}</span>
</div>
${distance ? `
<div class="data-row">
<span class="data-label">๐ ${labels.distance}</span>
<span class="data-value">${distance}</span>
</div>
` : ''}
${walkTimeText ? `
<div class="data-row">
<span class="data-label">๐ถ ${labels.walking_time}</span>
<span class="data-value">${walkTimeText}</span>
</div>
` : ''}
${address ? `
<div class="data-row">
<span class="data-label">๐ ${labels.address}</span>
<span class="data-value" style="font-size: 0.85em;">${address}</span>
</div>
` : ''}
</div>
`;
});
html += '</div>';
return html;
}
function renderForwardGeocode(data) {
const labels = LABELS[currentLanguage] || LABELS.zh;
const displayName = data.display_name || labels.unknown;
const lat = data.lat?.toFixed(6) || '';
const lon = data.lon?.toFixed(6) || '';
const city = data.city || '';
const road = data.road || '';
const suburb = data.suburb || '';
const mapsUrl = `https://www.google.com/maps?q=${lat},${lon}`;
return `
<div class="data-row">
<span class="data-label">๐ ${labels.location}</span>
<span class="data-value" style="font-weight: bold;">${displayName}</span>
</div>
${city ? `
<div class="data-row">
<span class="data-label">๐๏ธ ${labels.city}</span>
<span class="data-value">${city}</span>
</div>
` : ''}
${road ? `
<div class="data-row">
<span class="data-label">๐ฃ๏ธ ${labels.road}</span>
<span class="data-value">${road}</span>
</div>
` : ''}
${suburb ? `
<div class="data-row">
<span class="data-label">๐๏ธ ${labels.area}</span>
<span class="data-value">${suburb}</span>
</div>
` : ''}
<div class="data-row">
<span class="data-label">๐ ${labels.coordinates}</span>
<span class="data-value" style="font-size: 0.85em;">${lat}, ${lon}</span>
</div>
<div class="data-row" style="margin-top: 8px;">
<a href="${mapsUrl}" target="_blank" style="color: #0066cc; text-decoration: none; font-size: 0.9em;">
๐บ๏ธ ${labels.view_in_maps} โ
</a>
</div>
`;
}
function renderEnvironmentContext(data) {
const labels = LABELS[currentLanguage] || LABELS.zh;
const label = data.label || labels.unknown;
const detailedAddress = data.detailed_address || '';
const lat = data.lat?.toFixed(6) || '';
const lon = data.lon?.toFixed(6) || '';
const accuracy = data.accuracy_m ? `${data.accuracy_m}m` : '';
const device = data.device || {};
const platform = device.platform || '';
const tz = data.tz || '';
const mapsUrl = `https://www.google.com/maps?q=${lat},${lon}`;
return `
<div class="data-row">
<span class="data-label">๐ ${labels.location}</span>
<span class="data-value" style="font-weight: bold;">${label}</span>
</div>
${detailedAddress && detailedAddress !== label ? `
<div class="data-row">
<span class="data-label">๐ ${labels.address}</span>
<span class="data-value" style="font-size: 0.85em;">${detailedAddress}</span>
</div>
` : ''}
<div class="data-row">
<span class="data-label">๐ ${labels.coordinates}</span>
<span class="data-value" style="font-size: 0.85em;">${lat}, ${lon} ${accuracy ? `(ยฑ${accuracy})` : ''}</span>
</div>
${tz ? `
<div class="data-row">
<span class="data-label">โฐ ๆๅ</span>
<span class="data-value">${tz}</span>
</div>
` : ''}
${platform ? `
<div class="data-row">
<span class="data-label">๐ป ่จญๅ</span>
<span class="data-value">${platform}</span>
</div>
` : ''}
<div class="data-row" style="margin-top: 8px;">
<a href="${mapsUrl}" target="_blank" style="color: #0066cc; text-decoration: none; font-size: 0.9em;">
๐บ๏ธ ${labels.view_in_maps} โ
</a>
</div>
`;
}
function renderJSONFallback(data) {
return `<pre style="font-size: 0.85em; white-space: pre-wrap;">${JSON.stringify(data, null, 2)}</pre>`;
}
|