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 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309
|
!function(){window.Lately=new function(){var t=this;this.lang={second:"秒",minute:"分钟",hour:"小时",day:"天",month:"个月",year:"年",ago:"前",error:"NaN"};var e=function(e){e=new Date(n(e));var r=new function(){this.second=(Date.now()-e.getTime())/1e3,this.minute=this.second/60,this.hour=this.minute/60,this.day=this.hour/24,this.month=this.day/30,this.year=this.month/12},i=Object.keys(r).reverse().find(function(t){return r[t]>=1});return(i?function(t,e){return Math.floor(t)+e}(r[i],t.lang[i]):t.lang.error)+t.lang.ago},n=function(t){return t=new Date(t&&("number"==typeof t?t:t.replace(/-/g,"/").replace("T"," "))),!isNaN(t.getTime())&&t.getTime()};return{init:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=r.target,a=void 0===i?"time":i,o=r.lang;o&&(t.lang=o);var u=!0,h=!1,l=void 0;try{for(var s,c=document.querySelectorAll(a)[Symbol.iterator]();!(u=(s=c.next()).done);u=!0){var f=s.value,g=n(f.dateTime)||n(f.title)||n(f.innerHTML)||0;if(!g)return;f.title=new Date(g).toLocaleString(),f.innerHTML=e(g)}}catch(t){h=!0,l=t}finally{try{!u&&c.return&&c.return()}finally{if(h)throw l}}},format:e}}}();
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.createTemplateTagFirstArg=function(b){return b.raw=b};$jscomp.createTemplateTagFirstArgWithRaw=function(b,a){b.raw=a;return b};$jscomp.arrayIteratorImpl=function(b){var a=0;return function(){return a<b.length?{done:!1,value:b[a++]}:{done:!0}}};$jscomp.arrayIterator=function(b){return{next:$jscomp.arrayIteratorImpl(b)}};$jscomp.makeIterator=function(b){var a="undefined"!=typeof Symbol&&Symbol.iterator&&b[Symbol.iterator];return a?a.call(b):$jscomp.arrayIterator(b)}; $jscomp.arrayFromIterator=function(b){for(var a,d=[];!(a=b.next()).done;)d.push(a.value);return d};$jscomp.arrayFromIterable=function(b){return b instanceof Array?b:$jscomp.arrayFromIterator($jscomp.makeIterator(b))}; (function(){window.ViewImage=new function(){var b=this;this.target="[view-image] img";this.listener=function(a){if(!(a.ctrlKey||a.metaKey||a.shiftKey||a.altKey)){var d=String(b.target.split(",").map(function(g){return g.trim()+":not([no-view])"})),c=a.target.closest(d);if(c){var e=c.closest("[view-image]")||document.body;d=[].concat($jscomp.arrayFromIterable(e.querySelectorAll(d))).map(function(g){return g.href||g.src});b.display(d,c.href||c.src);a.stopPropagation();a.preventDefault()}}};this.init= function(a){a&&(b.target=a);["removeEventListener","addEventListener"].forEach(function(d){document[d]("click",b.listener,!1)})};this.display=function(a,d){var c=a.indexOf(d),e=(new DOMParser).parseFromString('\n <div class="view-image">\n <style>.view-image{position:fixed;inset:0;z-index:500;padding:1rem;display:flex;flex-direction:column;animation:view-image-in 300ms;backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px)}.view-image__out{animation:view-image-out 300ms}@keyframes view-image-in{0%{opacity:0}}@keyframes view-image-out{100%{opacity:0}}.view-image-btn{width:32px;height:32px;display:flex;justify-content:center;align-items:center;cursor:pointer;border-radius:3px;background-color:rgba(255,255,255,0.2)}.view-image-btn:hover{background-color:rgba(255,255,255,0.5)}.view-image-close__full{position:absolute;inset:0;background-color:rgba(48,55,66,0.3);z-index:unset;cursor:zoom-out;margin:0}.view-image-container{height:0;flex:1;display:flex;align-items:center;justify-content:center;}.view-image-lead{display:contents}.view-image-lead img{position:relative;z-index:1;max-width:100%;max-height:100%;object-fit:contain;border-radius:3px}.view-image-lead__in img{animation:view-image-lead-in 300ms}.view-image-lead__out img{animation:view-image-lead-out 300ms forwards}@keyframes view-image-lead-in{0%{opacity:0;transform:translateY(-20px)}}@keyframes view-image-lead-out{100%{opacity:0;transform:translateY(20px)}}[class*=__out] ~ .view-image-loading{display:block}.view-image-loading{position:absolute;inset:50%;width:8rem;height:2rem;color:#aab2bd;overflow:hidden;text-align:center;margin:-1rem -4rem;z-index:1;display:none}.view-image-loading::after{content:"";position:absolute;inset:50% 0;width:100%;height:3px;background:rgba(255,255,255,0.5);transform:translateX(-100%) translateY(-50%);animation:view-image-loading 800ms -100ms ease-in-out infinite}@keyframes view-image-loading{0%{transform:translateX(-100%)}100%{transform:translateX(100%)}}.view-image-tools{position:relative;display:flex;justify-content:space-between;align-content:center;color:#fff;max-width:600px;position: absolute; bottom: 5%; left: 1rem; right: 1rem; backdrop-filter: blur(10px);margin:0 auto;padding:10px;border-radius:5px;background:rgba(0,0,0,0.1);margin-bottom:constant(safe-area-inset-bottom);margin-bottom:env(safe-area-inset-bottom);z-index:1}.view-image-tools__count{width:60px;display:flex;align-items:center;justify-content:center}.view-image-tools__flip{display:flex;gap:10px}.view-image-tools [class*=-close]{margin:0 10px}.view-image{backdrop-filter:blur(5px)!important;-webkit-backdrop-filter:blur(5px)!important}.view-image-tools{opacity:1;animation:1s 1.5s forwards fadeOut}.view-image-tools:hover{opacity:1;animation:none;transition:opacity .2s}.view-image-container{margin-top:3rem}@keyframes fadeOut{to{opacity:0}}</style>\n <div class="view-image-container">\n <div class="view-image-lead"></div>\n <div class="view-image-loading"></div>\n <div class="view-image-close view-image-close__full"></div>\n </div>\n <div class="view-image-tools">\n <div class="view-image-tools__count">\n <span><b class="view-image-index">'+ (c+1)+"</b>/"+a.length+'</span>\n </div>\n <div class="view-image-tools__flip">\n <div class="view-image-btn view-image-tools__flip-prev">\n <svg width="20" height="20" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><rect width="48" height="48" fill="white" fill-opacity="0.01"/><path d="M31 36L19 24L31 12" stroke="white" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>\n </div>\n <div class="view-image-btn view-image-tools__flip-next">\n <svg width="20" height="20" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><rect width="48" height="48" fill="white" fill-opacity="0.01"/><path d="M19 12L31 24L19 36" stroke="white" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>\n </div>\n </div>\n <div class="view-image-btn view-image-close">\n <svg width="16" height="16" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><rect width="48" height="48" fill="white" fill-opacity="0.01"/><path d="M8 8L40 40" stroke="white" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M8 40L40 8" stroke="white" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>\n </div>\n </div>\n </div>\n ', "text/html").body.firstChild,g=function(f){var h={Escape:"close",ArrowLeft:"tools__flip-prev",ArrowRight:"tools__flip-next"};h[f.key]&&e.querySelector(".view-image-"+h[f.key]).click()},l=function(f){var h=new Image,k=e.querySelector(".view-image-lead");k.className="view-image-lead view-image-lead__out";setTimeout(function(){k.innerHTML="";h.onload=function(){setTimeout(function(){k.innerHTML='<img src="'+h.src+'" alt="ViewImage" no-view/>';k.className="view-image-lead view-image-lead__in"},100)}; h.src=f},300)};document.body.appendChild(e);l(d);window.addEventListener("keydown",g);e.onclick=function(f){f.target.closest(".view-image-close")?(window.removeEventListener("keydown",g),e.onclick=null,e.classList.add("view-image__out"),setTimeout(function(){return e.remove()},290)):f.target.closest(".view-image-tools__flip")&&(c=f.target.closest(".view-image-tools__flip-prev")?0===c?a.length-1:c-1:c===a.length-1?0:c+1,l(a[c]),e.querySelector(".view-image-index").innerHTML=c+1)}}}})();
"use strict";function _typeof(o){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}!function(o,t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(o=o||self,o.cocoMessage=t())}(void 0,function(){function o(o,t){var e=document.createElement("div");for(var n in o){var i=o[n];"className"==n?(n="class",e.setAttribute(n,i)):"_"==n[0]&&e.addEventListener(n.slice(1),i)}if("string"==typeof t)e.innerHTML=t;else if("object"==_typeof(t)&&t.tagName)e.appendChild(t);else if(t)for(var s=0;s<t.length;s++){var r=t[s];e.appendChild(r)}return e}function t(o,t){for(var e in t)o.style[e]=t[e];""===o.getAttribute("style")&&o.removeAttribute("style")}function e(o,t){var e=o.className||"";if(!n(e,t)){var i=e.split(/\s+/);i.push(t),o.className=i.join(" ")}}function n(o,t){return o.indexOf(t)>-1}function i(o,t){var e=o.className||"";if(n(e,t)){var i=e.split(/\s+/),s=i.indexOf(t);i.splice(s,1),o.className=i.join(" ")}""===o.className&&o.removeAttribute("class")}function s(){return r(arguments,"info")}function r(o,t){var e={};for(var n in h)e[n]=h[n];for(var i=0;i<o.length;i++){var s=o[i];void 0!==s&&("string"==typeof s||"object"==_typeof(s)?e.msg=s:"boolean"==typeof s?e.showClose=s:"function"==typeof s?e.onClose=s:"number"==typeof s&&(e.duration=s))}return e.type=t,a(e)}function a(e){var n=e.type,s=e.duration,r=e.msg,a=e.showClose,d=e.onClose,g=0===s,p=l();"loading"==n&&(r=""===r?"正在加载":r,g=a,s=0);var h=o({className:"coco-msg-wrapper"},[o({className:"coco-msg coco-msg-fade-in ".concat(n)},[o({className:"coco-msg-icon"},p[n]),o({className:"coco-msg-content"},r),o({className:"coco-msg-wait ".concat(g?"coco-msg-pointer":"coco-msg-wait-hidden"),_click:function(){f(h,d)}},c(g)||"")])]);return 0!==s&&setTimeout(function(){f(h,d)},s),m.children.length||document.body.appendChild(m),m.appendChild(h),t(h,{height:h.offsetHeight+"px"}),setTimeout(function(){i(h.children[0],"coco-msg-fade-in")},300),function(){f(h,d)}}function c(o){return o?'<svg class="coco-msg-close" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5514"><path d="M810 274l-238 238 238 238-60 60-238-238-238 238-60-60 238-238-238-238 60-60 238 238 238-238z" p-id="5515"></path></svg>':""}function f(o,n){o&&(t(o,{padding:0,height:0}),e(o.children[0],"coco-msg-fade-out"),n&&n(),setTimeout(function(){if(o){for(var t=!1,e=0;e<m.children.length;e++)m.children[e]===o&&(t=!0);t&&d(o),o=null,m.children.length||t&&d(m)}},300))}function l(){return{info:'\n <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3250"><path d="M469.333333 341.333333h85.333334v469.333334H469.333333z" fill="#ffffff" p-id="3251"></path><path d="M469.333333 213.333333h85.333334v85.333334H469.333333z" fill="#ffffff" p-id="3252"></path><path d="M384 341.333333h170.666667v85.333334H384z" fill="#ffffff" p-id="3253"></path><path d="M384 725.333333h256v85.333334H384z" fill="#ffffff" p-id="3254"></path></svg>\n ',success:'\n <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1807"><path d="M455.42 731.04c-8.85 0-17.75-3.05-24.99-9.27L235.14 553.91c-16.06-13.81-17.89-38.03-4.09-54.09 13.81-16.06 38.03-17.89 54.09-4.09l195.29 167.86c16.06 13.81 17.89 38.03 4.09 54.09-7.58 8.83-18.31 13.36-29.1 13.36z" p-id="1808" fill="#ffffff"></path><path d="M469.89 731.04c-8.51 0-17.07-2.82-24.18-8.6-16.43-13.37-18.92-37.53-5.55-53.96L734.1 307.11c13.37-16.44 37.53-18.92 53.96-5.55 16.43 13.37 18.92 37.53 5.55 53.96L499.67 716.89c-7.58 9.31-18.64 14.15-29.78 14.15z" p-id="1809" fill="#ffffff"></path></svg>\n ',warning:'\n <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="18912"><path d="M468.114286 621.714286c7.314286 21.942857 21.942857 36.571429 43.885714 36.571428s36.571429-14.628571 43.885714-36.571428L585.142857 219.428571c0-43.885714-36.571429-73.142857-73.142857-73.142857-43.885714 0-73.142857 36.571429-73.142857 80.457143l29.257143 394.971429zM512 731.428571c-43.885714 0-73.142857 29.257143-73.142857 73.142858s29.257143 73.142857 73.142857 73.142857 73.142857-29.257143 73.142857-73.142857-29.257143-73.142857-73.142857-73.142858z" p-id="18913" fill="#ffffff"></path></svg>\n ',error:'\n <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5514"><path d="M810 274l-238 238 238 238-60 60-238-238-238 238-60-60 238-238-238-238 60-60 238 238 238-238z" p-id="5515" fill="#ffffff"></path></svg>\n ',loading:'\n <div class="coco-msg_loading">\n <svg class="coco-msg-circular" viewBox="25 25 50 50">\n <circle class="coco-msg-path" cx="50" cy="50" r="20" fill="none" stroke-width="4" stroke-miterlimit="10"/>\n </svg>\n </div>\n '}}function d(o){o&&o.parentNode.removeChild(o)}function g(){for(var o=0;o<m.children.length;o++){var t=m.children[o];f(t)}}function p(){var o=document;if(o&&o.head){var t=o.head,e=o.createElement("style"),n=".coco-msg-stage *{box-sizing:border-box}.coco-msg-stage{position:fixed;top:20px;left:50%;width:auto;transform:translate(-50%,0);z-index:3000;padding-top:constant(safe-area-inset-top);padding-top:env(safe-area-inset-top)}.coco-msg-wrapper{position:relative;left:50%;transform:translate(-50%,0);transition:height .35s ease-out,padding .35s ease-out;padding:8px 0}.coco-msg{padding:8px 16px;border-radius:7px;position:relative;left:50%;transform:translate(-50%,0);display:inline-flex;align-items:center;box-shadow:0 4px 16px rgba(15,15,15,.15);color:rgba(44,44,44,.9);background-color:rgba(255,255,255,.95);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)}.dark .coco-msg{color:rgba(255,255,255,.9);background-color:rgba(36,36,36,.95);box-shadow:0 0 1px 0 rgba(55,55,55,.3)}.coco-msg-icon{position:relative;width:16px;height:16px;border-radius:100px;display:flex;justify-content:center;align-items:center}.coco-msg-icon svg{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:12px;height:12px}.coco-msg-wait{width:20px;height:20px;position:relative;display:inline-flex;justify-content:center;align-items:center;margin-left:10px}.coco-msg-wait:active svg{transform:scale(.7)}.coco-msg-wait svg{transition:.12s ease-out;fill:currentColor}.coco-msg-close{width:14px;height:14px}.coco-msg-content{margin-left:10px;text-align:left;font-size:14px;font-weight:400;word-break:keep-all;line-height:1.57143;display:inline-block}.coco-msg.info .coco-msg-icon{background-color:#3491fa}.coco-msg.success .coco-msg-icon{background-color:#00b42a}.coco-msg.warning .coco-msg-icon{background-color:#f7ba1e}.coco-msg.error .coco-msg-icon{background-color:#f53f3f}.dark .coco-msg.info .coco-msg-icon{background-color:#1d4dd2}.dark .coco-msg.success .coco-msg-icon{background-color:#129a37}.dark .coco-msg.warning .coco-msg-icon{background-color:#cc961f}.dark .coco-msg.error .coco-msg-icon{background-color:#cb2e34}.dark .coco-msg .coco-msg-icon path{fill:rgba(36,36,36,.95)}.coco-msg_loading{flex-shrink:0;width:20px;height:20px;position:relative}.coco-msg-circular{-webkit-animation:coco-msg-rotate 2s linear infinite both;animation:coco-msg-rotate 2s linear infinite both;transform-origin:center center;height:20px!important;width:20px!important;color:#3491fa;margin-top:-1px}.dark .coco-msg-circular{color:#1d4dd2}.coco-msg-path{stroke-dasharray:1,200;stroke-dashoffset:0;stroke:currentColor;-webkit-animation:coco-msg-dash 1.5s ease-in-out infinite;animation:coco-msg-dash 1.5s ease-in-out infinite;stroke-linecap:round}@-webkit-keyframes coco-msg-rotate{100%{transform:translate(-50%,-50%) rotate(360deg)}}@keyframes coco-msg-rotate{100%{transform:translate(-50%,-50%) rotate(360deg)}}@-webkit-keyframes coco-msg-dash{0%{stroke-dasharray:1,200;stroke-dashoffset:0}50%{stroke-dasharray:89,200;stroke-dashoffset:-35px}100%{stroke-dasharray:89,200;stroke-dashoffset:-124px}}@keyframes coco-msg-dash{0%{stroke-dasharray:1,200;stroke-dashoffset:0}50%{stroke-dasharray:89,200;stroke-dashoffset:-35px}100%{stroke-dasharray:89,200;stroke-dashoffset:-124px}}.coco-msg-pointer{cursor:pointer}.coco-msg-wait-hidden{display:none}.coco-msg-fade-in{-webkit-animation:coco-msg-fade .22s ease-out both;animation:coco-msg-fade .22s ease-out both}.coco-msg-fade-out{animation:coco-msg-fade .22s linear reverse both}@-webkit-keyframes coco-msg-fade{0%{opacity:0;transform:translate(-50%,-80%)}to{opacity:1;transform:translate(-50%,0)}}@keyframes coco-msg-fade{0%{opacity:0;transform:translate(-50%,-80%)}to{opacity:1;transform:translate(-50%,0)}}";e.innerHTML=n,t.appendChild(e)}}if("undefined"!=typeof window){var m=o({className:"coco-msg-stage"}),h={msg:"",duration:2e3,showClose:!1},u={info:function(){return r(arguments,"info")},success:function(){return r(arguments,"success")},warning:function(){return r(arguments,"warning")},error:function(){return r(arguments,"error")},loading:function(){return r(arguments,"loading")},destroyAll:function(){g()},config:function(o){for(var t in o)Object.hasOwnProperty.call(o,t)&&void 0!==o[t]&&(h[t]=o[t])}};for(var v in u)s[v]=u[v];return p(),s}});
class MemosBbs { constructor() { this.memosData = { dom: "#memos", listDom: "#memo-list", limit: "8" }; this.memosDom = document.querySelector(this.memosData.dom); this.memoList this.memosMyList = [ { "creatorName": #自己的名字, "website": #自己的网站地址, "link": #自己的Memos地址, "creatorId": #自己的Memos账号id, "avatar": #自己的头像url, "twikoo": #自己的twikoo地址 } ] this.memoDefaultList = [ { "creatorName": "林木木", "website": "https://immmmm.com", "link": "https://me.edui.fun", "creatorId": "101", "avatar": "https://gravatar.memobbs.app/avatar/ba83fa02fc4b2ba621514941307e21be?s=80", "twikoo": "https://metk.edui.fun" },{ "creatorName": "归臧", "website": "https://nuoea.com", "link": "https://memos.nuoea.com", "creatorId": "101", "avatar": "https://gravatar.memobbs.app/avatar/020d365ea2596ef6d516143bb0552704?s=80", "twikoo": "https://twikoo.nuoea.com" },{ "creatorName": "koobai", "website": "https://koobai.com", "link": "https://memos.koobai.com", "creatorId": "1", "avatar": "https://gravatar.memobbs.app/avatar/3b3d336a7d389b7ae8531cbe177ae9b7?s=80", "artalk": "https://c.koobai.com", "artSite": "空白唠叨" } ]; this.getEditor = window.localStorage && window.localStorage.getItem("memos-editor-display"); this.getMode = window.localStorage && window.localStorage.getItem("memos-mode"); this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); this.memosPath = window.localStorage && window.localStorage.getItem("memos-access-path"); this.memosMeID = window.localStorage && window.localStorage.getItem("memos-me-id"); this.memosMeNickname = window.localStorage && window.localStorage.getItem("memos-me-nickname"); this.memosMeAvatarUrl = window.localStorage && window.localStorage.getItem("memos-me-avatarurl"); this.memosMeArtalk = window.localStorage && window.localStorage.getItem("memos-artalk-input"); this.memosMeArtalkSite = window.localStorage && window.localStorage.getItem("memos-artalksite-input"); this.memosMeTwikoo = window.localStorage && window.localStorage.getItem("memos-twikoo-input"); this.cfwkAiUrl = window.localStorage && window.localStorage.getItem("memos-cfwkai-url") this.geminiKey = window.localStorage && window.localStorage.getItem("memos-gemini-key") this.filterName = window.localStorage && window.localStorage.getItem("memos-filter-name") this.myFeedsBtn = document.querySelector(".my-blog-feeds"); this.memosEditorInner = document.querySelector(".memos-editor-inner"); this.memosEditorOption = document.querySelector(".memos-editor-option"); this.memosRadomCont = document.querySelector(".memos-random"); this.taglistBtn = document.querySelector(".tag-btn"); this.codeoneBtn = document.querySelector(".codeone-btn"); this.codeBtn = document.querySelector(".code-btn"); this.linkBtn = document.querySelector(".link-btn"); this.linkPicBtn = document.querySelector(".linkpic-btn"); this.cfAiBtn = document.querySelector(".cfworkerai-btn") || ""; this.cfAiLoadBtn = document.querySelector(".cfworkerai-load-btn"); this.geminiAIBtn = document.querySelector(".geminiai-btn") || ""; this.geminiAILoadBtn = document.querySelector(".geminiai-load-btn"); this.randomBtn = document.querySelector(".random-btn"); this.oneDayBtn = document.querySelector(".oneday-btn"); this.userButton = document.querySelector('.user-button-span'); this.privateBtn = document.querySelector(".private-btn"); this.switchUserBtn = document.querySelector(".switchUser-btn"); this.backToEditerBtn = document.querySelector(".backto-editer-btn"); this.loadEditorBtn = document.querySelector(".call-memos-editor"); this.searchBtn = document.querySelector(".search-memos-btn"); this.searchInput = document.querySelector(".search-memos-input"); this.userlistBtn = document.querySelector(".userlist-memos"); this.randomUserBtn = document.querySelector(".randomuser-memos"); this.submitApiBtn = document.querySelector(".submit-openapi-btn"); this.submitMemoBtn = document.querySelector(".submit-memos-btn"); this.memosVisibilitySelect = document.querySelector(".select-memos-value"); this.pathInput = document.querySelector(".memos-path-input"); this.tokenInput = document.querySelector(".memos-token-input"); this.artalkInput = document.querySelector(".memos-artalk-input"); this.artalkSiteInput = document.querySelector(".memos-artalksite-input"); this.twikooInput = document.querySelector(".memos-twikoo-input"); this.cfwkAiUrlInput = document.querySelector(".cfwkai-url-input"); this.geminiKeyInput = document.querySelector(".gemini-key-input"); this.filterNameInput = document.querySelector(".filter-name-input"); this.uploadImageInput = document.querySelector(".memos-upload-image-input"); this.uploadWebpImageInput = document.querySelector(".memos-upload-Webp-image-input"); this.memosTextarea = document.querySelector(".memos-editor-textarea"); this.editMemoDom = document.querySelector(".edit-memos"); this.editMemoBtn = document.querySelector(".edit-memos-btn"); this.cancelEditBtn = document.querySelector(".cancel-edit-btn"); this.biaoqingBtn = document.querySelector(".biao-qing-btn"); this.usernowDom = document.querySelector(".user-now"); this.usernowBtnDom = document.querySelectorAll(".user-now .button"); this.goHomeBtn = document.querySelector('.gohome-memos') this.goBbsBtn = document.querySelector('.gobbs-memos') this.memoDom = document.querySelector(this.memosData.listDom); this.skeleton = `<div class="el-loading"><div class="el-skeleton mb-3"></div><div class="el-skeleton mb-3"></div><div class="el-skeleton width-50 mb-3"></div><div class="el-skeleton mb-3"></div><div class="el-skeleton mb-3"></div><div class="el-skeleton width-50 mb-3"></div></div>`; this.loadBtn = document.querySelector("button.button-load"); this.limit = this.memosData.limit; this.page = 1; this.nums = this.dataNum = this.memosContType = this.memosAccess = this.randomUser = 0; this.memoData = this.memosStr = []; this.memoCreatorMap = this.twikooCount = this.artalkCount = {}; this.memosMode; this.nowLink; this.nowId; this.nowName; this.nowAvatar; this.nowV1; this.nowTagList = ""; this.memoChangeDate = 0; this.getSelectedValue = window.localStorage && window.localStorage.getItem("memos-visibility-select") || "PUBLIC";
this._getTheme(); this._init(); this.myFeedsBtn.addEventListener('click', (event) => { this.loadBtn.classList.add('d-none'); this.memoDom.innerHTML = this.skeleton; this.usernowBtnDom.forEach((item) => {item.classList.remove('current');}) this.myFeedsBtn.classList.add("current") let fetchUrl = "https://cf.edui.fun/all?rule=created&end=20" fetch(fetchUrl).then(res => res.json()).then(resdata =>{ let myFeedData = resdata.article_data let myFeedArticle = ''; for (var i = 0;i<myFeedData.length;i++){ let item = myFeedData[i]; myFeedArticle +=` <div class="card-item flex-fill p-3"> <div class="d-flex flex-fill"> <div class="item-avatar mr-2" style="background-image:url(${item.avatar})"></div> <div class="item-sub d-flex flex-column p-1"> <div class="item-creator"><a href="${item.link}" target="_blank" rel="noopener nofollow" >${item.title}</a></div> <span class="myfeeds-floor">${item.floor}</span> <div class="item-mate mt-2 text-xs">${item.updated}</div> </div> </div> </div> `; } this.memoDom.innerHTML = `<div class="myfeeds-option row px-2 pb-2"> <div class="myfeeds-xml card-item px-3 py-2 mr-3" data-type="bfind" onclick="window.memosbbs._myFeedsXML(this)">BlogFinder</div> <div class="myfeeds-xml card-item px-3 py-2 mr-3" data-type="boyou" onclick="window.memosbbs._myFeedsXML(this)">博友圈</div> <div class="myfeeds-xml card-item px-3 py-2 mr-3" data-type="shinian" onclick="window.memosbbs._myFeedsXML(this)">十年之约</div> </div> <div class="myfeeds">${myFeedArticle}</div>`; window.Lately && Lately.init({ target: '.item-mate' }); }) }); this.memosTextarea.addEventListener('focus', () => { let nowTag = document.querySelector(".memos-tagnow-name") if(nowTag !== null && this.memosTextarea.value == ""){ this.memosTextarea.value = "#"+nowTag.textContent+" "; } }); this.searchBtn.addEventListener("click", () => { if(this.searchInput.classList.contains("d-none")){ this.userButton.classList.add("d-none") this.searchInput.classList.remove("d-none") this.searchInput.focus(); }else if(!this.searchInput.classList.contains("d-none") && this.searchInput.value == ""){ this.searchInput.classList.add("animate__fadeOutRight") setTimeout(() => { this.userButton.classList.remove("d-none") this.searchInput.classList.add("d-none") this.searchInput.classList.remove("animate__fadeOutRight") }, 500); }else if(this.searchInput.value !== ""){ this._searchNow(this.searchInput.value) } this.searchInput.addEventListener('keydown', (event) => { if (event.key === 'Enter') { this._searchNow(this.searchInput.value) } }); }); this.userlistBtn.addEventListener("click", () => { let userlistDom = document.querySelector(".userlist"); if(userlistDom){ userlistDom.remove(); }else{ let userlistDom = `<div class="userlist card-item d-flex flex-wrap mb-3 animate__animated animate__fadeIn">`; for (var i = 0; i < this.memoList.length; i++) { let nowMemo = this.memoList[i] userlistDom += `<div onclick="window.memosbbs._getUserMemos('${nowMemo.link}', '${nowMemo.creatorId}','${nowMemo.creatorName.replace(/'/g, "’")}','${nowMemo.avatar}')" class="item-avatar" style="background-image:url(${nowMemo.avatar})"></div>` } userlistDom += `</div>`; this.memosDom.insertAdjacentHTML('beforebegin', userlistDom); } }); this.goHomeBtn.addEventListener("click", () => { window.localStorage && window.localStorage.setItem("memos-mode", "MEMOSHOME"); let tagnowHas = document.querySelector(".memos-tagnow") if(tagnowHas) tagnowHas.remove(); this._goHome(); }); this.goBbsBtn.addEventListener("click", () => { window.localStorage && window.localStorage.setItem("memos-mode", "MEMOSBBS"); let tagnowHas = document.querySelector(".memos-tagnow") if(tagnowHas) tagnowHas.remove(); this._goBbs() }); this.randomUserBtn.addEventListener("click", () => { window.localStorage && window.localStorage.setItem("memos-mode", "RANDUSER"); let tagnowHas = document.querySelector(".memos-tagnow") if(tagnowHas) tagnowHas.remove(); this._goRandUser(); }); this.memosOldSelect; this.editMemoBtn.addEventListener("click", () => { let dataformNow = JSON.parse(window.localStorage && window.localStorage.getItem("memos-editor-dataform")); let memoId = dataformNow.id; let memoRelationList = dataformNow.relationList; this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); let memoContent = this.memosTextarea.value; let memocreatedTs = dataformNow.createdTs; let memoVisibility = this.memosVisibilitySelect.value; let memoResourceList = window.localStorage && JSON.parse(window.localStorage.getItem("memos-resource-list")); if(this.memoChangeDate == 1){ memocreatedTs = Math.floor(Date.now() / 1000);; } let hasContent = memoContent.length !== 0; if (hasContent) { let memoUrl = `${this.memosPath}api/v1/memo/${memoId}`; let memoBody = {content:memoContent,id:memoId,createdTs:memocreatedTs,relationList:memoRelationList,resourceIdList:memoResourceList,visibility:memoVisibility} fetch(memoUrl, { method: 'PATCH', body: JSON.stringify(memoBody), headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json' } }).then((res) => { if (res.ok) { let tagnowHas = document.querySelector(".memos-tagnow") if(tagnowHas) tagnowHas.remove(); cocoMessage.success( '修改成功', ()=>{ this.memosVisibilitySelect.value = this.memosOldSelect; this.memoChangeDate = 0; this._clearTextarea(); }) } }) } }); this.cancelEditBtn.addEventListener("click", () => { if (!this.editMemoDom.classList.contains("d-none")) { this.memosVisibilitySelect.value = this.memosOldSelect; window.localStorage && window.localStorage.removeItem("memos-editor-dataform"); this.editMemoDom.classList.add("d-none"); this.submitMemoBtn.classList.remove("d-none"); this._clearTextarea("cancel") } }); // 获取 owo.json 文件中的数据 this.emojiSelectorVisible = false; this.emojiSelector; this.emojis = [{"icon": "😂","text": "哭笑不得"},{"icon": "😎","text": "酷"},{"icon": "😏","text": "坏笑"},{"icon": "😅","text": "流汗"},{"icon": "😄","text": "笑"},{"icon": "😜","text": "调皮"},{"icon": "🤣","text": "笑倒"},{"icon": "😭","text": "大哭"},{"icon": "🙄","text": "白眼"},{"icon": "🤐","text": "嘘"},{"icon": "😋","text": "美食脸"},{"icon": "🥶","text": "冰冻"},{"icon": "🥵","text": "热"},{"icon": "😴","text": "睡觉"},{"icon": "🤧","text": "打喷嚏"},{"icon": "🍉","text": "西瓜"},{"icon": "😱","text": "惊恐"},{"icon": "👋","text": "招手"},{"icon": "🔨","text": "锤子"},{"icon": "🐶","text": "小狗"},{"icon": "👏","text": "鼓掌"},{"icon": "🙈","text": "不看"},{"icon": "😓","text": "汗"},{"icon": "😍","text": "爱心眼"},{"icon": "🤝","text": "握手"},{"icon": "🥺","text": "求你"},{"icon": "😔","text": "沮丧"},{"icon": "😪","text": "困"},{"icon": "😕","text": "困惑"},{"icon": "🤷♂️","text": "摊手"},{"icon": "😛","text": "舌头"},{"icon": "🤭","text": "偷笑"},{"icon": "🤮","text": "呕吐"},{"icon": "🥺","text": "求你"},{"icon": "🙂","text": "轻松的笑"},{"icon": "😈","text": "恶魔"},{"icon": "😃","text": "笑脸"},{"icon": "🤫","text": "嘘"},{"icon": "😒","text": "无语"},{"icon": "😵","text": "晕"},{"icon": "💪","text": "加油"},{"icon": "👍","text": "赞"},{"icon": "👎", "text": "踩"},{"icon": "😡","text": "愤怒"},{"icon": "🤬","text": "怒骂"},{"icon": "😖","text": "心烦"},{"icon": "🌹","text": "玫瑰"},{"icon": "🏃","text": "跑步"},{"icon": "😆","text": "大笑"},{"icon": "💵","text": "钞票"},{"icon": "😘","text": "飞吻"},{"icon": "😷","text": "生病"},{"icon": "🤕","text": "受伤"},{"icon": "🎉","text": "庆祝"},{"icon": "❤️","text": "红心"},{"icon": "💔","text": "心碎"},{"icon": "😣","text": "无奈"},{"icon": "😘","text": "飞吻"},{"icon": "💩","text": "一坨便便"},{"icon": "🤩","text": "爱慕"}]; // 表情选择器点击事件处理 this.biaoqingBtn.addEventListener("click", (event) => { event.stopPropagation(); this.emojiSelectorVisible = !this.emojiSelectorVisible; if (this.emojiSelectorVisible) { this._displayEmojiSelector(); } else { this.emojiSelector?.remove(); } }); this._backToTop(); // this._cfAiBtnClick(); if(this.cfwkAiUrl != null && this.cfwkAiUrl !== "") { this.cfAiBtn.addEventListener('click', async () => { this.cfAiBtn.classList.add("d-none","noclick") this.cfAiLoadBtn.classList.remove("d-none") try{ let textOld = this.memosTextarea.value let input = encodeURIComponent(this.memosTextarea.value) let fetchUrl = `${this.cfwkAiUrl}/?q=${input}` const source = new EventSource(fetchUrl); this.memosTextarea.value = `${textOld}\n----------\n` source.onmessage = (event) => { if(event.data=="[DONE]") { this.cfAiBtn.classList.remove("d-none","noclick") this.cfAiLoadBtn.classList.add("d-none") source.close(); return; } const data = JSON.parse(event.data); this.memosTextarea.value += data.response this.memosTextarea.style.height = this.memosTextarea.scrollHeight + 'px'; } } catch (error) { this.cfAiBtn.classList.add("d-none","noclick") this.cfAiLoadBtn.classList.remove("d-none") cocoMessage.error('已超时,请稍后再试~'); } }); } this.GeminiFetch = "https://lmm-api-gemini.deno.dev/v1/chat/completions"; }
_getTheme() { let getTheme = window.localStorage && window.localStorage.getItem("theme"); if (getTheme !== null && getTheme == "dark"){ document.body.classList.add("dark-theme","dark"); }else{ document.body.classList.remove("dark-theme","dark"); } if (getTheme == null && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { document.body.classList.add("dark-theme","dark"); } } async _init() { // 获取自定义列表 let memoOurList; if(typeof memosJson !== 'undefined') { try { memoOurList = await this._getMemoListData(memosJson.url); // 获取自定义列表 } catch (error) { memoOurList = this.memoDefaultList } } else { try { memoOurList = await this._getMemoListData("https://memobbs.app/memos.json"); // 获取自定义列表 } catch (error) { memoOurList = this.memoDefaultList } } if(typeof this.memosMyList !== 'undefined') { const mergedArray = [...this.memosMyList, ...memoOurList]; this.memoList = mergedArray.filter((item, index) => { const stringifiedItem = JSON.stringify(item); return index === mergedArray.findIndex(obj => { return JSON.stringify(obj) === stringifiedItem; }); }); } else { this.memoList = memoOurList } //查询当前页面 window.location.origin 作为主页展示 let memobbsAdmin = [] let memobbsLink = window.location.origin; let linkIndex = this.memoList.findIndex(item => (item.website == memobbsLink)) if(linkIndex >= 0){ memobbsAdmin.push(this.memoList[linkIndex]) const mergedArray2 = [...memobbsAdmin, ...this.memoList]; this.memoList = mergedArray2.filter((item, index) => { const stringifiedItem = JSON.stringify(item); return index === mergedArray2.findIndex(obj => { return JSON.stringify(obj) === stringifiedItem; }); }); } this.nowLink = this.memosPath || this.memoList[0].link; if (!this.nowLink.endsWith('/')) { this.nowLink += '/'; } this.nowId = this.memosMeID || this.memoList[0].creatorId; this.nowName = this.memosMeNickname || this.memoList[0].creatorName; this.nowAvatar = this.memosMeAvatarUrl || this.memoList[0].avatar; this.nowV1 = this.memoList[0].v1 || 'memo' this._memoFollow(this.getMode); this._getEditIcon(); } // 获取自定义 memos.json 订阅列表 async _getMemoListData(url) { const response = await fetch(url); const data = await response.json(); if(this.filterName){ let namesToRemove = this.filterName.replace(/,/g, ",").split(','); for (let name of namesToRemove) { let nameIndex = data.myMemoList.findIndex(item => (item.creatorName == name)); if (nameIndex !== -1) { delete data.myMemoList.splice(nameIndex, 1); } }; } return data.myMemoList } _memoFollow(mode) { //记忆显示模式 this.usernowBtnDom.forEach((item) => {item.classList.remove('current');}) if(mode == "MEMOSHOME"){ this.goHomeBtn.classList.add("current") this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","","MEMOSHOME") }else if(mode == "MEMOSBBS"){ this.goBbsBtn.classList.add("current") this._getMemos(); }else if(mode == "RANDUSER"){ this.randomUserBtn.classList.add("current") this._goRandUser() }else if(mode == "NOPUBLIC"){ this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","",mode) }else if(mode == "oneday"){ this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","",mode) }else{ this.goHomeBtn.classList.add("current") this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","","") } this.loadBtn.addEventListener("click", () => { if(this.page < this.dataNum) { this.page++; } this._updateData(this.memoData) cocoMessage.success("加载中"); }); }
async _getMemoCount(m) { let twikooData = m.filter(item => item.twikoo); if (twikooData.length !== 0) { let twikooRes = {}; for (const { creatorName, twikoo, link, id } of twikooData) { if (!twikooRes[creatorName]) { twikooRes[creatorName] = { creatorName, envId: twikoo, urls: [] }; } twikooRes[creatorName].urls.push(`${link}m/${id}`); } let twikooList = Object.values(twikooRes); let twikooPromise = await Promise.all( twikooList.map(async (item) => { try { let res = await twikoo.getCommentsCount({ envId: item.envId, urls: item.urls, includeReply: false }); return res; } catch (err) { console.error(err); return []; } }) ); this.twikooCount = twikooPromise.flatMap(r => r); } let artalkData = m.filter(item => item.artalk); if (artalkData.length !== 0) { let artalkRes = {}; for (const { creatorName, artalk, artSite, link, id } of artalkData) { if (!artalkRes[creatorName]) { artalkRes[creatorName] = { creatorName, envId: artalk, site_name: artSite, link, urls: [] }; } artalkRes[creatorName].urls.push(`/m/${id}`); } let artalkList = Object.values(artalkRes); let artalkPromise = await Promise.all( artalkList.map(async (item) => { try { let pageKeys = item.urls.join(','); let siteName = item.site_name; let response = await fetch(`${item.envId}/api/v2/stats/page_comment?page_keys=${pageKeys}&site_name=${siteName}`); if (!response.ok) { throw new Error(`Request failed`); } let results = await response.json(); let countList = item.urls.map(url => { let count = results.data[url] || 0; return { url: item.link + url, count }; }); return countList; } catch (err) { return []; } }) ) this.artalkCount = artalkPromise.flatMap(r => r); } for (const item of m) { let count = 0; let url = `${item.link}/m/${item.id}`; if (item.twikoo) { let memoCount = this.twikooCount.find((o) => o.url === url); if (memoCount) { count = memoCount.count; } } else if (item.artalk) { let memoCount = this.artalkCount.find((o) => o.url === url); if (memoCount) { count = memoCount.count; } } item.count = count; } return m; }
_updateData(res) { let oneDayTag = window.localStorage && window.localStorage.getItem("memos-oneday-tag"); if(oneDayTag !== null){ const firstItem = res.slice(0, 1); const restItems = res.slice(1); // 对后面的内容进行排序 restItems.sort((a, b) => b.createdTs - a.createdTs); // 将两部分合并在一起 const sortedArray = firstItem.concat(restItems); // 返回排序后的数组 this._pagination(sortedArray) this.dataNum = Math.ceil(sortedArray.length/this.limit); this.nums = this.dataNum - 1; if (this.page > this.nums) { this.loadBtn.classList.add('d-none'); return }; }else{ res.sort((i,o)=>{ return( o.createdTs - i.createdTs) }) this._pagination(res) this.dataNum = Math.ceil(res.length/this.limit); this.nums = this.dataNum - 1; if (this.page > this.nums) { this.loadBtn.classList.add('d-none'); return }; } }
_pagination(data) { this.memosStr = []; var last = this.page * this.limit - 1; last = last >= data.length ? (data.length - 1) : last; for (var i = (this.page * this.limit - this.limit); i <= last; i++) { this.memosStr.push(data[i]) }; this._updateHtml(this.memosStr); }
// 插入 html async _updateHtml(data) { let oneDayClass = "oneday"; let tagnowHas = document.querySelector(".memos-tagnow") this.memosMode = window.localStorage && window.localStorage.getItem("memos-mode"); let oneDayTag = window.localStorage && window.localStorage.getItem("memos-oneday-tag"); let result = '',itemOption = '',itemContent = ''; let TAG_REG = /#([^#\s!.,;:?"'()]+)(?= )/g, IMG_REG = /\!\[(.*?)\]\((.*?)\)/g, LINK_REG = /(?<!!)\[(.*?)\]\((.*?)\)/g, LINE_REG = /\n/g, BLOCKQUDTE_REG = /\>.*$/g, CODE_REG = /\```.*$/g, DOUDB_LINK_REG = /(https:\/\/(www|movie|book)\.douban\.com\/(game|subject)\/[0-9]+\/).*?/g, NEODB_LINK_REG = /(https:\/\/neodb\.social\/(game|movie|tv\/season|book)\/[0-9a-zA-Z]+)(?= )/g, BILIBILI_REG2 = /{ bilibili ([0-9a-zA-Z]+) }/g, BILIBILI_REG = /<a.*?href="https:\/\/www\.bilibili\.com\/video\/((av[\d]{1,10})|(BV([\w]{10})))\/?".*?>.*<\/a>/g, NETEASE_MUSIC_REG = /<a.*?href="https:\/\/music\.163\.com\/.*id=([0-9]+)".*?>.*<\/a>/g, QQMUSIC_REG = /<a.*?href="https\:\/\/y\.qq\.com\/.*(\/[0-9a-zA-Z]+)(\.html)?".*?>.*?<\/a>/g, QQVIDEO_REG = /<a.*?href="https:\/\/v\.qq\.com\/.*\/([a-z|A-Z|0-9]+)\.html".*?>.*<\/a>/g, YOUKU_REG = /<a.*?href="https:\/\/v\.youku\.com\/.*\/id_([a-z|A-Z|0-9|==]+)\.html".*?>.*<\/a>/g, YOUTUBE_REG = /<a.*?href="https:\/\/www\.youtube\.com\/watch\?v\=([a-z|A-Z|0-9]{11})\".*?>.*<\/a>/g, APLAYER_REG = /\{aplayer:[^}]+\}/g, SONG_TITLE_REG = /(?<=title:)[^;]+/i, SONG_ARTIST_REG = /(?<=artist:)[^;]+/i, SONG_COVER_REG = /(?<=cover:)[^;]+/i, APLAYER_SERVER_REG = /(?<=server:)([^;]+)/i, APLAYER_ID_REG = /(?<=id:)[^}]+/i, APLAYER_TYPE_REG = /(?<=type:)[^;]+/i;
marked.setOptions({ breaks: true, smartypants: false, langPrefix: 'language-' }); for (var i = 0; i < data.length; i++) { let memo = data[i]; let link = memo.link; if (!link.endsWith('/')) { link += '/'; } let memoString = JSON.stringify(memo).replace(/"/g, '"'); let avatar = memo.avatar; let count = memo.count || ""; let website = memo.website; let creatorId = memo.creatorId; let creatorName = memo.creatorName; let createdTs = memo.createdTs; let in2Week = Math.floor(new Date().getTime()/ 1000) - createdTs <= 1209600 ? "in2week" : "out2week"; let memosId = createdTs+memo.id; let memosVisibility = memo.visibility let twikooEnv = memo.twikoo; let artalkEnv = memo.artalk; let artSite = `${memo.artSite}`; let memosLink = link + "m/" + (memo.uid || memo.name || memo.id); let memosRes = memo.content .replace(TAG_REG, "") .replace(IMG_REG, "") .replace(DOUDB_LINK_REG, "") .replace(NEODB_LINK_REG, "") .replace(LINK_REG, `<a class='primary' href='$2' target='_blank'>$1</a>`) memosRes = marked.parse(memosRes) .replace(BILIBILI_REG, `<div class='video-wrapper'><iframe src='//player.bilibili.com/player.html?autoplay=0&bvid=$1' scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>`) .replace(BILIBILI_REG2, `<div class='video-wrapper'><iframe src='//player.bilibili.com/player.html?autoplay=0&bvid=$1' scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>`) .replace(NETEASE_MUSIC_REG, `<meting-js auto='https://music.163.com/#/song?id=$1'></meting-js>`) .replace(QQMUSIC_REG, `<meting-js auto='https://y.qq.com/n/yqq/song$1.html'></meting-js>`) .replace(QQVIDEO_REG, `<div class='video-wrapper'><iframe src='//v.qq.com/iframe/player.html?vid=$1' allowFullScreen='true' frameborder='no'></iframe></div>`) .replace(YOUKU_REG, `<div class='video-wrapper'><iframe src='https://player.youku.com/embed/$1' frameborder=0 'allowfullscreen'></iframe></div>`) .replace(YOUTUBE_REG, `<div class='video-wrapper'><iframe src='https://www.youtube.com/embed/$1' title='YouTube video player' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen title='YouTube Video'></iframe></div>`) .replace(APLAYER_REG, ""); let transData = memo.content.replace(TAG_REG, "").replace(IMG_REG, "").replace(LINK_REG, "$1").replace(LINE_REG, " ").replace(BLOCKQUDTE_REG, "").replace(CODE_REG, ""); if(transData.length>140){transData = transData.substring(0,140) + '...'}; let memosForm = {creatorName:creatorName,content:transData,url:memosLink}; let memosFormString = JSON.stringify(memosForm).replace(/"/g, '"'); //解析 content 内 md 格式图片 let imgArr = memo.content.match(IMG_REG); let imgStr = String(imgArr).replace(/[,]/g, ''); if (imgArr) { let memosImg = imgStr.replace(IMG_REG, `<div class="memo-resource width-100"><img class="lozad" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="$2"></div>`) memosRes += `<div class="resource-wrapper"><div class="images-wrapper my-2" view-image>${memosImg}</div></div>` } // aplayer let aplayerArr = memo.content.match(APLAYER_REG); let musicDom = ''; if (aplayerArr) { for(let x=0;x < aplayerArr.length;x++){ let server = APLAYER_SERVER_REG.exec(aplayerArr[x]), type = APLAYER_TYPE_REG.exec(aplayerArr[x]), id = APLAYER_ID_REG.exec(aplayerArr[x]), cover = SONG_COVER_REG.exec(aplayerArr[x]), title = SONG_TITLE_REG.exec(aplayerArr[x]), artist = SONG_ARTIST_REG.exec(aplayerArr[x]) musicDom += `<button class="bber-music" onclick="sco.changePlaylist('${server[0]}', '${type}', '${id}')" data-pjax-state=""><div class="bber-music-wrap"><div class="bber-music-pic" style="background: url("${cover}") center/contain no-repeat"></div><div class="bber-music-info"><div class="bber-music-title">${title}</div><div class="bber-music-artist">${artist}</div></div></div><svg fill="#000000" width="800px" height="800px" viewBox="-5.5 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M5.688 9.656v10.906c-0.469-0.125-0.969-0.219-1.406-0.219-1 0-2.031 0.344-2.875 0.906s-1.406 1.469-1.406 2.531c0 1.125 0.563 1.969 1.406 2.531s1.875 0.875 2.875 0.875c0.938 0 2-0.313 2.844-0.875s1.375-1.406 1.375-2.531v-11.438l9.531-2.719v7.531c-0.438-0.125-0.969-0.188-1.438-0.188-0.969 0-2.031 0.281-2.875 0.844s-1.375 1.469-1.375 2.531c0 1.125 0.531 2 1.375 2.531 0.844 0.563 1.906 0.906 2.875 0.906 0.938 0 2.031-0.344 2.875-0.906 0.875-0.531 1.406-1.406 1.406-2.531v-14.406c0-0.688-0.469-1.156-1.156-1.156-0.063 0-0.438 0.125-1.031 0.281-1.25 0.344-3.125 0.875-5.25 1.5-1.094 0.281-2.063 0.594-3.031 0.844-0.938 0.281-1.75 0.563-2.469 0.75-0.75 0.219-1.219 0.344-1.406 0.406-0.5 0.156-0.844 0.594-0.844 1.094z"></path></svg></button>` } } // DoubanDB let doudbArr = memo.content.match(DOUDB_LINK_REG); let neodbDom = ''; if(doudbArr){ for(let k=0;k < doudbArr.length;k++){ neodbDom += await this._fetchNeoDB(doudbArr[k],"douban") } } // DoubanDB let neodbArr = memo.content.match(NEODB_LINK_REG); if(neodbArr){ for(let l=0;l < neodbArr.length;l++){ neodbDom += await this._fetchNeoDB(neodbArr[l],"neodb") } } //标签 let tagArr = memo.content.match(TAG_REG); let memosTag = ''; if (tagArr) { memosTag = tagArr.map(t=>{ return `<div class="item-tag d-flex align-items-center text-sm line-xl mr-2 px-2" onclick="window.memosbbs._getTagNow('${link}','${creatorId}','${creatorName}','${avatar}',this)">${String(t).replace(/[#]/, '')}</div>`; }).join(''); }else{ memosTag = `<div class="item-tag d-flex align-items-center text-sm line-xl mr-2 px-2 no-cursor">动态</div>`; } //解析内置资源文件 if (memo.resourceList && memo.resourceList.length > 0) { let resourceList = memo.resourceList; let imgUrl = '',resUrl = '',resImgLength = 0; for (let j = 0; j < resourceList.length; j++) { let restype = resourceList[j].type.slice(0, 5); let resexlink = resourceList[j].externalLink; let imgLink = '', fileId = ''; if (resexlink) { imgLink = resexlink } else { fileId = resourceList[j].id; if(resourceList[j].uid !== undefined){ fileId = resourceList[j].uid }else if(resourceList[j].name !== undefined){ fileId = resourceList[j].name+"?thumbnail=1" } imgLink = `${link}o/r/${fileId}`; } if (restype == 'image') { imgUrl += `<div class="memo-resource w-100"><img class="lozad" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="${imgLink}"/></div>`; resImgLength = resImgLength + 1 } if (restype == 'video') { resUrl += `<video style="width:100%;max-height:50vh;" crossorigin="anonymous" src="${imgLink}" controls=""></video>` } if (restype !== 'video' && restype !== 'image') { resUrl += `<a class="memos-tag p-1" target="_blank" rel="noreferrer" href="${imgLink}">${resourceList[j].filename}</a>`; } } if (imgUrl) { memosRes += `<div class="resource-wrapper"><div class="images-wrapper my-2" view-image>${imgUrl}</div></div>` } if (resUrl) { memosRes += `<p class="datasource">${resUrl}</p>` } } this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); if (this.memosOpenId != null && this.memosOpenId !== "" && this.nowId == creatorId && this.nowLink == link) { itemOption = `<div class="item-option mr-1"><div class="d-flex dropdown"><svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></g></svg><div class="dropdown-wrapper d-none"><a class="btn edit-btn" data-form="${memoString}" onclick="window.memosbbs._editMemo(this)">编辑</a><a class="btn arch-btn" onclick="window.memosbbs._archiveMemo('${memo.id}')">归档</a><a class="btn del-btn" onclick="window.memosbbs._deleteMemo('${memo.id}')">删除</a></div></div></div>`; }else if (this.memosOpenId != null && this.memosOpenId !== "") { itemOption = `<div class="item-option mr-1"> <div class="d-flex dropdown"> <svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></g></svg> <div class="dropdown-wrapper d-none"> <a class="btn sav-btn" data-form="${memoString}" onclick="window.memosbbs._saveMemo(this)">收藏</a> <a class="btn via-btn" data-form="${memoString}" onclick="window.memosbbs._viaNow(this)">引用</a> <a class="btn jump-btn" href="${memosLink}" target="_blank" rel="noopener noreferrer">跳转</a> </div> </div> </div>`; }else{ itemOption = `<div class="item-option mr-1"><a class="d-flex" href="${memosLink}" target="_blank" rel="noopener noreferrer"><svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6m4-3h6v6m-11 5L21 3"></path></svg></a></div>`; } itemContent = `<div class="item-content"><div class="item-inner">${memosRes+musicDom}</div><div class="item-footer d-flex mt-2"><div class="d-flex">${memosTag}</div>`; if (twikooEnv && memosVisibility == "PUBLIC") { itemContent += `<div class="d-flex flex-fill justify-content-end"><div class="item d-flex align-items-center"><a data-id="${memo.id}" data-time="${createdTs}" data-env="${twikooEnv}" data-path="${memosLink}" onclick="window.memosbbs._loadTwikoo(this)" rel="noopener noreferrer" class="d-flex twikoo-btn"><svg xmlns="http://www.w3.org/2000/svg" width="1.25rem" height="1.25rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2zM8 10h.01M12 10h.01M16 10h.01"/></svg></a><span class="ml-1">${count}</span></div></div></div><div id="${memosId}" class="item-comment mt-3 d-none"></div>`; } else if (artalkEnv && memosVisibility == "PUBLIC") { itemContent += `<div class="d-flex flex-fill justify-content-end"><div class="item d-flex align-items-center"><a data-id="${memo.id}" data-time="${createdTs}" data-env="${artalkEnv}" data-path="${artSite}" onclick="window.memosbbs._loadArtalk(this)" rel="noopener noreferrer" class="d-flex artalk-btn"><svg xmlns="http://www.w3.org/2000/svg" width="1.25rem" height="1.25rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2zM8 10h.01M12 10h.01M16 10h.01"/></svg></a><span class="ml-1">${count}</span></div></div></div><div id="${memosId}" class="item-comment mt-3 d-none"></div>`; } else if(memosVisibility !== "PUBLIC"){ itemContent += `<div class="d-flex flex-fill justify-content-end"><div class="item d-flex align-items-center mr-1 pri-btn" onclick="window.memosbbs._getUserMemos('${link}','${creatorId}','${creatorName}','${avatar}','','','NOPUBLIC')"><svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 14 14"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M1.68 4.206C2.652 6.015 4.67 7.258 7 7.258c2.331 0 4.348-1.243 5.322-3.052M2.75 5.596L.5 7.481m4.916-.415L4.333 9.794m6.917-4.198l2.25 1.885m-4.92-.415l1.083 2.728"/></svg></div></div></div>`; } else { itemContent += `<div class="d-flex flex-fill justify-content-end"></div></div>`; } itemContent += `</div></div></div>` result = `<div class="${this.memosMode == "MEMOSHOME" && tagnowHas == null &&oneDayTag !== null && i == 0 ? oneDayClass : ''} memo-${memosId} d-flex animate__animated mb-3 memos-item"><div class="card-item flex-fill p-3"><div class="item-header d-flex mb-3"><div class="d-flex flex-fill"><div class="item-avatar mr-2" style="background-image:url(${avatar})"></div><div class="item-sub d-flex flex-column p-1"><div class="item-creator"><a ${website !== undefined ? 'href=\"' + website + '\"': ''} target="_blank">${creatorName}</a></div><div class="item-mate ${in2Week} mt-2 text-xs">${new Date(createdTs * 1000 - 5 ).toLocaleString()}</div></div></div>${itemOption}</div>${neodbDom+itemContent}</div></div>`; this.memoDom.insertAdjacentHTML('beforeend', result);
//循环绑定事件,替代元素内onclick方法 update: 放弃了,如果有更好的办法的话请告诉我吧,谢谢! let queryAvatarList = document.querySelectorAll('#memo-list .item-avatar'), lastAvatar = queryAvatarList[queryAvatarList.length - 1]; lastAvatar.addEventListener('click', () => {this._getUserMemos(link, creatorId, creatorName, avatar)}); } // end for
this.loadBtn.textContent = "加载更多"; function animation() { var animate = document.getElementsByClassName("animate__animated"); Array.prototype.slice.call(animate,0).forEach((i,index) => { const top = i.getBoundingClientRect().top; // 目标元素dom距离顶部的高度 if (top <= window.innerHeight) { // 当top小于等于文档显示区域的高时,就进入可视区域了 i.classList.contains('animate__fadeIn"') ? '' : i.classList.add("animate__fadeIn") } }) } animation(); window.addEventListener('scroll', animation); //图片灯箱 window.ViewImage && ViewImage.init('.images-wrapper img') //相对时间 window.Lately && Lately.init({ target: '.item-mate.in2week' }); //延迟加载 let observer = lozad('.lozad'); observer.observe(); //下拉菜单 let dropdowns = document.querySelectorAll(".dropdown"); Array.from(dropdowns).forEach((dropdown) => { let lis = Array.from(dropdown.children).slice(1); dropdown.addEventListener("mouseenter", () => { lis.forEach((item) => { item.classList.remove("d-none"); }); }); dropdown.addEventListener("mouseleave", () => { lis.forEach((item) => { item.classList.add("d-none"); }); }); }); } _withTimeout(millis, promise) { let timeout = new Promise((resolve, reject) => setTimeout(() => reject(`Timed out after ${millis} ms.`), millis) ); return Promise.race([promise, timeout]); }; async _getMemos(search) { this.memoData = [], this.memoCreatorMap = {}, this.page = 1, this.nums = 0, this.dataNum = 0, this.memosContType = 0, this.memosAccess = 0; this.memoDom.innerHTML = this.skeleton; this.loadBtn.classList.add("d-none"); let results; if(search && search != "" && search != null ){ results = await Promise.allSettled(this.memoList.map(u => { let uLink = u.link if (!uLink.endsWith('/')) { uLink += '/'; } const fetchUrl = `${uLink}api/v1/memo?creatorId=${u.creatorId}&content=${search}&rowStatus=NORMAL&limit=${this.limit}`; return this._withTimeout(2000, fetch(fetchUrl) .then(response => { if (!response.ok) { throw new Error(response.statusText); } return response.json(); }) ); })); }else{ results = await Promise.allSettled(this.memoList.map(async(u) => { let matchedMemo = this.memoList.find(item => item.link === u.link); let matchedV1 = matchedMemo ? matchedMemo.v1 : undefined; let fetchUrl; let uLink = u.link if (!uLink.endsWith('/')) { uLink += '/'; } if (matchedV1) { const filter = `creator=='users/${matchedMemo.creatorId}'&&visibilities==['PUBLIC']` fetchUrl = `${uLink}api/v1/memos?pageSize=${this.limit}&filter=${encodeURIComponent(filter)}` }else{ fetchUrl = `${uLink}api/v1/memo?creatorId=${u.creatorId}&rowStatus=NORMAL&limit=${this.limit}`; } const response = await this._withTimeout(2000, fetch(fetchUrl)); if (!response.ok) { throw new Error(response.statusText); } const data = await response.json(); const memosData = matchedV1 ? data.memos : data; memosData.forEach(item => { if (matchedV1 && item.createTime) { item.createdTs = Math.floor(new Date(item.createTime).getTime() / 1000); } for (let key in matchedMemo) { if (matchedMemo.hasOwnProperty(key)) { item[key] = matchedMemo[key]; } } }); return memosData })); } results = results.filter(i => i.status === 'fulfilled'); this.memoData = results.flatMap(result => result.value); //this.memoData = await getMemoCount(this.memoData); this.memoDom.innerHTML = ""; this._updateData(this.memoData); setTimeout(() => { this.loadBtn.classList.remove('d-none'); }, 1000); //setTimeout(() => { window.scrollTo({ top: this.usernowDom.offsetTop - 30, behavior: "smooth" }); //}, 800); this.goBbsBtn.classList.remove("noclick") } _myFeedsXML(e){ this.loadBtn.classList.add('d-none'); let myfeedsDom = document.querySelector(".myfeeds") document.querySelectorAll('.myfeeds-xml').forEach((item) => { item.classList.add('noclick'); item.classList.remove('current'); }) e.classList.add("current") let type = e.getAttribute("data-type") myfeedsDom.innerHTML = "" let myFeedArticle = '',entries; myfeedsDom.innerHTML = this.skeleton; if(type=="bfind"){ fetch('https://cors.memobbs.app/https://bf.zzxworld.com/feed.xml').then(response => response.text()).then(str => new window.DOMParser().parseFromString(str, 'text/xml')) .then(data => { entries = Array.from(data.querySelectorAll('entry')).map(entry => { return { title: entry.querySelector('title').textContent, link: entry.querySelector('link').getAttribute('href'), published: entry.querySelector('published').textContent, creator: entry.querySelector('author name').textContent }; }); var myFeedArticle = ''; for (var i = 0;i<20;i++){ let item = entries[i]; myFeedArticle +=` <div class="card-item flex-fill p-3"> <div class="d-flex flex-fill"> <div class="item-avatar mr-2 face" style="background-image:url('https://favicon.memobbs.app?url=${item.link}')"></div> <div class="item-sub d-flex flex-column p-1"> <div class="item-creator"><a href="${item.link}" target="_blank" rel="noopener nofollow" >${item.title}</a></div> <span class="myfeeds-floor">${i+1}</span> <div class="item-mate mt-2 text-xs">${item.published}</div> </div> </div> </div> `; myfeedsDom.innerHTML = myFeedArticle } document.querySelectorAll('.myfeeds-xml').forEach((item) => {item.classList.remove('noclick');}) window.Lately && Lately.init({target: '.item-mate'}); }); } if(type=="boyou"){ fetch("https://www.boyouquan.com/feed.xml").then(response => response.text()).then(str => new window.DOMParser().parseFromString(str, 'text/xml')) .then(data => { entries = Array.from(data.querySelectorAll('item')).map(entry => { return { title: entry.querySelector('title').textContent, link: decodeURIComponent(entry.querySelector('link').textContent.replace('https://www.boyouquan.com/go?from=feed&link=',"")), published: entry.getElementsByTagName('dc:date')[0].textContent, creator: entry.getElementsByTagName('dc:creator')[0].textContent }; }); for (var i = 0;i<20;i++){ let item = entries[i]; myFeedArticle +=` <div class="card-item flex-fill p-3"> <div class="d-flex flex-fill"> <div class="item-avatar mr-2 face" style="background-image:url('https://favicon.memobbs.app?url=${item.link}')"></div> <div class="item-sub d-flex flex-column p-1"> <div class="item-creator"><a href="${item.link}" target="_blank" rel="noopener nofollow" >${item.title}</a></div> <span class="myfeeds-floor">${i+1}</span> <div class="item-mate mt-2 text-xs">${item.published}</div> </div> </div> </div> `; myfeedsDom.innerHTML = myFeedArticle } document.querySelectorAll('.myfeeds-xml').forEach((item) => {item.classList.remove('noclick');}) window.Lately && Lately.init({target: '.item-mate'}); }); } if(type=="shinian"){ fetch("https://www.foreverblog.cn/api/v1/blog/feeds?page=1").then(res => res.json()).then(resdata =>{ for (var i = 0;i<20;i++){ let item = resdata.data.data[i]; myFeedArticle +=` <div class="card-item flex-fill p-3"> <div class="d-flex flex-fill"> <div class="item-avatar mr-2" style="background-image:url(https://gravatar.loli.net/avatar/${item.email})"></div> <div class="item-sub d-flex flex-column p-1"> <div class="item-creator"><a href="${item.link}" target="_blank" rel="noopener nofollow" >${item.title}</a></div> <span class="myfeeds-floor">${i+1}</span> <div class="item-mate mt-2 text-xs">${item.created_at}</div> </div> </div> </div> `; myfeedsDom.innerHTML = myFeedArticle } document.querySelectorAll('.myfeeds-xml').forEach((item) => {item.classList.remove('noclick');}) window.Lately && Lately.init({target: '.item-mate'}); }); } } //标签筛选且输入框为空,自动插入标签 _memosTextareaFocus() { let nowTag = document.querySelector(".memos-tagnow-name") if(nowTag !== null && this.memosTextarea.value == ""){ this.memosTextarea.value = "#"+nowTag.textContent+" "; } }; _searchNow(serchText){ if(serchText !== ""){ let tagnowHas = document.querySelector(".memos-tagnow") if(tagnowHas) tagnowHas.remove(); let usernowName = document.querySelector(".user-now-name").innerHTML; let serchDom = ` <div class="memos-tagnow row p-2 mb-2"> <div class="memos-tagnow-title mr-3">当前搜索b:</div> <div class="memos-tagnow-name card-item pr-2 pl-2" onclick="window.memosbbs._reloadUser('search')">${serchText}<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-4 h-auto ml-1 opacity-40"><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></svg></div> </div>` this.memosDom.insertAdjacentHTML('beforebegin', serchDom); if(usernowName == ""){ this._getMemos(serchText) }else{ let userNameIndex = this.memoList.findIndex(item => (item.creatorName == usernowName)); if(userNameIndex == -1){ this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"",serchText) }else{ let userNowData = this.memoList[userNameIndex] this._getUserMemos(userNowData.link,userNowData.creatorId,userNowData.creatorName,userNowData.avatar,"",serchText) } } this.searchInput.value = '' this.searchInput.classList.add("animate__fadeOutRight") setTimeout(() => { this.userButton.classList.remove("d-none") this.searchInput.classList.add("d-none") this.searchInput.classList.remove("animate__fadeOutRight") }, 500); } } //返回个人主页 _goHome(){ this.goHomeBtn.classList.add("noclick") this.usernowBtnDom.forEach((item) => {item.classList.remove('current');}) this.goHomeBtn.classList.add("current") this.goBbsBtn.classList.remove("current") this.randomUser = 0; this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar) cocoMessage.success("Hi, "+this.nowName); }; //切换为广场模式 _goBbs(){ this.goBbsBtn.classList.add("noclick") this.usernowBtnDom.forEach((item) => {item.classList.remove('current');}) this.goBbsBtn.classList.add("current") this.goHomeBtn.classList.remove("current") this._getMemos(); let usernowName = document.querySelector(".user-now-name"); let usernowAvatar = document.querySelector(".user-now-avatar"); usernowName.innerHTML = ""; usernowAvatar.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; //this.goBbsBtn.classList.remove("noclick") cocoMessage.success("有啥新鲜事儿?"); }; //随机个人 _goRandUser(){ this.randomUser = 1; this.usernowBtnDom.forEach((item) => {item.classList.remove('current');}) this.randomUserBtn.classList.add("current") let usernowName = document.querySelector(".user-now-name"); let usernowAvatar = document.querySelector(".user-now-avatar"); usernowName.innerHTML = "" usernowAvatar.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" let randomIndex = Math.round(Math.random() * (this.memoList.length - 1)); let userNowData = this.memoList[randomIndex] this._getUserMemos(userNowData.link,userNowData.creatorId,userNowData.creatorName,userNowData.avatar,"","") cocoMessage.success(userNowData.creatorName+" 上线~"); } //重载当前 user _reloadUser(mode){ let tagnowHas = document.querySelector(".memos-tagnow") if(tagnowHas) tagnowHas.remove(); let usernowName = document.querySelector(".user-now-name").innerHTML; if(usernowName == ""){ this._getMemos() }else{ let userNameIndex = this.memoList.findIndex(item => (item.creatorName == usernowName)); if(userNameIndex == -1){ this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar) }else{ let userNowData = this.memoList[userNameIndex] this._getUserMemos(userNowData.link,userNowData.creatorId,userNowData.creatorName,userNowData.avatar) } } if(mode == "search"){ this.memosTextarea.value = ''; } } // 获取指定用户列表 async _getUserMemos(link,id,name,avatar,tag,search,mode,random) { let matchedMemo = this.memoList.find(item => (item.link === link)) let matchedV1 = matchedMemo ? matchedMemo.v1 : undefined; this.memoDom.innerHTML = this.skeleton; this.loadBtn.classList.add('d-none'); this.randomUserBtn.classList.add("noclick"); this.memoData = [],this.memoCreatorMap = {}, this.page = 1,this.nums = 0,this.dataNum = 0,this.memosContType = 1; this.memosPath = window.localStorage && window.localStorage.getItem("memos-access-path"); let usernowName = document.querySelector(".user-now-name"); let usernowAvatar = document.querySelector(".user-now-avatar"); usernowName.innerHTML = name; usernowAvatar.src = avatar; if (!link.endsWith('/')) { link += '/'; } if (this.memosPath && !this.memosPath.endsWith('/')) { this.memosPath += '/'; } if (link == this.memosPath) { this.memosAccess = 1; }; let userMemoUrl; if(tag && (random == null || random == "" )){ userMemoUrl = `${link}api/v1/memo?creatorId=${id}&tag=${tag}&rowStatus=NORMAL&limit=50`; }else if(search){ userMemoUrl = `${link}api/v1/memo?creatorId=${id}&content=${search}&rowStatus=NORMAL&limit=${this.limit}`; }else if(mode == "NOPUBLIC"){ userMemoUrl = `${link}api/v1/memo`; }else if(random){ if(tag){ userMemoUrl = `${link}api/v1/memo?tag=${tag}&limit=1&offset=${random}`; }else{ userMemoUrl = `${link}api/v1/memo?&limit=1&offset=${random}`; } }else{ if (matchedV1) { const filter = `creator=='users/${id}'&&visibilities==['PUBLIC']` userMemoUrl = `${link}api/v1/memos?pageSize=50&filter=${encodeURIComponent(filter)}` }else{ userMemoUrl = `${link}api/v1/memo?creatorId=${id}&rowStatus=NORMAL&limit=50`; } }
if (link == this.memosPath) { try { let response = await fetch(userMemoUrl,{ headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', }, cache: 'no-store', }); if (response.ok) { let data = await response.json(); if(this.nowV1 == "memos"){ data = data.memos } let oneDayTag = window.localStorage && window.localStorage.getItem("memos-oneday-tag"); let oneDayTagCount = window.localStorage && window.localStorage.getItem("memos-oneday-count"); if( oneDayTag !== null && oneDayTagCount !== null && !search ){ let randomOneNum = Math.floor(Math.random() * oneDayTagCount) let oneDayUrl = `${link}api/v1/memo?tag=${oneDayTag}&limit=1&offset=${randomOneNum}` try { let responseOne = await fetch(oneDayUrl,{ headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', }, cache: 'no-store', }); if (!responseOne.ok) { throw new Error(`Request failed oneDay`); } dataone = await responseOne.json(); data.splice(0, 0, ...dataone); } catch (error) { console.error(error); } } data.forEach(item => { item.avatar = this.memosMeAvatarUrl item.link = this.memosPath item.twikoo = this.memosMeTwikoo item.artalk = this.memosMeArtalk item.artSite = `${this.memosMeArtalkSite}` }); if (mode == "NOPUBLIC") { let memosCount = data.length; window.localStorage && window.localStorage.setItem("memos-response-count", memosCount); data = data.filter((item) => item.visibility !== "PUBLIC"); } this.memoData = data.flatMap(result => result); if(this.nowV1 == "memos"){ let creatorName = name let creatorId = id let linkFind = this.memoList.find(item => (item.link == link)); let website = linkFind ? linkFind.website : undefined; this.memoData = this.memoData.map(item => { let cTime = new Date(item.createTime) let createdTs = Math.floor(cTime.getTime() / 1000); return {...item, creatorName,avatar,createdTs,creatorId,link,website}; }); }else{ this.memoList.forEach(item => { this.memoCreatorMap[item.creatorName] = item; }); this.memoData = this.memoData.map(item => { let data = this.memoCreatorMap[item.creatorName]; return {...item, ...data}; }); } if (mode !== "NOPUBLIC") { this.memoData = await this._getMemoCount(this.memoData); } this.memoDom.innerHTML = ""; this._updateData(this.memoData); if(!random && this.memoData.length >= 8 ){ setTimeout(() => { this.loadBtn.classList.remove('d-none'); }, 1000); } } } catch (error) { console.error(error); } }else{ try { let response = await fetch(userMemoUrl); if (!response.ok) { throw new Error(response.statusText); } let data = await response.json(); if(matchedV1){ data = data.memos let creatorName = name let creatorId = id let linkFind = this.memoList.find(item => (item.link == link)); let website = linkFind ? linkFind.website : undefined; this.memoData = data.flatMap(result => result); this.memoData = this.memoData.map(item => { let cTime = new Date(item.createTime) let createdTs = Math.floor(cTime.getTime() / 1000); return {...item, creatorName,avatar,createdTs,creatorId,link,website}; }); }else{ this.memoData = data.flatMap(result => result); this.memoList.forEach(item => { this.memoCreatorMap[item.creatorName] = item; }); this.memoData = this.memoData.map(item => { let data = this.memoCreatorMap[item.creatorName]; return {...item, ...data}; }); } this.memoData = await this._getMemoCount(this.memoData); this.memoDom.innerHTML = ""; this._updateData(this.memoData); if(this.memoData.length >= 8 ){ setTimeout(() => { this.loadBtn.classList.remove('d-none'); }, 1000); } } catch (error) { console.error(error); } } setTimeout(() => { this.goHomeBtn.classList.remove("noclick") this.randomUserBtn.classList.remove("noclick") }, 800); window.scrollTo({ top: this.usernowDom.offsetTop - 30, behavior: "smooth" }); } // Fetch NeoDB async _fetchNeoDB(url,mode){ let urlNow; if(mode == "douban"){ urlNow = "https://api-neodb.immmmm.com/?url="+url }else if(mode = "neodb"){ urlNow = url.replace("social/","social/api/") } let response = await fetch(urlNow); let dbFetch = await response.json(); let neodbDom = `<div class="db-card"> <div class="db-card-subject"> <div class="db-card-post"><img loading="lazy" decoding="async" referrerpolicy="no-referrer" src="https://cors.immmmm.com/${dbFetch.cover_image_url}"></div> <div class="db-card-content"> <div class="db-card-title"><a href="${url}" class="cute" target="_blank" rel="noreferrer">${dbFetch.title}</a></div> <div class="rating"><span class="allstardark"><span class="allstarlight" style="width:${dbFetch.rating*10}%"></span></span><span class="rating_nums">${dbFetch.rating}</span></div> <div class="db-card-abstract">${dbFetch.brief}</div> </div> <div class="db-card-cate">${dbFetch.category}</div> </div> </div>` return neodbDom } //获取指定 Tag _getTagNow(u,i,n,a,e){ let tagnowHas = document.querySelector(".memos-tagnow") if(tagnowHas) tagnowHas.remove(); let tagName = e.innerHTML let tagnowDom = ` <div class="memos-tagnow row p-2 mb-2"> <div class="memos-tagnow-title mr-3">标签筛选:</div> <div class="memos-tagnow-name card-item pr-2 pl-2" onclick="window.memosbbs._reloadUser()">${tagName}<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-4 h-auto ml-1 opacity-40"><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></svg></div> </div>` this.memosDom.insertAdjacentHTML('beforebegin', tagnowDom); this._getUserMemos(u,i,n,a,tagName); } // 加载Twikoo评论 _loadTwikoo(i) { let twikooEnv = i.getAttribute("data-env") let twikooPath = i.getAttribute("data-path") let twikooId = i.getAttribute("data-id") let twikooTime = i.getAttribute("data-time") let twikooDom = document.getElementById(`${Number(twikooTime)+Number(twikooId)}`); let twikooCon = "<div id='twikoo'></div>" if (twikooDom.classList.contains('d-none')) { document.querySelectorAll('.item-comment').forEach((item) => {item.classList.add('d-none');}) if(document.getElementById("twikoo")){ document.getElementById("twikoo").remove() } twikooDom.insertAdjacentHTML('beforeend', twikooCon); twikooDom.classList.remove('d-none'); twikoo.init({ envId: twikooEnv, el: '#twikoo', path: twikooPath }); }else{ twikooDom.classList.add('d-none'); document.getElementById("twikoo").remove() } } // 加载Artalk评论 _loadArtalk(e) { let artalkEnv = e.getAttribute("data-env") let artalkPath= e.getAttribute("data-path") let artalkId = e.getAttribute("data-id") let artalkTime = e.getAttribute("data-time") let artalkDom = document.getElementById(`${Number(artalkTime) + Number(artalkId)}`); let artalkCon = "<div id='artalk'></div>" if (artalkDom.classList.contains('d-none')) { document.querySelectorAll('.item-comment').forEach((item) => {item.classList.add('d-none');}) if(document.getElementById("artalk")){ document.getElementById("artalk").remove() } artalkDom.insertAdjacentHTML('beforeend', artalkCon); artalkDom.classList.remove('d-none'); Artalk.init({ el: '#artalk', pageKey: '/m/' + artalkId, pageTitle: '', site: artalkPath, server: artalkEnv, emoticons: false }); }else{ artalkDom.classList.add('d-none'); document.getElementById("artalk").remove() } } //收藏 _saveMemo(memo) { let e = JSON.parse(memo.getAttribute("data-form")); let memosContent = e.content; this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); let hasContent = memosContent.length !== 0; if (this.memosOpenId && hasContent) { this.submitMemoBtn.classList.add("noclick") let memoUrl = `${this.memosPath}api/v1/memo`; let memoBody = {content:memosContent,visibility:"PRIVATE"} fetch(memoUrl, { method: 'POST', body: JSON.stringify(memoBody), headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json' } }).then((res) => { cocoMessage.success('收藏成功') }); }else if(!hasContent){ cocoMessage.info('内容不能为空'); } } //编辑修改 _editMemo(memo) { this.memosOldSelect = this.memosVisibilitySelect.value; this.getEditor = window.localStorage && window.localStorage.getItem("memos-editor-display"); this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); if(this.memosOpenId && this.getEditor == "show"){ document.querySelector(".memos-image-list").innerHTML = ''; let e = JSON.parse(memo.getAttribute("data-form")); let memoResList = e.resourceList,memosResource = [],imageList = ""; this.memosVisibilitySelect.value = e.visibility; window.localStorage && window.localStorage.setItem("memos-editor-dataform",JSON.stringify(e)); window.localStorage && window.localStorage.setItem("memos-visibility-select",this.memosVisibilitySelect.value); this.memosTextarea.value = e.content; this.memosTextarea.style.height = this.memosTextarea.scrollHeight + 'px'; this.submitMemoBtn.classList.add("d-none"); this.editMemoDom.classList.remove("d-none"); if(memoResList.length > 0){ for (let i = 0; i < memoResList.length; i++) { let imgLink = '', fileId = '',resexlink = memoResList[i].externalLink; if (resexlink) { imgLink = resexlink } else { fileId = memoResList[i].publicId || memoResList[i].filename imgLink = `${this.memosPath}/o/r/${memoResList[i].id}`;///${fileId} } memosResource.push(memoResList[i].id); imageList += `<div data-id="${memoResList[i].id}" class="imagelist-item d-flex text-xs mt-2 mr-2" onclick="window.memosbbs._deleteImage(this)"><div class="d-flex image-background" style="background-image:url(${imgLink})"><span class="d-none">${fileId}</span></div></div>`; } window.localStorage && window.localStorage.setItem("memos-resource-list", JSON.stringify(memosResource)); document.querySelector(".memos-image-list").insertAdjacentHTML('afterbegin', imageList); //this._imageListDrag() } document.body.scrollIntoView({behavior: 'smooth'}); } } _setMemoTag(e){ let memoTag = ''; const inputValue = this.memosTextarea.value; const lastWord = inputValue.charAt(inputValue.length - 1); if (lastWord == '#') { memoTag = e.textContent.replace("#","") + " "; }else{ memoTag = e.textContent + " "; } this.memosTextarea.value += memoTag; this.memosTextarea.focus() document.querySelector(".memos-tag-list").classList.add("d-none"); } //归档 _archiveMemo(memoId) { let isOk = confirm("确认归档?"); if(isOk){ this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); if(this.memosOpenId && memoId){ let memoUrl = `${this.memosPath}api/v1/memo/${memoId}`; let memoBody = {id:memoId,rowStatus:"ARCHIVED"}; fetch(memoUrl, { method: 'PATCH', body: JSON.stringify(memoBody), headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json' } }).then((res) => { if (res.ok) { cocoMessage.success( '归档成功', ()=>{ this.memosMode = window.localStorage && window.localStorage.getItem("memos-mode"); this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","",this.memosMode) }) } }) } } } //删除 _deleteMemo(memoId) { let isOk = confirm("确认删除?"); if(isOk){ this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); if(this.memosOpenId && memoId){ let memoUrl = `${this.memosPath}api/v1/memo/${memoId}`; fetch(memoUrl, { method: 'DELETE', headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json' } }).then((res) => { if (res.ok) { cocoMessage.success( '删除成功', ()=>{ this.memosMode = window.localStorage && window.localStorage.getItem("memos-mode"); this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","",this.memosMode) }) } }).catch(err => { cocoMessage.error('出错了,再检查一下吧') }) } } } _viaNow(e){ let dataForm = JSON.parse(e.getAttribute("data-form")); let memoName = dataForm.creatorName let memoLink = dataForm.link+ "/m/" + (dataForm.name || dataForm.id); let memoContent = dataForm.content if(memoContent.length > 120){ memoContent = memoContent.substring(0, 119) + '...'; } let viaCopy = `${memoContent}(via [@${memoName}](${memoLink}))` navigator.clipboard.writeText(viaCopy).then(() => { cocoMessage.success("引用内容已复制") }); } _getEditIcon() { let memosContent = ''; let memosVisibility = ''; let memosResource = []; let memosRelation = []; let memosCount = window.localStorage && window.localStorage.getItem("memos-response-count"); this.memosPath = window.localStorage && window.localStorage.getItem("memos-access-path"); this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); this.getEditor = window.localStorage && window.localStorage.getItem("memos-editor-display"); let isHide = this.getEditor === "hide"; this.memosVisibilitySelect.value = this.getSelectedValue; window.localStorage && window.localStorage.setItem("memos-resource-list", JSON.stringify(memosResource)); window.localStorage && window.localStorage.setItem("memos-relation-list", JSON.stringify(memosRelation)); let memosTagList = document.querySelector(".memos-tag-list") let selectedTagIndex = -1; this.memosTextarea.addEventListener('input', (e) => { this.memosTextarea.style.height = 'inherit'; this.memosTextarea.style.height = e.target.scrollHeight + 'px'; const inputValue = this.memosTextarea.value; const lastWord = inputValue.slice(-2); if (lastWord == ' #') { memosTagList.classList.remove('d-none'); } else { memosTagList.classList.add('d-none'); } }); this.memosTextarea.addEventListener('keydown', event => { const keyCode = event.keyCode; if (memosTagList.classList.contains("d-none") === false) { const matchingTags = Array.from(memosTagList.querySelectorAll('.memos-tag')).map(tag => tag.textContent); if (keyCode === 38 || keyCode === 40 || keyCode === 37 || keyCode === 39) { // 添加左右方向键的处理 event.preventDefault(); if (keyCode === 37 || keyCode === 39) { // 处理左右方向键 const direction = keyCode === 37 ? -1 : 1; selectedTagIndex = (selectedTagIndex + direction + matchingTags.length) % matchingTags.length; } else { // 处理上下方向键 selectedTagIndex = (selectedTagIndex + (keyCode === 38 ? -1 : 1) + matchingTags.length) % matchingTags.length; } Array.from(memosTagList.querySelectorAll('.memos-tag')).forEach((option, index) => option.classList.toggle('selected', index === selectedTagIndex)); } else if (keyCode === 13 && selectedTagIndex !== -1) { event.preventDefault(); let tagName = matchingTags[selectedTagIndex].replace(/[#]/,'') + " " this._insertValue(tagName,"",0) memosTagList.querySelector('.memos-tag').classList.remove('selected'); memosTagList.classList.add('d-none'); selectedTagIndex = -1; } } }); if (this.getEditor !== null) { document.querySelector(".memos-editor").classList.toggle("d-none",isHide); this.getEditor == "show" ? this._hasMemosOpenId() : ''; }; this.loadEditorBtn.addEventListener("click", () => { this.getEditor != "show" ? this._hasMemosOpenId() : ''; document.querySelector(".memos-editor").classList.toggle("d-none"); window.localStorage && window.localStorage.setItem("memos-editor-display", document.querySelector(".memos-editor").classList.contains("d-none") ? "hide" : "show"); this.getEditor = window.localStorage && window.localStorage.getItem("memos-editor-display"); }); this.taglistBtn.addEventListener("click", () => { document.querySelector(".memos-tag-list").classList.toggle("d-none"); }); //todoBtn.addEventListener("click", () => { // let memoTodo = '- [] \n'; // this._insertValue(memoTodo); // let bracketIndex = this.memosTextarea.value.indexOf("[]"); // if (bracketIndex !== -1) { // this.memosTextarea.selectionStart = bracketIndex + 1; // this.memosTextarea.selectionEnd = bracketIndex + 1; // } //}); this.codeoneBtn.addEventListener("click", () => { this._insertValue(" `` ","`",2) }); this.codeBtn.addEventListener("click", () => { let memoCode = "```\n\n```\n"; this._insertValue(memoCode,"",5); this.memosTextarea.style.height = this.memosTextarea.scrollHeight + 'px'; }); this.linkBtn.addEventListener("click", () => { this._insertValue(" []() ","[",2) }); this.linkPicBtn.addEventListener("click", () => { this._insertValue(" ![]() ","!",2) }); this.memosVisibilitySelect.addEventListener('change', () => { let memoNowSelct = window.localStorage && window.localStorage.getItem("memos-visibility-select"); var selectedValue = this.memosVisibilitySelect.value; window.localStorage && window.localStorage.setItem("memos-visibility-select",selectedValue); if(memoNowSelct == "PRIVATE" && selectedValue == "PUBLIC"){ this.memoChangeDate = 1; } }); this.privateBtn.addEventListener("click", async () => { if (!this.privateBtn.classList.contains("private")) { this.privateBtn.classList.add("private") this.memosVisibilitySelect.value = "PRIVATE" this.usernowBtnDom.forEach((item) => {item.classList.remove('current');}) window.localStorage && window.localStorage.setItem("memos-mode", "NOPUBLIC"); this.memosMode = window.localStorage && window.localStorage.getItem("memos-mode"); this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","","NOPUBLIC") cocoMessage.success("进入「私有浏览」模式") }else{ this.memosVisibilitySelect.value = "PUBLIC" window.localStorage && window.localStorage.setItem("memos-mode", ""); this.privateBtn.classList.remove("private") this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","","") cocoMessage.success("已退出「私有浏览」模式") } }); this.randomBtn.addEventListener("click", async () => { let memosAllCount = window.localStorage && window.localStorage.getItem("memos-response-count"); let nowTag,userMemoUrl,nowTagText = document.querySelector(".memos-tagnow-name") || '' if(nowTagText){ nowTag = nowTagText.textContent; userMemoUrl= `${this.nowLink}api/v1/memo?tag=${nowTag}` }else{ userMemoUrl = `${this.nowLink}api/v1/memo/stats?creatorId=${this.nowId}` } if(!memosAllCount || nowTagText){ try { let response = await fetch(userMemoUrl,{ headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', }, cache: 'no-store', }); if (!response.ok) { throw new Error(response.statusText); } let data = await response.json(); memosAllCount = data.length - 1; if(!nowTag){ window.localStorage && window.localStorage.setItem("memos-response-count",memosAllCount); } let randomNum = this._random(0,memosAllCount); this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,nowTag,"","",randomNum) } catch (error) { console.error(error); } if(nowTagText){ this.oneDayBtn.classList.remove("d-none") } }else{ let randomNum = this._random(0,memosAllCount); this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,nowTag,"","",randomNum) } }); //开启回忆一条 this.oneDayBtn.addEventListener("click", async () => { let oneDayNow = window.localStorage && window.localStorage.getItem("memos-oneday-tag"); if (oneDayNow == null ) { let nowTag = document.querySelector(".memos-tagnow-name").textContent let nowTagCount; let nowTagUrl= `${this.nowLink}api/v1/memo?tag=${nowTag}` try { let response = await fetch(nowTagUrl,{ headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', }, cache: 'no-store', }); if (!response.ok) { throw new Error(response.statusText); } let data = await response.json(); nowTagCount = data.length - 1; window.localStorage && window.localStorage.setItem("memos-oneday-tag",nowTag); window.localStorage && window.localStorage.setItem("memos-oneday-count",nowTagCount); } catch (error) { console.error(error); } cocoMessage.success("开启「OneDay」") }else{ window.localStorage && window.localStorage.removeItem("memos-oneday-tag"); window.localStorage && window.localStorage.removeItem("memos-oneday-count"); cocoMessage.success("已退出「OneDay」") } this.oneDayBtn.classList.add("d-none") }); this.uploadWebpImageInput.addEventListener('change', () => { let filesData = this.uploadWebpImageInput.files; if (filesData.length !== 0) { for (let i = 0; i < filesData.length; i++) { this._uploadWebpImage(filesData[i]); } cocoMessage.info('压缩并上传中……'); } });
this.uploadImageInput.addEventListener('change', () => { let filesData = this.uploadImageInput.files[0]; if (this.uploadImageInput.files.length !== 0){ this._uploadImage(filesData); cocoMessage.info('图片上传中……'); } });
this.switchUserBtn.addEventListener("click", () => { this.memosEditorOption.classList.remove("d-none"); this.memosEditorInner.classList.add("d-none"); this.memosRadomCont.innerHTML = ''; //this.tokenInput.value = ''; //this.pathInput.value = ''; }); this.backToEditerBtn.addEventListener("click", () => { this.memosEditorOption.classList.add("d-none"); this.memosEditorInner.classList.remove("d-none"); this.memosRadomCont.innerHTML = ''; }); this.submitApiBtn.addEventListener("click", () => { if(this.tokenInput.value == null || this.tokenInput.value == ''){ cocoMessage.info('请输入Token'); }else if(this.pathInput.value == null || this.pathInput.value == ''){ cocoMessage.info('请输入Path'); }else{ let pathInputValue = this.pathInput.value; if (pathInputValue.substr(-1) === '/') { pathInputValue = pathInputValue.substr(0, pathInputValue.length - 1); } this._getMemosData(pathInputValue,this.tokenInput.value); if(this.artalkInput.value !== null || this.artalkInput.value !== '') window.localStorage && window.localStorage.setItem("memos-artalk-input", this.artalkInput.value); if(this.artalkSiteInput.value !== null || this.artalkSiteInput.value !== '') window.localStorage && window.localStorage.setItem("memos-artalksite-input", this.artalkSiteInput.value); if(this.twikooInput.value !== null || this.twikooInput.value !== '') window.localStorage && window.localStorage.setItem("memos-twikoo-input", this.twikooInput.value); if(this.cfwkAiUrlInput.value !== null || this.cfwkAiUrlInput.value !== '') window.localStorage && window.localStorage.setItem("memos-cfwkai-url", this.cfwkAiUrlInput.value); if(this.geminiKeyInput.value !== null || this.geminiKeyInput.value !== '') window.localStorage && window.localStorage.setItem("memos-gemini-key", this.geminiKeyInput.value); if(this.filterNameInput.value !== null || this.filterNameInput.value !== '') window.localStorage && window.localStorage.setItem("memos-filter-name", this.filterNameInput.value); } }); this.submitMemoBtn.addEventListener("click", () => { let memosContent = this.memosTextarea.value; let memosVisibility = this.memosVisibilitySelect.value; let memosResource = window.localStorage && JSON.parse(window.localStorage.getItem("memos-resource-list")); let memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); let TAG_REG = /(?<=#)([^#\s!.,;:?"'()]+)(?= )/g; let memosTag = memosContent.match(TAG_REG); let hasContent = memosContent.length !== 0; if (memosOpenId && hasContent) { this.submitMemoBtn.classList.add("noclick") let memoUrl = `${this.memosPath}api/v1/${this.nowV1}`; let memoBody = {content:memosContent,relationList:memosRelation,resourceIdList:memosResource,visibility:memosVisibility} fetch(memoUrl, { method: 'POST', body: JSON.stringify(memoBody), headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json' } }).then((res) => { if (res.status == 200) { if (memosTag !== null && this.nowV1 !== 'memos') { let memoTagUrl = `${this.memosPath}api/v1/tag`; (async () => { for await (const i of memosTag) { const response = await fetch(memoTagUrl, { method: 'POST', headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: i }) }); } })(); } cocoMessage.success( '发送成功', () => { this._clearTextarea() }) } }); }else if(!hasContent){ cocoMessage.info('内容不能为空'); }else{ cocoMessage.info( '请设置 Access Tokens', () => { this.memosEditorInner.classList.add("d-none"); this.memosEditorOption.classList.remove("d-none"); } ); } }); } async _uploadWebpImage(data) { let memosPath = window.localStorage && window.localStorage.getItem("memos-access-path"); let memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); let memosResourceListNow = JSON.parse(window.localStorage && window.localStorage.getItem("memos-resource-list")) || []; let imageData = new FormData(); let blobUrl = `${memosPath}api/v1/resource/blob`; const webpData = await this._convertToWebP(data); const timestamp = new Date().getTime(); const fileName = `${timestamp}_${Math.random()}.webp`; imageData.append('file', webpData, fileName); let resp = await fetch(blobUrl, { method: "POST", body: imageData, headers: { 'Authorization': `Bearer ${memosOpenId}` } }); let res = await resp.json(); if (res.id) { let resexlink = res.externalLink; let imgLink = '', fileId = ''; if (resexlink) { imgLink = resexlink; } else { fileId = res.publicId || res.filename; imgLink = `${memosPath}/o/r/${res.id}`; } let imageList = ""; imageList += `<div data-id="${res.id}" class="imagelist-item d-flex text-xs mt-2 mr-2" onclick="window.memosbbs._deleteImage(this)"> <div class="d-flex image-background" style="background-image:url(${imgLink})"> <span class="d-none">${fileId}</span> </div> </div>`; document.querySelector(".memos-image-list").insertAdjacentHTML('afterbegin', imageList); cocoMessage.success('上传成功', () => { memosResourceListNow.push(res.id); window.localStorage && window.localStorage.setItem("memos-resource-list", JSON.stringify(memosResourceListNow)); this._imageListDrag(); }); } }
_convertToWebP(imageData) { return new Promise((resolve) => { const img = new Image(); img.onload = () => { const canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0, img.width, img.height); canvas.toBlob((blob) => { resolve(blob); }, 'image/webp', 0.7); // 设置压缩质量为70% }; img.src = URL.createObjectURL(imageData); }); };
async _uploadImage(data) { let memosPath = window.localStorage && window.localStorage.getItem("memos-access-path"); let memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); let memosResourceListNow = JSON.parse(window.localStorage && window.localStorage.getItem("memos-resource-list")) || []; let imageData = new FormData(); let blobUrl = `${memosPath}api/v1/resource/blob`; imageData.append('file', data, data.name) let resp = await fetch(blobUrl, { method: "POST", body: imageData, headers: { 'Authorization': `Bearer ${memosOpenId}` } }) let res = await resp.json(); if(res.id){ let resexlink = res.externalLink; let imgLink = '', fileId = ''; if (resexlink) { imgLink = resexlink } else { fileId = res.publicId || res.filename imgLink = `${memosPath}/o/r/${res.id}`;///${fileId} } let imageList = ""; imageList += `<div data-id="${res.id}" class="imagelist-item d-flex text-xs mt-2 mr-2" onclick="window.memosbbs._deleteImage(this)"><div class="d-flex image-background" style="background-image:url(${imgLink})"><span class="d-none">${fileId}</span></div></div>`; document.querySelector(".memos-image-list").insertAdjacentHTML('afterbegin', imageList); cocoMessage.success( '上传成功', ()=>{ memosResourceListNow.push(res.id); window.localStorage && window.localStorage.setItem("memos-resource-list", JSON.stringify(memosResourceListNow)); this._imageListDrag() }) } };
_hasMemosOpenId() { if (!this.memosOpenId) { this.memosEditorOption.classList.remove("d-none"); cocoMessage.info('请设置 Access Tokens'); }else{ if (!this.memosPath.endsWith('/')) { this.memosPath += '/'; } let tagUrl = `${this.memosPath}api/v1/tag`; if(this.nowV1 == 'memos'){ var filter = "?filter=" + encodeURIComponent(`creator == 'users/${this.memosMeID}'`); tagUrl = this.memosPath+'api/v1/memos/-/tags' + filter; } const response = fetch(tagUrl,{ method: 'GET', headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json' } }).then(resdata => resdata.json()).then(response => { let taglist = ""; if(this.nowV1 == 'memos'){ Object.keys(response.tagAmounts).map((t)=>{ this.nowTagList += `${t},`; taglist += `<div class="memos-tag d-flex text-xs mt-2 mr-2 px-2" onclick="window.memosbbs._setMemoTag(this)">#${t}</div>`; }) }else{ response.map((t)=>{ this.nowTagList += `${t},`; taglist += `<div class="memos-tag d-flex text-xs mt-2 mr-2 px-2" onclick="window.memosbbs._setMemoTag(this)">#${t}</div>`; }) } document.querySelector(".memos-tag-list").innerHTML = taglist; //cocoMessage.success('准备就绪'); this.memosEditorInner.classList.remove("d-none"); this.memosEditorOption.classList.add("d-none"); this.memosRadomCont.innerHTML = ''; this.memosRadomCont.classList.remove("d-none"); }).catch(err => { this.memosEditorOption.classList.remove("d-none"); cocoMessage.error('Access Tokens 有误,请重新输入!'); }); } }
_random(a,b) { let choices = b - a + 1; return Math.floor(Math.random() * choices + a); }
async _getMemosData(p,t) { if (p.length > 0 && !p.endsWith('/')) { p += '/'; } try { let response; if(this.nowV1 == 'memos'){ response = await fetch(`${p}api/v1/auth/status`,{ async: true, crossDomain: true, method: 'POST', headers: { 'Authorization': `Bearer ${t}` } }); }else{ response = await fetch(`${p}api/v1/user/me`,{ method: 'GET', headers: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' } }); } if (response.ok) { let resdata = await response.json(); if (resdata) { this.memosMeID = resdata.id; this.memosMeNickname = resdata.nickname || resdata.username ; this.memosMeAvatarUrl = resdata.avatarUrl || "https://memobbs.app/pwa/48.png"; window.localStorage && window.localStorage.setItem("memos-access-path", p); window.localStorage && window.localStorage.setItem("memos-access-token", t); window.localStorage && window.localStorage.setItem("memos-visibility-select","PUBLIC"); window.localStorage && window.localStorage.setItem("memos-me-id", this.memosMeID); window.localStorage && window.localStorage.setItem("memos-me-nickname", this.memosMeNickname); window.localStorage && window.localStorage.setItem("memos-me-avatarurl", this.memosMeAvatarUrl); cocoMessage.success('保存成功', () => { this.memosPath = window.localStorage && window.localStorage.getItem("memos-access-path"); this.memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token"); window.location.reload(); //this._getUserMemos(this.memosPath,this.memosMeID,this.memosMeNickname,this.memosMeNickname,"") this._hasMemosOpenId(); }); } } else { cocoMessage.error('出错了,再检查一下吧!'); } } catch (error) { cocoMessage.error('出错了,再检查一下吧!'); } }
_insertValue(text,wrap,back) { this.memosTextarea.focus(); const start = this.memosTextarea.selectionStart; const end = this.memosTextarea.selectionEnd; const selectedText = this.memosTextarea.value.substring(start, end); if(selectedText == ""){ this.memosTextarea.value = this.memosTextarea.value.substring(0, start) + text + this.memosTextarea.value.substring(end); this.memosTextarea.selectionStart = start + text.length - back; this.memosTextarea.selectionEnd = start + text.length - back; }else{ let wrapSelText; if( wrap == "`" ){ wrapSelText = " `" + selectedText + "` "; back = 0; } if( wrap == "[" ){ wrapSelText = " [" + selectedText + "]() "; } if( wrap == "!" ){ wrapSelText = " ![" + selectedText + "]() "; } const newText = this.memosTextarea.value.substring(0, start) + wrapSelText + this.memosTextarea.value.substring(end); this.memosTextarea.value = newText; this.memosTextarea.selectionStart = start + wrapSelText.length - back; this.memosTextarea.selectionEnd = end + wrapSelText.length - back - selectedText.length; } } _deleteImage(e){ if(e){ let memoId = e.getAttribute("data-id") let memosResource = window.localStorage && JSON.parse(window.localStorage.getItem("memos-resource-list")); let memosResourceList = memosResource.filter((item) => { return item != memoId}); window.localStorage && window.localStorage.setItem("memos-resource-list", JSON.stringify(memosResourceList)); e.remove() } } _imageListDrag(){// 获取包含所有图像元素的父元素 const imageList = document.querySelector('.memos-image-list'); // 存储被拖动的元素 let draggedItem = null; let memosResourceList; // 为每个图像元素添加拖动事件监听器 imageList.querySelectorAll('.imagelist-item').forEach(item => { item.draggable = true; // 当拖动开始时 item.addEventListener('dragstart', (e) => { // 存储被拖动的元素 draggedItem = this; memosResourceList = []; }); // 当拖动元素进入目标区域时 item.addEventListener('dragover', (e) => { e.preventDefault(); // 阻止默认行为 this.classList.add('dragover'); // 添加拖动进入样式 }); // 当拖动元素离开目标区域时 item.addEventListener('dragleave', () => { this.classList.remove('dragover'); // 移除拖动进入样式 }); // 当拖动元素放置到目标区域时 item.addEventListener('drop', (e) => { e.preventDefault(); // 阻止默认行为 this.classList.remove('dragover'); // 移除拖动进入样式 // 计算拖动元素中心点 const rect = this.getBoundingClientRect(); const centerX = rect.left + rect.width / 2; // 判断鼠标相对中心点的位置 const isLeft = e.clientX < centerX; if (isLeft) { // 插入到前一个元素前 this.parentNode.insertBefore(draggedItem, this.previousElementSibling); } else { // 插入到后一个元素后 this.parentNode.insertBefore(draggedItem, this.nextElementSibling); } document.querySelectorAll('.memos-image-list .imagelist-item').forEach((item) => { let itemId = Number(item.dataset.id) memosResourceList.push(itemId); }) window.localStorage && window.localStorage.setItem("memos-resource-list", JSON.stringify(memosResourceList)); }); }); } _clearTextarea(mode){ if (!this.editMemoDom.classList.contains("d-none")) { window.localStorage && window.localStorage.removeItem("memos-editor-dataform"); this.editMemoDom.classList.add("d-none"); this.submitMemoBtn.classList.remove("d-none"); } this.submitMemoBtn.classList.remove("noclick"); document.querySelector(".memos-image-list").innerHTML = ''; window.localStorage && window.localStorage.removeItem("memos-resource-list"); window.localStorage && window.localStorage.removeItem("memos-relation-list"); this.memosTextarea = document.querySelector(".memos-editor-textarea") this.memosTextarea.value = ''; this.memosTextarea.style.height = 'inherit'; this.memosMode = mode || window.localStorage && window.localStorage.getItem("memos-mode"); if(this.memosMode != "cancel"){ this._getUserMemos(this.nowLink,this.nowId,this.nowName,this.nowAvatar,"","",this.memosMode) } }
// 显示表情选择器 _displayEmojiSelector() { if (!this.emojiSelector) { this.emojiSelector = document.createElement('div'); this.emojiSelector.classList.add('emoji-selector'); this.emojiSelector.addEventListener('click', (event) => { const target = event.target; if (target.classList.contains('emoji-item')) { this._insertEmoji(target.innerHTML); } }); } this.emojiSelector.innerHTML = ''; this.emojis.forEach(emoji => { const emojiItem = document.createElement('div'); emojiItem.classList.add('emoji-item'); emojiItem.innerHTML = emoji.icon; emojiItem.title = emoji.text; this.emojiSelector.appendChild(emojiItem); }); const memosEditorTools = document.querySelector(".memos-editor-tools"); if (memosEditorTools) { memosEditorTools.insertAdjacentElement('afterend', this.emojiSelector); } } // 表情光标位置 _insertEmoji(emojiText) { const selectionStart = this.memosTextarea.selectionStart; const newValue = `${this.memosTextarea.value.substring(0, selectionStart)}${emojiText}${this.memosTextarea.value.substring(this.memosTextarea.selectionEnd)}`; this.memosTextarea.value = newValue; this.memosTextarea.dispatchEvent(new Event('input')); const newCursorPosition = selectionStart + emojiText.length; this.memosTextarea.setSelectionRange(newCursorPosition, newCursorPosition); this.memosTextarea.focus(); } // 回到顶部 _backToTop() { let BackTop = document.querySelector(".backtop") document.onscroll = () => { let iRollingLength = document.documentElement.scrollTop if(iRollingLength > 300){ BackTop.classList.add("d-md-flex") }else{ BackTop.classList.remove("d-md-flex") } } BackTop.onclick = () => { document.body.scrollIntoView({behavior: 'smooth'}) }; } _geminiAI(e){ let AIMode = e.innerText; let textOld = this.memosTextarea.value; let memosContent; if(!textOld){ cocoMessage.info('内容不能为空'); return } if(AIMode == "语音润色"){ this.memosTextarea.value = `${textOld}\n---\n` memosContent = `请用简洁明了的语言,编辑以下段落,以改善其逻辑流程,消除任何印刷错误。请务必保持文章的原意,禁止回答解释文字里的问题,只返回编辑后的文字,以简体中文回复。请从编辑以下文字开始:[${textOld}]` }else if(AIMode == "自动标签"){ memosContent = `分析这段文本内容:[${textOld}],从这些标签列表中: ["${this.nowTagList}"] 尝试找出1个最适合的标签,并"#TAG "的形式反馈给我` }else if(AIMode == "智囊团队"){ this.memosTextarea.value = `${textOld}\n---\n` memosContent = `你是我的智囊团,团内有 6 个不同的董事作为教练,分别是乔布斯、伊隆马斯克、马云、柏拉图、维达利和慧能大师。他们都有自己的个性、世界观、价值观,对问题有不同的看法、建议和意见。我会在这里说出我的处境和我的决策。先分别以这 6 个身份,以他们的视角来审视我的决策,给出他们的批评和建议,我的第一个处境是 [${textOld}]` }else if(AIMode == "育儿帮手"){ this.memosTextarea.value = `${textOld}\n---\n` memosContent = `As an expert in child development, you are tasked with answering various imaginative questions from children between the ages of 5 and 10, as if you were a kindergarten teacher. Your responses should be lively, patient, and friendly in tone and manner, and as concrete and understandable as possible, avoiding complex or abstract vocabulary. Use metaphors and examples whenever possible, and extend your answers to cover more scenarios, not just explaining why, but also suggesting concrete actions to deepen understanding. Respond in Chinese.My first questions: [${textOld}]` }else if(AIMode == "智能问答"){ this.memosTextarea.value = `${textOld}\n---\n` memosContent = `${textOld}` } this.geminiAIBtn.classList.add("d-none","noclick") this.geminiAILoadBtn.classList.remove("d-none") this._sendToGemini(memosContent) }; //"https: async _sendToGemini(memosContent) { const res = await fetch(this.GeminiFetch, { headers: { 'Authorization': `Bearer ${this.geminiKey}`, 'Content-Type': 'application/json' }, method: 'POST', body: JSON.stringify({ model: 'gemini-pro', messages: [{ role: 'user', content: memosContent }], temperature: 0.7, stream: true }) }) if(!res.ok){ setTimeout(() => { this.geminiAIBtn.classList.remove("d-none","noclick") this.geminiAILoadBtn.classList.add("d-none") cocoMessage.error("出错咯,稍后再试") }, 1000); } const reader = res.body.getReader() while(true) { const {value, done} = await reader.read() if (done) { this.geminiAIBtn.classList.remove("d-none","noclick") this.geminiAILoadBtn.classList.add("d-none") break } const text = new TextDecoder().decode(value) const match = text.match(/DONE/) if(!match){ const textJson = JSON.parse(text.substring(5)) const resData = textJson.choices[0].delta.content if(resData.length > 0){ this.memosTextarea.value += resData this.memosTextarea.style.height = this.memosTextarea.scrollHeight + 'px'; } } } } async _getMemosForAI() { let fetchUrl = `${this.nowLink}api/v1/memo?creatorId=${this.nowId}&limit=100` let response = await fetch(fetchUrl,{ headers: { 'Authorization': `Bearer ${this.memosOpenId}`, 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', }, cache: 'no-store', }); if (!response.ok) { throw new Error(`Request failed oneDay`); } let originalArray = await response.json() const filteredArray = originalArray.map(item => { return { id: item.id, content: item.content }; }); return JSON.stringify(filteredArray).substring(0, 30000); } }
class MemosElement extends HTMLElement { connectedCallback() { window.memosbbs = new MemosBbs(); } disconnectedCallback() { delete window.memosbbs; } }
if (window.customElements && !window.customElements.get('memos-bbs')) { window.MemosElement = MemosElement window.customElements.define('memos-bbs', MemosElement) }
|