Spaces:
Running
Running
File size: 112,995 Bytes
cabd7e6 395a975 cabd7e6 395a975 cabd7e6 35e8599 fcab9ad cabd7e6 676d28d c43506f 35e8599 395a975 35e8599 474474d 395a975 42b75a8 474474d 395a975 cabd7e6 474474d cabd7e6 474474d 395a975 474474d cabd7e6 395a975 cabd7e6 474474d cabd7e6 474474d f561d4d cabd7e6 395a975 c43506f f561d4d 42b75a8 474474d a4898fa 474474d a4898fa 474474d d6d1e62 474474d a4898fa cabd7e6 474474d 49cd608 16ae0cf 474474d 395a975 35e8599 474474d a4898fa 35e8599 a4898fa f561d4d a4898fa 35e8599 a4898fa 474474d a4898fa 474474d 35e8599 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 35e8599 40c75f3 cabd7e6 474474d cabd7e6 35e8599 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 35e8599 395a975 35e8599 395a975 204e009 f4c1cc5 204e009 395a975 204e009 395a975 cabd7e6 395a975 9e44986 395a975 9e44986 7572315 9e44986 395a975 9e44986 395a975 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 cabd7e6 214046a cabd7e6 214046a cabd7e6 474474d a4898fa 214046a 395a975 5fc2029 a4898fa cabd7e6 a4898fa 474474d cabd7e6 395a975 f4c1cc5 cabd7e6 474474d cabd7e6 474474d cabd7e6 474474d a4898fa fcab9ad a4898fa cabd7e6 a4898fa 474474d cabd7e6 fcab9ad cabd7e6 40c75f3 cabd7e6 40c75f3 cabd7e6 40c75f3 cabd7e6 40c75f3 cabd7e6 40c75f3 cabd7e6 40c75f3 cabd7e6 474474d cabd7e6 474474d cabd7e6 395a975 cabd7e6 395a975 cabd7e6 395a975 474474d 395a975 474474d 395a975 474474d 395a975 214046a 395a975 214046a 395a975 214046a 395a975 214046a c43506f 474474d 395a975 474474d 395a975 cabd7e6 204e009 cabd7e6 204e009 474474d 214046a cabd7e6 474474d cabd7e6 214046a cabd7e6 204e009 cabd7e6 7572315 9e44986 cabd7e6 9e44986 cabd7e6 9e44986 cabd7e6 f4c1cc5 cabd7e6 f561d4d 5fc2029 f561d4d 5fc2029 f561d4d cabd7e6 f561d4d cabd7e6 204e009 395a975 204e009 395a975 204e009 cabd7e6 474474d cabd7e6 474474d cabd7e6 9e44986 cabd7e6 474474d cabd7e6 474474d cabd7e6 9e44986 cabd7e6 474474d cabd7e6 474474d cabd7e6 9e44986 cabd7e6 204e009 cabd7e6 204e009 f4c1cc5 204e009 cabd7e6 f4c1cc5 cabd7e6 fcab9ad cabd7e6 fcab9ad 204e009 fcab9ad 204e009 fcab9ad 204e009 fcab9ad 42b75a8 fcab9ad 42b75a8 fcab9ad 42b75a8 fcab9ad 42b75a8 fcab9ad 204e009 fcab9ad 204e009 fcab9ad 204e009 fcab9ad 204e009 c68f502 fcab9ad cabd7e6 204e009 cabd7e6 35e8599 a4898fa 474474d a4898fa 474474d fcab9ad a4898fa cabd7e6 474474d 35e8599 204e009 16ae0cf 35e8599 204e009 16ae0cf f561d4d 35e8599 cabd7e6 35e8599 cabd7e6 474474d cabd7e6 474474d cabd7e6 474474d cabd7e6 214046a cabd7e6 214046a cabd7e6 214046a cabd7e6 214046a cabd7e6 214046a cabd7e6 474474d 214046a 474474d a4898fa 214046a a4898fa e92667d 474474d 214046a 474474d cabd7e6 474474d cabd7e6 474474d a4898fa 214046a a4898fa 214046a 42b75a8 a4898fa 214046a a4898fa cabd7e6 474474d a4898fa cabd7e6 a4898fa 474474d cabd7e6 474474d a4898fa 474474d a4898fa cabd7e6 214046a cabd7e6 40c75f3 cabd7e6 40c75f3 cabd7e6 40c75f3 cabd7e6 40c75f3 204e009 40c75f3 204e009 40c75f3 cabd7e6 35e8599 cabd7e6 35e8599 89f2ef2 fcab9ad 42b75a8 cabd7e6 0b20068 cabd7e6 e5f6923 204e009 cabd7e6 474474d 0b20068 204e009 cabd7e6 474474d cabd7e6 204e009 42b75a8 204e009 395a975 cabd7e6 395a975 d482631 7572315 395a975 7572315 395a975 7572315 395a975 7572315 cabd7e6 395a975 cabd7e6 c43506f 676d28d 395a975 676d28d c43506f 42b75a8 676d28d f4c1cc5 676d28d c43506f fcab9ad c43506f fcab9ad c43506f fcab9ad c43506f 35e8599 474474d a4898fa 35e8599 02fb1eb 35e8599 02fb1eb d6d1e62 204e009 d6d1e62 35e8599 02fb1eb 35e8599 204e009 35e8599 204e009 35e8599 474474d 35e8599 474474d a4898fa 35e8599 474474d a4898fa 474474d 35e8599 474474d 35e8599 474474d a4898fa 474474d a4898fa 35e8599 474474d 42b75a8 395a975 42b75a8 474474d fcab9ad bb43957 fcab9ad 204e009 fcab9ad 89f2ef2 cabd7e6 395a975 204e009 cabd7e6 395a975 cabd7e6 204e009 cabd7e6 395a975 cabd7e6 9e44986 395a975 9e44986 f561d4d cabd7e6 f4c1cc5 f561d4d f4c1cc5 cabd7e6 fcab9ad 02fb1eb fcab9ad cabd7e6 fcab9ad cabd7e6 204e009 fcab9ad cabd7e6 fcab9ad cabd7e6 fcab9ad cabd7e6 fcab9ad bb43957 c68f502 bb43957 fcab9ad cabd7e6 204e009 35e8599 cabd7e6 35e8599 cabd7e6 35e8599 fcab9ad cabd7e6 fcab9ad 89f2ef2 cabd7e6 f561d4d cabd7e6 f561d4d cabd7e6 395a975 f561d4d 395a975 676d28d cabd7e6 214046a cabd7e6 89f2ef2 cabd7e6 c43506f 395a975 c43506f cabd7e6 395a975 cabd7e6 35e8599 395a975 f561d4d 395a975 cabd7e6 42b75a8 cabd7e6 35e8599 f561d4d 35e8599 cabd7e6 89f2ef2 676d28d 42b75a8 395a975 42b75a8 395a975 474474d |
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 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 |
//
//
//
//
// global variables
var p1 = performance.now();
var timer;
var artTypes = ['🎨','🧑','🏞️'];
var artTitles = ['artwork','portraits','landscapes'];
var models = [
// path, short display name, full display name
['SDXL_1_0','SDXL 1.0','SDXL 1.0 Stability.ai official'],
['SDXL_DynaVision','XL DynaVision','SDXL DynaVision beta v0.4.1.1'],
['SDXL_Crystal_Clear','XL CrystalClr','Crystal Clear XL vCCXL'],
];
var secondModelIsSelected = false;
var secondModelSelected = 1;
var initialPosX = -1;
var initialPosY = -1;
var prevScrollTop = -1; // used for lazyLoad
var newPosX = -1;
var newPosY = -1;
var imgTypeShown = 0;
var log = '';
var editMostUsedMode = false;
var informationMode = false;
var windowWidth = 0;
var gutterStartPosX, mouseStartPosX, gutterEndPercentX
var style, tempStyle, stylesheet, tempStylesheet, imgHoverRule, teaseRules;
var theTime = new Date;
var startUpTime;
var tagsConcatenated = new Set();
var tagCountsPermissive = [];
var editedArtists = new Set();
var storingAccessType = 'none';
var missingFiles = '';
// the longer prompt is better for non-photographers
var promptStyleWords = ['artwork in the style of','by|||']
const lowCountThreshold = 3;
const unloadedImgSrc = 'data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAkA4JaQAA3AA/vgfgAA='; // a 1x1 pixel
const maxAristsToBeLoaded = 50; // each artist has 6 images, 3 per model
const artistLoadingChunk = 15; // artists loaded per lazy load call
const missingInterval = setInterval(checkMissingInterval, 5000);
var imageItemUnloadQueue = [];
//
//
//
// wait for DOM
document.addEventListener("DOMContentLoaded", function() {
checkStoringAccessType().then(state => {
startUp();
});
startUpTime = theTime.getTime();
});
// functions
async function startUp() {
makeConcatenatedTagSet();
await loadEditedArtists();
insertArtists();
insertModels();
insertCheckboxesFromArtistsData();
insertCheckboxesFromCategories();
await loadCheckboxesState();
showHideCategories();
await loadOptionsState();
await loadFavoritesState();
blurUnblurNudity();
hideAllArtists();
unhideBasedOnPermissiveSetting();
sortArtists();
rotatePromptsImages();
updateArtistsImgSrc(false,false);
updateTags('start');
makeStyleRuleForDrag();
// teasePartition();
promptBuilderAddArtist(true);
updatePromptBuilderParts();
addAllListeners();
}
function checkStoringAccessType() {
return new Promise((resolve, reject) => {
try {
localStorage.setItem('testKey', 'testValue');
localStorage.removeItem('testKey');
storingAccessType = 'localStorage';
console.log('all settings saved using localStorage');
resolve();
} catch (error) {
return caches.open('testCache')
.then(cache => {
const blob = new Blob([JSON.stringify('test')], { type: 'application/json' });
const responseToCache = new Response(blob);
cache.put('testCache', responseToCache).then(response => {
storingAccessType = 'dataCache';
console.log('all settings saved using dataCache');
return;
})
.catch(error => {
console.warn('no settings can be saved; we only have read access to cache: ' + error);
resolve();
});
})
.catch(error => {
console.warn('no settings can be saved; no access to any storage method: ' + error);
resolve();
});
}
}).catch(error => {
console.warn('had error writing to localStorage: ', error);
});
}
function loadItemBasedOnAccessType(item) {
if(storingAccessType == 'localStorage') {
return new Promise((resolve, reject) => {
try {
const state = JSON.parse(localStorage.getItem(item));
resolve(state || {});
} catch (error) {
reject(error);
}
}).catch(error => {
console.warn(item + ' had error loading from localStorage: ', error);
return {};
});
} else if(storingAccessType == 'dataCache') {
return caches.open('dataCache')
.then(cache => {
return cache.match(item);
})
.then(response => {
if(response) {
return response.json();
}
return {};
})
.catch(error => {
console.warn(item + ' had error loading from cache: ', error);
});
} else if(storingAccessType == 'none') {
return Promise.resolve({});
}
}
function storeItemBasedOnAccessType(item, stateArray, key, value) {
if(storingAccessType == 'localStorage') {
try {
if(stateArray) {
localStorage.setItem(item, JSON.stringify(stateArray));
} else {
let state = JSON.parse(localStorage.getItem(item)) || {};
state[key] = value;
localStorage.setItem(item, JSON.stringify(state));
}
} catch (error) {
console.warn(item + ' had error saving localStorage: ', error);
}
} else if(storingAccessType = 'dataCache') {
caches.open('dataCache').then(cache => {
if(stateArray) {
const blob = new Blob([JSON.stringify(stateArray)], { type: 'application/json' });
const responseToCache = new Response(blob);
return cache.put(item, responseToCache);
} else {
// try to get the item state from the cache
cache.match(item).then(response => {
let state = {};
if(response) {
return response.json().then(cachedData => {
state = cachedData || {};
return state;
});
} else {
return state;
}
}).then(state => {
state[key] = value;
// store the updated state back to the cache
const blob = new Blob([JSON.stringify(state)], { type: 'application/json' });
const responseToCache = new Response(blob);
return cache.put(item, responseToCache);
});
}
}).catch(error => {
console.warn(item + ' had error saving to cache: ', error);
});
} else if(storingAccessType == 'none') {
alertNoStoringAccess(0);
}
}
async function deleteItemBasedOnAccessType(item) {
if(storingAccessType == 'localStorage') {
localStorage.removeItem(item);
} else if(storingAccessType = 'dataCache') {
await caches.delete(item);
} else if(storingAccessType == 'none') {
// nothing to do
}
}
function alertNoStoringAccess(wait) {
window.setTimeout(function(){
let msg = '';
msg += 'My apologies, your browser settings block the ability to save settings and favorites. Suggestions:\n';
msg += '1. Try Firefox, Safari, or Edge\n'
msg += '2. Download the app to use offline\n';
msg += '3. On Chrome, enable 3rd-party cookies (not recommended)\n\n';
msg += 'This app doesn\'t use cookies, never sends data to any server, and saves all data locally. But since this app is hosted on Hugging Face, Chrome treats it as a "3rd-party". Other browsers give you more nuanced control of your privacy settings.';
alert(msg);
},wait);
}
function makeConcatenatedTagSet() {
// this set is used for tag editing mode
for (var i=0, il=tagCategories.length; i<il; i++) {
for (var j=1, jl=tagCategories[i].length; j<jl; j++) {
// j=1 because we don't want to include the category name
// we also exclude tags that have the in the format of "added-YYYY-MM-DD"
let tag = tagCategories[i][j].replace(/, added-(\d|-)*/g,'');
tagsConcatenated.add(tag);
}
}
let tagsConcatenatedArray = Array.from(tagsConcatenated).sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
tagsConcatenated = new Set(tagsConcatenatedArray);
}
async function loadEditedArtists() {
await loadItemBasedOnAccessType('editedArtists').then(state => {
editedArtists = new Set(Array.from(state));
let proto = window.location.protocol;
let anyChanges = false;
for (let i=0, il=artistsData.length; i<il; i++) {
// find match in artistsData if first and last names match
let artist = artistsData[i];
let artistFound = Array.from(editedArtists).find(editedA => editedA[0] === artist[0] && editedA[1] === artist[1]);
if(artistFound) {
// check if the edit now matches the original
let match = true;
for (let j=0, jl=artist.length; j<jl; j++) {
if (artist[j] !== artistFound[j]) {
match = false;
}
}
if(match) {
anyChanges = true;
editedArtists.delete(artistFound);
} else {
if (!proto.startsWith('http')) {
// if this is a local file, then update artistsData with the saved edits
artistsData[i] = artistFound;
}
}
}
}
if(anyChanges) {
storeItemBasedOnAccessType('editedArtists',editedArtists,false,false);
}
});
}
function insertArtists() {
let container = document.getElementById('image-container');
// artistsData is defined in the artists_and_tags.js file
for(i=0, il=artistsData.length; i<il; i++) {
var artist = artistsData[i];
var last = artist[0];
var first = artist[1];
var tags2 = artist[2].replaceAll('|', ', '); // for display
// artists can have a tag in the format of "added-YYYY-MM"
// we want that to show up as a filter, but not on the artist card
tags2 = tags2.replace(/, added-(\d|-)*/g,'');
var itemDiv = document.createElement('div');
itemDiv.className = 'image-item';
itemDiv.dataset.tagList = artist[2].toLowerCase();
var itemHeader = document.createElement('span');
var h3 = document.createElement('h3');
itemHeader.appendChild(h3);
var firstN = document.createElement('span');
var lastN = document.createElement('span');
firstN.className = 'firstN';
lastN.className = 'lastN';
firstN.textContent = `${first}`;
lastN.textContent = `${last}`;
h3.appendChild(firstN);
h3.appendChild(lastN);
h3.title = 'copy to clipboard';
var h4 = document.createElement('h4');
h4.textContent = tags2;
h4.title = 'copy to clipboard';
itemHeader.appendChild(h4);
itemDiv.appendChild(itemHeader);
//
var holder = document.createElement('div');
var imgTools = document.createElement('div');
imgTools.className = 'imgTools';
//
var artPrev = document.createElement('div');
artPrev.className = 'art_prev';
var artPrevSpan = document.createElement('span');
artPrevSpan.textContent = '🎨';
artPrevSpan.title = 'showing artwork'
artPrev.appendChild(artPrevSpan);
imgTools.appendChild(artPrev);
//
var artStar = document.createElement('div');
artStar.className = 'art_star';
var artStarSpan = document.createElement('span');
artStarSpan.textContent = '⭐️';
artStarSpan.title = 'toggle favorite';
artStar.appendChild(artStarSpan);
imgTools.appendChild(artStar);
//
var artNext = document.createElement('div');
artNext.className = 'art_next';
var artNextSpan = document.createElement('span');
artNextSpan.textContent = '🎨';
artNextSpan.title = 'showing artwork';
artNext.appendChild(artNextSpan);
imgTools.appendChild(artNext);
//
var artEdit = document.createElement('div');
artEdit.className = 'art_edit';
var artEditSpan = document.createElement('span');
artEditSpan.textContent = '✍️';
artEditSpan.title = 'toggle tag edit mode';
artEdit.appendChild(artEditSpan);
imgTools.appendChild(artEdit);
//
var artSearch = document.createElement('a');
artSearch.className = 'art_search';
artSearch.href = 'https://www.bing.com/images/search?q=' + artist[1].replace(' ','+') + '+' + artist[0].replace(' ','+') + '+artist';
artSearch.target = '_blank';
artSearch.title = 'Bing image search';
var artSearchSpan = document.createElement('span');
artSearchSpan.textContent = '🌐';
artSearch.appendChild(artSearchSpan);
imgTools.appendChild(artSearch);
//
var artSet = document.createElement('div');
artSet.className = 'art_set';
var artSetSpan = document.createElement('span');
artSetSpan.textContent = 'A: ' + models[0][1];
artSetSpan.title = 'showing ' + models[0][2];
artSet.appendChild(artSetSpan);
imgTools.appendChild(artSet);
//
holder.appendChild(imgTools);
var imgBox0 = document.createElement('div');
imgBox0.className = 'imgBox';
imgBox0.dataset.model = 0;
var imgArtwork = document.createElement('img');
var imgPortrait = document.createElement('img');
var imgLandscape = document.createElement('img');
var modelName = document.createElement('span');
imgArtwork.className = 'img img_artwork';
imgPortrait.className = 'img img_portrait hidden';
imgLandscape.className = 'img img_landscape hidden';
modelName.className = 'img model_name hidden';
imgArtwork.src = unloadedImgSrc;
imgPortrait.src = unloadedImgSrc;
imgLandscape.src = unloadedImgSrc;
imgBox0.appendChild(imgArtwork);
imgBox0.appendChild(imgPortrait);
imgBox0.appendChild(imgLandscape);
let modelNameSpan = document.createElement('span');
modelNameSpan.appendChild(document.createElement('strong'));
modelNameSpan.querySelector('strong').appendChild(document.createTextNode('Model:'));
modelNameSpan.appendChild(document.createElement('br'));
modelNameSpan.appendChild(document.createTextNode(models[0][2]));
modelName.appendChild(modelNameSpan);
imgBox0.appendChild(modelName);
holder.appendChild(imgBox0);
//
let imgBox1 = imgBox0.cloneNode(true);
imgBox1.classList.add('hidden');
imgBox1.dataset.model = 1;
imgBox1.querySelector('.model_name span').childNodes[2].nodeValue = models[secondModelSelected][2];
holder.appendChild(imgBox1);
//
if(artist[3]) {
itemDiv.dataset.deprecated = true;
var deprecatedSpan = document.createElement('span');
deprecatedSpan.textContent = 'this artist is unknown to SDXL - more info in the help ⁉️'
deprecatedSpan.className = 'deprecated';
imgBox0.appendChild(deprecatedSpan);
}
//
itemDiv.appendChild(holder);
container.appendChild(itemDiv);
}
}
function getArtistsByDistanceFromMiddle() {
// visible artists based on the distance from the center with current scroll
// sort these to the top add add non-deprecated hidden artists after that
let imageItemsVisible = Array.from(document.querySelectorAll('.image-item:not(.hidden)'));
let artistsAreaCenter = (document.getElementById('rows').clientHeight / 2) - 300;
let middleItem = null;
for (let item of imageItemsVisible) {
// get rect!
let rect = item.getBoundingClientRect();
if (rect.top > artistsAreaCenter) {
if (!middleItem || middleItem.getBoundingClientRect().top > rect.bottom) {
middleItem = item;
}
}
}
if(middleItem !== null) {
let middleItemTop = middleItem.getBoundingClientRect().top;
imageItemsVisible.sort((a, b) => {
let aY = a.getBoundingClientRect().top;
let bY = b.getBoundingClientRect().top;
return Math.abs(aY - middleItemTop) - Math.abs(bY - middleItemTop);
});
}
return imageItemsVisible;
}
function updateArtistsImgSrc(filteredImageItems,onlySecondModel) {
if(filteredImageItems == false) {
// initial page load
filteredImageItems = getArtistsByDistanceFromMiddle();
let imageItemsHidden = Array.from(document.querySelectorAll('.image-item.hidden'))
.filter(item => !item.dataset.deprecated);
// if not enough visible artists, load hidden, unloaded, non-deprecated artists
filteredImageItems = filteredImageItems.concat(imageItemsHidden).slice(0, maxAristsToBeLoaded);
}
// load those artists (update the image src)
let imagePromises = [];
filteredImageItems.forEach(function(item){
let src0 = 'images/' + models[0][0] + '_thumbs/';
let src1 = 'images/' + models[secondModelSelected][0] + '_thumbs/';
let firstN = item.querySelector('.firstN').textContent;
let lastN = item.querySelector('.lastN').textContent;
// files use accented characters and huggingface stores the files with this encoding
src0 = encodeURI(src0.normalize("NFD"));
src1 = encodeURI(src1.normalize("NFD"));
if(firstN == '') {
src0 += lastN.replaceAll(' ', '_');
src1 += lastN.replaceAll(' ', '_');
} else {
src0 += firstN.replaceAll(' ', '_') + '_' + lastN.replaceAll(' ', '_');
src1 += firstN.replaceAll(' ', '_') + '_' + lastN.replaceAll(' ', '_');
}
//
let imgAlt0 = 'artist: ' + firstN + ' ' + lastN + ' - model: ' + models[0][1];
let imgAlt1 = 'artist: ' +firstN + ' ' + lastN + ' - model: ' + models[secondModelSelected][1];
//
let imgBox0 = item.querySelector('.imgBox[data-model="0"]');
let imgBox1 = item.querySelector('.imgBox[data-model="1"]');
delete imgBox1.querySelector('.img_artwork').dataset.thumbSrc;
delete imgBox1.querySelector('.img_portrait').dataset.thumbSrc;
delete imgBox1.querySelector('.img_landscape').dataset.thumbSrc;
let imgArray = [];
if(!onlySecondModel) {
imgArray.push([imgBox0.querySelector('.img_artwork'), src0 + '-artwork.webp', imgAlt0 + ' - prompt: artwork']);
imgArray.push([imgBox0.querySelector('.img_portrait'), src0 + '-portrait.webp', imgAlt0 + ' - prompt: portrait']);
imgArray.push([imgBox0.querySelector('.img_landscape'), src0 + '-landscape.webp', imgAlt0 + ' - prompt: landscape']);
}
imgArray.push([imgBox1.querySelector('.img_artwork'), src1 + '-artwork.webp', imgAlt1 + ' - prompt: artwork']);
imgArray.push([imgBox1.querySelector('.img_portrait'), src1 + '-portrait.webp', imgAlt1 + ' - prompt: portrait']);
imgArray.push([imgBox1.querySelector('.img_landscape'), src1 + '-landscape.webp', imgAlt1 + ' - prompt: landscape']);
//
generateUnloadQueue();
imgArray.forEach(function(imgDetails) {
let p = new Promise((resolve, reject) => {
imgDetails[0].src = imgDetails[1];
imgDetails[0].alt = imgDetails[2];
if(imgDetails[0].complete) {
if(imgDetails[0].classList.contains('img_artwork') &&
imgDetails[0].closest('.imgBox').dataset.model == '0') {
lazyUnloadOne();
}
resolve();
return;
}
imgDetails[0].onload = (img) => {
if(imgDetails[0].classList.contains('img_artwork') &&
imgDetails[0].closest('.imgBox').dataset.model == '0') {
lazyUnloadOne();
}
imgDetails[0].onload = null;
imgDetails[0].onerror = null;
resolve();
};
imgDetails[0].onerror = (img) => {
missingFiles += imgDetails[1] + '\n';
imgDetails[0].onload = null;
imgDetails[0].onerror = null;
reject(new Error('Image loading error'));
};
});
imagePromises.push(p);
});
});
Promise.allSettled(imagePromises).then(() => {
});
}
function lazyLoad() {
let container = document.getElementById('rows');
let currentScrollTop = container.scrollTop;
if(prevScrollTop == -1) {
// this skips the scroll that's triggered on page load
prevScrollTop = currentScrollTop;
return;
}
let scrollDirection = currentScrollTop > prevScrollTop ? 'down' : 'up';
let scrollAmount = Math.abs(currentScrollTop - prevScrollTop);
let lookAhead = 750;
if(scrollAmount > lookAhead) {
lookAhead = scrollAmount;
}
let imageItems = Array.from(container.querySelectorAll('.image-item:not(.hidden)'));
// look for any visible unloaded images ahead in either scroll direction by the lookAhead amount
unloadedItemsInRange = imageItems.filter(item => {
let itemMid = item.getBoundingClientRect().top + (item.clientHeight / 2);
let imgSrc = item.querySelector('img').src;
return imgSrc.indexOf(unloadedImgSrc) > -1 &&
itemMid > 0 - lookAhead &&
itemMid < container.clientHeight + lookAhead;
});
if(unloadedItemsInRange.length > 0) {
let itemsToBeLoaded;
// get all unloaded images in the scroll direction, by closest
// it's already sorted top to bottom
if (scrollDirection === 'down') {
itemsToBeLoaded = imageItems.filter(item => {
let itemMid = item.getBoundingClientRect().top + (item.clientHeight / 2);
let imgSrc = item.querySelector('img').src;
return imgSrc.indexOf(unloadedImgSrc) > -1 &&
itemMid + currentScrollTop > currentScrollTop;
});
imageItems.reverse();
} else {
itemsToBeLoaded = imageItems.filter(item => {
let itemMid = item.getBoundingClientRect().top + (item.clientHeight / 2);
let imgSrc = item.querySelector('img').src;
return imgSrc.indexOf(unloadedImgSrc) > -1 &&
itemMid + currentScrollTop < currentScrollTop;
});
itemsToBeLoaded = itemsToBeLoaded.reverse();
}
itemsToBeLoaded = itemsToBeLoaded.slice(0, artistLoadingChunk);
// if we don't have enough in the forward direction work backwards
// for reasons I haven't figured out, sometimes the src update fails
// yet promise.allSettled doesn't fire, so we load up to the max each time
let allLoadedImageItems = Array.from(document.querySelectorAll('.image-item'));
allLoadedImageItems = allLoadedImageItems.filter(item => {
let imgSrc = item.querySelector('img').src;
return imgSrc.indexOf(unloadedImgSrc) == -1;
});
let i = 0;
while(itemsToBeLoaded.length < (maxAristsToBeLoaded - allLoadedImageItems.length)) {
itemsToBeLoaded.push(imageItems[i]);
i++;
}
// slice to a chunk-size and load
updateArtistsImgSrc(itemsToBeLoaded,false);
}
prevScrollTop = currentScrollTop;
}
function generateUnloadQueue() {
// there's no way to predict which artists are best to unload
// so pick a random chunk out of loaded, hidden, non-deprecated artists
let imageItemsHidden = Array.from(document.querySelectorAll('.image-item.hidden:not([data-deprecated="true"]'));
imageItemsHidden = imageItemsHidden.filter(item => {
let imgSrc = item.querySelector('img').src;
return imgSrc.indexOf(unloadedImgSrc) == -1;
});
imageItemsHidden.forEach(function(item) {
item.dataset.randomRank = Math.random();
});
imageItemsHidden.sort(function(a, b) {
var aValue = a.dataset.randomRank;
var bValue = b.dataset.randomRank;
return bValue - aValue;
});
// in case there aren't enough items, add all loaded, visible, non-deprecated artists, with furthest away sorted first
let imageItemsVisible;
imageItemsVisible = getArtistsByDistanceFromMiddle();
imageItemsVisible.reverse();
imageItemsVisible = imageItemsVisible.filter(item => {
let imgSrc = item.querySelector('img').src;
return imgSrc.indexOf(unloadedImgSrc) == -1;
});
imageItemUnloadQueue = imageItemsHidden.concat(imageItemsVisible);
}
function lazyUnloadOne() {
let allLoadedImageItems = Array.from(document.querySelectorAll('.image-item'));
allLoadedImageItems = allLoadedImageItems.filter(item => {
let imgSrc = item.querySelector('img').src;
return imgSrc.indexOf(unloadedImgSrc) == -1;
});
if(allLoadedImageItems.length > maxAristsToBeLoaded) {
let toBeUnloaded = imageItemUnloadQueue[0];
imageItemUnloadQueue.shift();
let images = toBeUnloaded.querySelectorAll('img');
images.forEach(function(img) {
img.src = unloadedImgSrc;
delete img.dataset.thumbSrc;
});
}
}
function insertModels() {
let secondModelSelector = document.querySelector('#second_model select');
secondModelSelector.innerHTML = '';
for (var i=1, il=models.length; i<il; i++) {
// model 0 is the primary model
let model = models[i];
let option = document.createElement('option');
option.value = model[0];
option.textContent = model[1];
secondModelSelector.appendChild(option);
}
}
function setSecondModelSelected(select) {
for(i=0,il=models.length; i<il; i++) {
if(models[i][0] === select.value) {
secondModelSelected = i;
break;
}
}
secondModelIsSelected = false;
rotateModelsImages();
// update images (but only second model)
updateArtistsImgSrc(false,true);
}
function insertCheckboxesFromArtistsData() {
var uniqueTags = new Set();
artistsData.forEach(function(artist) {
var tags = artist[2].split('|');
tags.forEach(function(tag) {
uniqueTags.add(tag.toLowerCase());
});
});
// favorite isn't an artist tag so has to be added
uniqueTags.add('favorite');
var uTags = Array.from(uniqueTags);
var toggles = document.getElementById('toggles');
for(i=0,il=uTags.length;i<il;i++) {
if(uTags[i].length > 0) {
// 👆 shouldn't need to sanitize database, but just in case
var label = document.createElement('label');
var el = document.createElement('i');
el.className = 'most_used_indicator';
el.textContent = '+';
var input = document.createElement('input');
input.type = 'checkbox';
input.name = uTags[i];
input.value = uTags[i];
input.checked = true;
var span1 = document.createElement('span');
span1.textContent = uTags[i];
var span2 = document.createElement('span');
span2.className = 'count';
label.appendChild(el);
label.appendChild(input);
label.appendChild(span1);
label.appendChild(span2);
toggles.appendChild(label);
}
}
// so it can be referenced by CSS
document.querySelector('input[name="favorite"').parentNode.id = "favorite_label";
}
function insertCheckboxesFromCategories() {
for(i=0,il=tagCategories.length;i<il;i++) {
let name = tagCategories[i][0];
var label = document.createElement('label');
label.dataset.categoryName = name;
label.className = 'category';
var input = document.createElement('input');
input.type = 'checkbox';
input.name = name;
input.value = name;
input.checked = true;
var span1 = document.createElement('span');
span1.textContent = name;
var span2 = document.createElement('span');
span2.className = 'count';
label.appendChild(input);
label.appendChild(span1);
label.appendChild(span2);
toggles.appendChild(label);
}
}
async function loadCheckboxesState() {
await loadItemBasedOnAccessType('tagsChecked').then(state => {
let allChecked = true;
for (let name in state) {
let checkbox = document.querySelector('input[name="'+name+'"]');
if (checkbox) {
if(name != 'mode') {
// a past bug allowed permissiveness to be saved
// this ensure it's not loaded
checkbox.checked = state[name];
styleLabelToCheckbox(checkbox);
}
if(name != 'mode'
&& name != 'use_categories'
&& name != 'low_count'
&& name != 'deprecated'
&& name != 'nudity') {
if(!state[name]) {
allChecked = false;
}
}
}
}
if(!allChecked) {
document.querySelector('input[name="check-all"]').checked = false;
}
});
}
function storeCheckboxState(checkbox) {
if(document.querySelector('input[name="mode"]').checked) {
// while in strict mode, don't save selections
if(checkbox.name != 'check-all' && checkbox.name != 'mode') {
storeItemBasedOnAccessType('tagsChecked',false,checkbox.name,checkbox.checked);
}
}
}
function storeCheckboxStateAll(isChecked) {
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
let state = {};
checkboxes.forEach(function(checkbox) {
let isTop = checkbox.parentNode.classList.contains('top_control');
if(!isTop || checkbox.name == 'favorite') {
// is a tag checkbox, not a setting
if(isChecked) {
state[checkbox.name] = true;
} else {
state[checkbox.name] = false;
}
}
});
storeItemBasedOnAccessType('tagsChecked',state,false,false);
}
async function loadOptionsState() {
await loadItemBasedOnAccessType('optionsChecked').then(state => {
if(state['prompt']) {
let optionsPrompts = document.getElementById('options_prompts');
optionsPrompts.querySelectorAll('.selected')[0].classList.remove('selected');
document.getElementById(state['prompt']).classList.add('selected');
if(state['prompt'] == 'promptA') {
imgTypeShown = 0;
} else if(state['prompt'] == 'promptP') {
imgTypeShown = 1;
} else if(state['prompt'] == 'promptL') {
imgTypeShown = 2;
}
} else {
// promptA is already highlighted by HTML
imgTypeShown = 0;
}
if(state['artistSort']) {
document.getElementById('options_artist_sort').querySelectorAll('.selected')[0].classList.remove('selected');
document.getElementById(state['artistSort']).classList.add('selected');
} else {
// sortAR is already highlighted by HTML
}
if(state['tagSort']) {
document.getElementById('options_tag_sort').querySelectorAll('.selected')[0].classList.remove('selected');
document.getElementById(state['tagSort']).classList.add('selected');
} else {
// sortTC is already highlighted by HTML
}
});
}
function highlightSelectedOption(selected) {
if(selected == 'prev' || selected == 'next') {
if(selected == 'prev') {
imgTypeShown--;
if(imgTypeShown < 0) { imgTypeShown = 2; }
} else if(selected == 'next') {
imgTypeShown++;
if(imgTypeShown > 2) { imgTypeShown = 0; }
}
let optionsPrompts = document.getElementById('options_prompts');
var links = optionsPrompts.querySelectorAll('.link');
links.forEach(function(link) {
link.classList.remove('selected');
});
if(imgTypeShown == 0) {
document.getElementById('promptA').classList.add('selected');
doAlert('Showing artwork',0);
} else if(imgTypeShown == 1) {
document.getElementById('promptP').classList.add('selected');
doAlert('Showing portraits',0);
} else if(imgTypeShown == 2) {
document.getElementById('promptL').classList.add('selected');
doAlert('Showing landscapes',0);
}
} else {
if(selected == 'promptA') {
imgTypeShown = 0;
doAlert('Showing artwork',0);
} else if(selected == 'promptP') {
imgTypeShown = 1;
doAlert('Showing portraits',0);
} else if(selected == 'promptL') {
imgTypeShown = 2;
doAlert('Showing landscapes',0);
}
var links = document.getElementById(selected).parentNode.querySelectorAll('.link');
links.forEach(function(link) {
link.classList.remove('selected');
});
document.getElementById(selected).classList.add('selected');
}
}
function storeOptionsState() {
let state = {};
if(document.getElementById('promptA').classList.contains('selected')) {
state['prompt'] = 'promptA';
} else if(document.getElementById('promptP').classList.contains('selected')) {
state['prompt'] = 'promptP';
} else {
state['prompt'] = 'promptL';
}
if(document.getElementById('sortAR').classList.contains('selected')) {
state['artistSort'] = 'sortAR';
} else {
state['artistSort'] = 'sortAA';
}
if(document.getElementById('sortTC').classList.contains('selected')) {
state['tagSort'] = 'sortTC';
} else {
state['tagSort'] = 'sortTA';
}
storeItemBasedOnAccessType('optionsChecked',state,false,false);
}
function rotatePromptsImages() {
// hide all images
let images = document.querySelectorAll('.imgBox img');
images.forEach(function(image) {
image.classList.add('hidden');
});
// unhide images matching highlighted option (imgTypeShown)
if(imgTypeShown == 0) {
images = document.querySelectorAll('.img_artwork');
} else if(imgTypeShown == 1) {
images = document.querySelectorAll('.img_portrait');
} else if(imgTypeShown == 2) {
images = document.querySelectorAll('.img_landscape');
}
images.forEach(function(image) {
image.classList.remove('hidden');
});
// switch prev and next button icons
let prevButtons = document.querySelectorAll('.art_prev span');
prevButtons.forEach(function(span) {
span.textContent = artTypes[imgTypeShown];
span.title = 'showing ' + artTitles[imgTypeShown];
});
let nextButtons = document.querySelectorAll('.art_next span');
nextButtons.forEach(function(span) {
span.textContent = artTypes[imgTypeShown];
span.title = 'showing ' + artTitles[imgTypeShown];
});
}
function rotateModelsImages() {
// hide all imgBoxes
let visibleImgBoxes = document.querySelectorAll('.imgBox:not(.hidden)');
visibleImgBoxes.forEach(function(imgBox) {
imgBox.classList.add('hidden');
});
// switch model selection, unhide desired imgBox
if(secondModelIsSelected) {
secondModelIsSelected = false;
visibleImgBoxes = document.querySelectorAll('.imgBox[data-model="0"]');
} else {
secondModelIsSelected = true;
visibleImgBoxes = document.querySelectorAll('.imgBox[data-model="1"]');
}
visibleImgBoxes.forEach(function(imgBox) {
imgBox.classList.remove('hidden');
});
// update button
let artSetSpans = document.querySelectorAll('.art_set span');
artSetSpans.forEach(function(span) {
if(secondModelIsSelected) {
span.textContent = 'B: ' + models[secondModelSelected][1];
span.title = 'showing ' + models[secondModelSelected][2];
doAlert('Showing B: ' + models[secondModelSelected][1],0);
} else {
span.textContent = 'A: ' + models[0][1];
span.title = 'showing ' + models[0][2];
doAlert('Showing A:' + models[0][1],0);
}
});
// update name shown on hover
let modelName = document.querySelectorAll('.model_name span');
modelName.forEach(function(span) {
span.childNodes[2].nodeValue = models[secondModelSelected][2];
});
}
function updateTags(whoCalled) {
let delay = 10;
if(whoCalled == 'start') {
// delay of 200ms allow checkbox CSS animation to complete
delay = 200;
}
timer = setTimeout(async function() {
// we defer counts per tag because strict mode is slow
updateArtistsCountPerTagSlow(whoCalled);
if(whoCalled == 'start') {
await loadMostUsedTags();
sortTags();
showHideLowCountTags();
// #toggles has .start from HTML; we shown normal appearance after sorting
document.querySelector('#toggles').classList.remove('start');
}
}, delay);
}
function updateArtistsCountPerTagSlow(whoCalled) {
let hideDeprecated = document.querySelector('input[name="deprecated"]').checked;
let isPermissive = document.querySelector('input[name="mode"]').checked;
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
if(whoCalled == 'start' || whoCalled == 'permissivenessClick') {
// permissive mode tag counts don't change based on what's selected
// so we gather counts based on the data rather than DOM
// since it's fast, we'll do it for start regardless of permissive setting
if(whoCalled == 'start') {
for(i=1,il=tagCategories.length-1; i<il; i++) {
// skip first category ('important')
// and skip last category ('other')
let category = tagCategories[i];
for(j=1,jl=category.length; j<jl; j++) {
// skip first item, which is category name
let tag = category[j];
let countKnown = 0;
let countAll = 0;
for(k=0,kl=artistsData.length; k<kl; k++) {
let artist = artistsData[k];
if(artist[2].indexOf(tag) > -1) {
countAll++;
if(!artist[3]) {
countKnown++;
}
}
}
let arr = [tag,countKnown,countAll];
tagCountsPermissive.push(arr);
}
}
}
// write counts to DOM
let hideLowCount = document.querySelector('input[name="deprecated"]').checked;
for (i=0, il=tagCountsPermissive.length; i<il; i++) {
let tag = tagCountsPermissive[i];
checkbox = document.querySelector('input[name="' + tag[0].toLowerCase() + '"]');
if(checkbox !== null) {
// some tags tagCategories aren't found in artistsData
if(!checkbox.parentNode.classList.contains('top_control')) {
if(hideLowCount) {
checkbox.parentNode.querySelector('.count').textContent = ' - ' + tag[1].toLocaleString();
} else {
checkbox.parentNode.querySelector('.count').textContent = ' - ' + tag[2].toLocaleString();
}
}
}
}
checkboxes.forEach(function(checkbox) {
checkbox.parentNode.classList.remove('no_matches');
checkbox.parentNode.querySelector('input').disabled = false;
});
updateArtistsCountPerCategory();
}
if(!isPermissive) {
// strict mode updates the counts with every checkbox change
// counts depend on what's checked and what's visible
checkboxes.forEach(function(checkbox) {
// 'favorite' count is updated elsewhere
if(checkbox.name != 'favorite') {
// top controls aren't tags and don't have counts
if(!checkbox.parentNode.classList.contains('top_control')) {
let matchingDivs;
// for each checkbox, only count artists with a tags matching all checked checkboxes
matchingDivs = document.querySelectorAll('.image-item[data-tag-list*="' + checkbox.name + '"]:not(.hidden)');
count = matchingDivs.length;
if(!count) { count = 0; }
checkbox.parentNode.querySelector('.count').textContent = ' - ' + count.toLocaleString();
if(count == 0) {
checkbox.parentNode.classList.add('no_matches');
checkbox.parentNode.querySelector('input').disabled = true;
} else {
checkbox.parentNode.classList.remove('no_matches');
checkbox.parentNode.querySelector('input').disabled = false;
}
}
}
});
}
let allDivs = document.querySelectorAll('.image-item');
let hiddenDivs = document.querySelectorAll('.image-item.hidden');
updateCountOfAllArtistsShown(allDivs, hiddenDivs);
}
function updateArtistsCountPerCategory() {
let imageItems = document.querySelectorAll('.image-item');
let notDeprecatedItems = document.querySelectorAll('.image-item:not([data-deprecated="true"])');
let deprecatedCheckbox = document.querySelector('input[name="deprecated"]');
let countItems = imageItems;
if(deprecatedCheckbox.checked) {
countItems = notDeprecatedItems;
}
let counts = [];
for(i=0,il=tagCategories.length; i<il; i++) {
counts[i] = 0;
}
countItems.forEach(function(imageItem) {
let tagList = imageItem.dataset.tagList.split('|');
let isFavorited = imageItem.classList.contains('favorite');
for(i=0,il=tagCategories.length; i<il; i++) {
if(tagCategories[i].map(tag => tag.toLowerCase()).some(tag => tagList.includes(tag))) {
counts[i]++;
}
if(tagCategories[i][0] == 'important') {
if(isFavorited) {
counts[i]++;
}
}
}
});
for(i=0,il=tagCategories.length; i<il; i++) {
let label = document.querySelector('[data-category-name="' + tagCategories[i][0] + '"]');
if(tagCategories[i][0] == 'other') {
label.querySelector('.count').textContent = '';
} else {
label.querySelector('.count').textContent = ' - ' + counts[i].toLocaleString();
}
}
}
function updateCountOfAllArtistsShown(divs, hiddenDivs) {
var checkAll = document.querySelector('input[name="check-all"]').parentNode.querySelector('.count');
var shown = document.getElementById('artistsShown').querySelector('.count');
var deprecatedItems = document.querySelectorAll('[data-deprecated="true"]');
if(!divs) {
// when this is called by change of a checkbox, divs is not passed
var divs = document.querySelectorAll('.image-item');
var hiddenDivs = document.querySelectorAll('.image-item.hidden');
}
var total = 0;
var visible = 0;
if(document.querySelector('input[name="deprecated"]').checked) {
total = divs.length - deprecatedItems.length;
visible = total - hiddenDivs.length + deprecatedItems.length;
} else {
total = divs.length;
visible = total - hiddenDivs.length;
}
var percent = Math.round((visible / total) * 100) + '%';
if(percent == '0%') {
percent = '<1%';
}
checkAll.textContent = ' - ' + total.toLocaleString();
shown.textContent = 'shown - ' + visible.toLocaleString() + ' / ' + percent;
}
function styleLabelToCheckbox(checkbox) {
if(checkbox.checked) {
checkbox.parentNode.classList.add('isChecked');
} else {
checkbox.parentNode.classList.remove('isChecked');
}
}
function checkAllInCategory(theCheckbox) {
let thisLabel = theCheckbox.parentNode;
if (thisLabel.classList.contains('category')) {
let container = document.getElementById('toggles');
let labels = container.getElementsByTagName('label');
let isChecking = false;
for (let label of labels) {
// If we reach 'thisLabel', start checking.
if(label === thisLabel) {
isChecking = true;
continue; // Skip 'thisLabel' itself.
}
// If 'isChecking' is true and we found another 'category', stop checking.
if(isChecking && label.classList.contains('category')) {
break;
}
// If 'isChecking' is true, check or uncheck the checkbox inside the current label.
if(isChecking) {
if(!label.classList.contains('hidden')) {
// hidden labels must remain unchecked
let checkbox = label.querySelector('input[type="checkbox"]');
if(checkbox) {
checkbox.checked = theCheckbox.checked;
}
}
}
}
}
}
function blurUnblurNudity() {
let nudity = document.querySelector('input[name="nudity"]');
if(nudity.checked) {
nudity.parentNode.classList.remove('warning');
let images = document.querySelectorAll('.img');
images.forEach(function(img){
img.classList.remove('censored');
});
} else {
nudity.parentNode.classList.add('warning');
for (let i=0, il=artistsData.length; i<il; i++) {
let artist = artistsData[i];
for(j=0,jl=artist[4].length; j<jl; j++) {
let blurBox = 0;
let blurModel = artist[4][j][0];
if(blurModel > 0) { blurBox = 1; }
let blurImage = artist[4][j][1];
if(blurImage == 'a') { blurImage = '.img_artwork'; }
if(blurImage == 'p') { blurImage = '.img_portrait'; }
if(blurImage == 'l') { blurImage = '.img_landscape'; }
if(blurModel == secondModelSelected || blurModel == 0) {
let imageItems = document.querySelectorAll('.image-item');
for(k=0,kl=imageItems.length; k<kl; k++) {
// find match in artistsData if first and last names match
let imageItem = imageItems[k];
let firstN = imageItem.querySelector('.firstN').textContent;
let lastN = imageItem.querySelector('.lastN').textContent;
if(artist[0] == lastN && artist[1] == firstN) {
let box = imageItem.querySelector('.imgBox[data-model="' + blurBox + '"');
let image = box.querySelector(blurImage).classList.add('censored');
break;
}
}
}
}
}
}
}
function toggleCensored(h4) {
let imageItem = h4.closest('.image-item');
let firstN = imageItem.querySelector('.firstN').textContent;
let lastN = imageItem.querySelector('.lastN').textContent;
for (let i=0, il=artistsData.length; i<il; i++) {
let artist = artistsData[i];
if(artist[0] == lastN && artist[1] == firstN) {
let blurModel = imageItem.querySelector('.imgBox:not(.hidden)').dataset.model;
if(blurModel == 1) { blurModel = secondModelSelected; }
let img = imageItem.querySelector('.imgBox:not(.hidden) .img:not(.hidden)');
let blurImage = '';
if(img.classList.contains('img_artwork')) { blurImage = 'a'; }
if(img.classList.contains('img_portrait')) { blurImage = 'p'; }
if(img.classList.contains('img_landscape')) { blurImage = 'l'; }
let blurNew = blurModel + blurImage;
let match = false;
for(j=0,jl=artist[4].length; j<jl; j++) {
let blurOld = artist[4][j]
if(blurNew == blurOld) {
match = true;
artist[4].splice(j,1);
img.classList.remove('censored');
}
}
if(!match) {
artist[4].push(blurNew);
img.classList.add('censored');
}
break;
}
}
}
function hideAllArtists() {
let imageItems = document.querySelectorAll('.image-item');
imageItems.forEach(function(imageItem) {
imageItem.classList.add('hidden');
});
}
function uncheckedAllStrictMode(isChecked) {
if(!isChecked) {
// when entering strict mode, only allow one checked tag, the first one found
let labels = Array.from(document.querySelectorAll('label'))
.filter(l => !l.classList.contains('top_control'))
.filter(l => !l.classList.contains('category'))
.filter(l => l.querySelector('input').checked == true);
if(document.querySelector('input[name="favorite"]').checked) {
labels.unshift(document.querySelector('input[name="favorite"]').parentNode);
}
if(labels.length > 0) {
document.querySelector('input[name="check-all"]').checked = false;
checkOrUncheckAll(false);
let checkbox = labels[0].querySelector('input');
checkbox.checked = true;
styleLabelToCheckbox(checkbox);
doAlert(checkbox.name + ' is checked',0);
}
}
}
function unhideBasedOnPermissiveSetting() {
var permissiveCheckbox = document.querySelector('input[name="mode"]');
if(permissiveCheckbox.checked) {
permissiveCheckbox.parentNode.classList.remove('warning');
unhideArtistsPermissive();
} else {
permissiveCheckbox.parentNode.classList.add('warning');
unhideArtistsStrict();
}
var unHidden = document.querySelectorAll('.image-item').length - document.querySelectorAll('.image-item.hidden').length;
if(unHidden == 0) {
document.getElementById('filtersHidingAll').classList.add('shown');
} else {
document.getElementById('filtersHidingAll').classList.remove('shown');
}
}
function unhideArtistsPermissive() {
// permissive mode unhides images that match ANY checked tag
// the set of checkboxes is derived from the unique tags within the imageItem (Artists) tagList dataSet
var imageItems = document.querySelectorAll('.image-item');
var checkboxes = Array.from(document.querySelectorAll('input[type="checkbox"]'))
.filter(cb => !cb.parentNode.classList.contains("top_control"));
checkboxes.push(document.querySelector('input[name="favorite"]'));
var checked = checkboxes.filter(cb => cb.checked).map(cb => cb.name);
imageItems.forEach(function(imageItem) {
let tagList = imageItem.dataset.tagList.split('|');
if(imageItem.classList.contains('favorite')) {
tagList.push('favorite');
}
if(checked.some(tag => tagList.includes(tag))) {
imageItem.classList.remove('hidden');
}
});
hideDeprecated();
}
function unhideArtistsStrict() {
// strict mode unhides images that match ALL checked tags
// the set of checkboxes is derived from the unique tags within the imageItem (Artists) tagList dataSet
var imageItems = document.querySelectorAll('.image-item');
var checkboxes = Array.from(document.querySelectorAll('input[type="checkbox"]'))
.filter(cb => !cb.parentNode.classList.contains("top_control"));
checkboxes.push(document.querySelector('input[name="favorite"]'));
var checked = checkboxes.filter(cb => cb.checked).map(cb => cb.name);
if(checked.length > 0) {
imageItems.forEach(function(imageItem, index) {
let tagList = imageItem.dataset.tagList.split('|');
if(imageItem.classList.contains('favorite')) {
tagList.push('favorite');
}
if(checked.every(tag => tagList.includes(tag))) {
imageItem.classList.remove('hidden');
}
});
} else {
// while not strictly logical, it's needed because
// nothing would be checkable if strict is entered while everything is unchecked
imageItems.forEach(function(imageItem) {
imageItem.classList.remove('hidden');
});
}
hideDeprecated();
}
function unhideAristsExact() {
// exact mode isn't currently used because almost no two artists have the same set of tags
// exact mode unhides images that match ALL checked tags and NO unchecked tags
// the set of checkboxes is derived from the unique tags within the imageItem (Artists) tagList dataSet
var imageItems = document.querySelectorAll('.image-item');
var checkboxes = Array.from(document.querySelectorAll('input[type="checkbox"]'))
.filter(cb => !cb.parentNode.classList.contains("top_control"));
checkboxes.push(document.querySelector('input[name="favorite"]'));
var checked = checkboxes.filter(cb => cb.checked).map(cb => cb.name);
var unchecked = checkboxes.filter(cb => !cb.checked).map(cb => cb.name);
if(checked.length > 0) {
imageItems.forEach(function(imageItem, index) {
let tagList = imageItem.dataset.tagList.split('|');
if(imageItem.classList.contains('favorite')) {
tagList.push('favorite');
}
if(checked.every(tag => tagList.includes(tag))) {
if(unchecked.every(tag => !tagList.includes(tag))) {
imageItem.classList.remove('hidden');
}
}
});
}
hideDeprecated();
}
function hideDeprecated() {
if(document.querySelector('input[name="deprecated"]').checked) {
let deprecatedItems = document.querySelectorAll('[data-deprecated="true"]');
deprecatedItems.forEach(function(item, index) {
item.classList.add('hidden');
});
}
}
function checkOrUncheckAll(isChecked) {
let divs = document.querySelectorAll('.image-item');
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
let permissiveCheckbox = document.querySelector('input[name="mode"]');
let isPermissive = permissiveCheckbox.checked;
if(isChecked) {
if(isPermissive) {
checkboxes.forEach(function(checkbox) {
let label = checkbox.parentNode;
let isTop = label.classList.contains('top_control');
let isHidden = label.classList.contains('hidden');
if(!isTop || checkbox.name == 'favorite') {
if(!isHidden) {
// hidden/disabled label must not be checked
checkbox.checked = true;
styleLabelToCheckbox(checkbox);
}
};
});
} else {
// can't allow check-all for strict mode
// because the order of checking change the available checkmarks
document.querySelector('input[name="check-all"]').checked = false;
doAlert('Only works in permissive mode',0);
}
} else {
checkboxes.forEach(function(checkbox) {
let label = checkbox.parentNode;
let isTop = label.classList.contains('top_control');
if(!isTop || checkbox.name == 'favorite') {
checkbox.checked = false;
styleLabelToCheckbox(checkbox);
}
});
}
}
function showInfo() {
document.getElementById('information').classList.add('shown');
informationMode = true;
}
function hideInfo() {
document.getElementById('info_search_input').value = '';
document.getElementById('information').classList.remove('shown');
informationMode = false;
}
function showInformation(tab) {
let info = document.querySelectorAll('#information .selected');
info.forEach(function(element) {
element.classList.remove('selected');
});
document.getElementById('info_' + tab).classList.add('selected');
document.getElementById('information_' + tab).classList.add('selected');
document.getElementById('information_' + tab).scrollTop = 0;
if (tab == 'actions') {
document.getElementById('info_search_input').focus();
} else if(tab == 'export') {
showExport();
}
}
function searchForTagsInfo(event) {
let input = document.getElementById('info_search_input');
if(input.dataset.match !== undefined) {
event.preventDefault();
if(event.key === 'Backspace' || event.keyCode === 8) {
input.value = '';
delete input.dataset.match;
} else {
input.value = input.dataset.match;
}
} else {
let matches = 0;
let output = document.getElementById('info_search_output');
output.innerHTML = '';
let match = '';
let tags = document.querySelectorAll('#toggles label:not(.top_control):not(.category):not([data-is-in-category="other"]');
tags.forEach(function(tag) {
let tagName = tag.querySelector('input').name;
if(tagName.toLowerCase().indexOf(input.value.toLowerCase()) > -1) {
let label = tag.cloneNode(true);
label.addEventListener('change', function(e) {
toggleMatchingTag(this);
});
output.appendChild(label);
match = tagName;
matches++;
}
});
if(matches == 0) {
let noneFound = document.createElement('label');
noneFound.textContent = 'no matching tags';
output.appendChild(noneFound);
} else if(matches == 1) {
input.value = match;
event.preventDefault();
input.dataset.match = match;
} else {
// sortInfoSearchTags(output);
}
}
}
function sortInfoSearchTags(output) {
let labels = Array.from(output.querySelectorAll('label'));
let sortByCount = document.getElementById('sortTC').classList.contains('selected');
labels.sort(function(a, b) {
if(sortByCount) {
var numA = parseInt(a.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2),10);
var numB = parseInt(b.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2),10);
return numB - numA;
} else {
var aValue = a.querySelector('input[type="checkbox"]').name;
var bValue = b.querySelector('input[type="checkbox"]').name;
return aValue.localeCompare(bValue);
}
});
labels.forEach(function(label) {
output.appendChild(label);
});
}
function toggleMatchingTag(searchLabel) {
let toggleLabels = document.getElementById('toggles').querySelectorAll('label');
let searchInput = searchLabel.querySelector('input');
let toggleMatch;
for(i=0,il=toggleLabels.length; i<il; i++) {
let toggleInput = toggleLabels[i].querySelector('input');
if(toggleInput.value == searchInput.value) {
toggleMatch = toggleLabels[i];
break;
}
}
toggleMatch.querySelector('input').checked = searchInput.checked;
toggleMatch.classList.remove('hidden');
toggleMatch.querySelector('input').dispatchEvent(new Event('change'));
let input = document.getElementById('info_search_input');
input.focus();
}
function searchShowRandomTags() {
document.querySelector('input[name="check-all"]').checked = false;
checkOrUncheckAll(false);
hideAllArtists();
unhideBasedOnPermissiveSetting();
let output = document.getElementById('info_search_output');
output.innerHTML = '';
let tags = Array.from(document.querySelectorAll('#toggles label:not(.top_control):not(.category):not([data-is-in-category="other"])'));
tags.forEach(function(tag) {
tag.dataset.randomRank = Math.random();
});
tags.sort(function(a, b) {
var aValue = a.dataset.randomRank;
var bValue = b.dataset.randomRank;
return bValue - aValue;
});
let firstLabel;
for(i=0,il=6; i<il; i++) {
let label = tags[i].cloneNode(true);
label.addEventListener('change', function(e) {
toggleMatchingTag(this);
});
output.appendChild(label);
if(i==0) {
firstLabel = label;
}
}
// check-mark and toggle on the first random label
firstLabel.querySelector('input').checked = true;
toggleMatchingTag(firstLabel);
// cleanup
tags.forEach(function(tag) {
delete tag.dataset.randomRank;
});
}
function showExport() {
// favorites
var textareaF = document.getElementById('export_favorites_list');
var favoritedArtists = false;
loadItemBasedOnAccessType('favoritedArtists').then(state => {
var value = '';
if(state) {
value += 'To import these favorites later, click "copy to clipboard" and save to any file. Then paste the text from that file into this text box, and click "import". The imported text must contain the JSON string below (the curly brackets and what\'s between them).\r\n\r\n' + JSON.stringify(state);
textareaF.value = value;
} else {
value += 'You haven\'t favorited any artists yet.\r\n\r\n';
value += 'To import favorites that you exported earlier, paste the text into this text box, and click "import".';
textareaF.value = value;
}
});
// edits
var textareaE = document.getElementById('export_edits_list');
let editedArtistsArr = Array.from(editedArtists);
if(editedArtistsArr.length > 0) {
value = 'Post a comment with these edits on Hugging Face:\r\n\r\n';
for(i=0,il=editedArtistsArr.length;i<il;i++) {
let edit = editedArtistsArr[i];
value += '["'+edit[0]+'","'+edit[1]+'","'+edit[2]+'",'+edit[3]+'],\r\n';
}
} else {
value = '';
}
textareaE.value = value;
// db
var textareaA = document.getElementById('export_artists_list');
value = '';
artistsData = artistsData.sort((a, b) => {
// compare by known to SDXL boolean
if (a[3] && !b[3]) return 1;
if (!a[3] && b[3]) return -1;
// compare by last name (ignoring case)
const lastNameComparison = a[0].toLowerCase().localeCompare(b[0].toLowerCase());
if (lastNameComparison !== 0) return lastNameComparison;
// compare by first name (ignoring case)
return a[1].toLowerCase().localeCompare(b[1].toLowerCase());
});
for(i=0,il=artistsData.length;i<il;i++) {
// sort tags within artist by alpha
let artist = artistsData[i];
let tags = artist[2].split('|');
tags = tags.sort(function(a, b) {
var aValue = a.toLowerCase();
var bValue = b.toLowerCase();
return aValue.localeCompare(bValue);
});
let newTags = [];
let added = '';
// move the 'added' tag to the end
for (let i=0, il=tags.length; i<il; i++) {
if(tags[i].match(/added-(\d|-)*/)) {
added = tags[i];
} else {
newTags.push(tags[i]);
}
}
newTags.push(added);
artist[2] = newTags.join('|');
// sort censored images array
artist[4] = artist[4].sort(function(a, b) {
return a.localeCompare(b);
});
let arrayStr = '';
for (let i=0, il=artist[4].length; i<il; i++) {
arrayStr += '"' + artist[4][i] + '",';
}
arrayStr = arrayStr.substring(0,arrayStr.length-1);
// output updated artist
value += '["'+artist[0]+'","'+artist[1]+'","'+artist[2]+'",'+artist[3]+',['+arrayStr+']],\r\n';
}
textareaA.value = value;
}
function exportTextarea(type) {
let contents = '';
if(type == 'favorites') {
contents = document.getElementById('export_favorites_list').value;
} else if(type == 'edits') {
contents = document.getElementById('export_edits_list').value;
} else if(type == 'artists') {
contents = document.getElementById('export_artists_list').value;
}
navigator.clipboard.writeText(contents)
.then(() => {
doAlert(type + ' copied to clipboard!',1);
})
.catch(() => {
doAlert('😭😭 Can\'t access clipboard',1);
});
}
function importFavorites() {
let el = document.getElementById('export_favorites_list');
let favorites = el.value;
let startCount = (favorites.match(/{/g) || []).length;
let endCount = (favorites.match(/}/g) || []).length;
if (startCount > 1 || endCount > 1) {
el.value = 'That text can\'t be imported because it contains multiple curly brackets {}.'
return null;
}
let start = favorites.indexOf('{');
let end = favorites.lastIndexOf('}');
if (start === -1 || end === -1) {
el.value = 'That text can\'t be imported because it contains zero curly brackets {}.'
return null;
}
let jsonString = favorites.substring(start, end + 1);
try {
let favoritesObject = JSON.parse(jsonString);
// check structure of each key-value pair in favoritesObject
for (let key in favoritesObject) {
let value = favoritesObject[key];
if (!key.includes('|') || typeof value !== 'boolean') {
el.value = 'That text can\'t be imported because the JSON string it contains doesn\'t contain a valid list of artists.'
return null;
}
}
if(confirm('This will overwrite any saved favorites. Are you sure?')) {
storeItemBasedOnAccessType('favoritedArtists',favoritesObject,false,false);
alert('Favorites were imported!');
loadFavoritesState();
} else {
alert('Okay, you have cancelled the import.');
return null;
}
} catch(e) {
el.value = 'That text can\'t be imported because it doesn\'t contain a valid JSON sting.'
return null;
}
}
function sortTags() {
if(document.getElementById('sortTC').classList.contains('selected')) {
sortTagsByCount();
} else {
sortTagsByAlpha();
}
}
function sortTagsByAlpha() {
var useCategories = document.querySelector('input[name="use_categories"]').checked;
let container = document.getElementById('toggles');
let labels = Array.from(container.getElementsByTagName('label'));
if (!useCategories) {
// <labels> with class="category" are hidden, sort all other labels together by alpha
labels.sort(function(a, b) {
var aValue = a.querySelector('input[type="checkbox"]').name;
var bValue = b.querySelector('input[type="checkbox"]').name;
return aValue.localeCompare(bValue);
});
labels.forEach(function(label) {
let isTop = label.classList.contains('top_control');
if(!isTop) {
// appendChild will move the element to the end of the container
// "favorite" tag always stays at top
if(label.querySelector('input').name != 'favorite') {
container.appendChild(label);
}
}
});
// "added" tags always goes to bottom
labels.forEach(function(label) {
let name = label.querySelector('input').name;
if(name.indexOf('added-') > -1) {
// appendChild will move the element to the end of the container
container.appendChild(label);
}
});
} else {
let labelMap = labels.reduce((acc, label) => {
// map: keys are checkbox names, values are corresponding parent label element
let checkboxName = label.querySelector('input[type="checkbox"]').name;
acc[checkboxName.toLowerCase()] = label;
return acc;
}, {});
// sort tags that exist in tagCategories under that category
tagCategories.forEach(arrayOfTags => {
// first append the label that matches the category name
let categoryName = arrayOfTags[0];
let categoryLabel = labelMap[categoryName.toLowerCase()];
if (categoryLabel) {
container.appendChild(categoryLabel);
}
// the append the sorted labels that match the tag
let arrayOfTagsLower = arrayOfTags.slice(1).map(tag => tag.toLowerCase());
arrayOfTagsLower.sort();
arrayOfTagsLower.forEach(tag => {
let label = labelMap[tag];
if(label) {
let isTop = label.classList.contains('top_control');
if(!isTop) {
label.dataset.isInCategory = categoryLabel.dataset.categoryName;
// appendChild will move the element to the end of the container
container.appendChild(label);
}
// remove this label from the map
delete labelMap[tag];
}
});
if(categoryName == 'important') {
container.appendChild(document.getElementById('edit_most_used'));
}
});
// this leaves all the tags that didn't exist in tagCategories sorted at the top
let leftoverLabelsKeys = Object.keys(labelMap);
leftoverLabelsKeys.sort();
leftoverLabelsKeys.forEach(key => {
let label = labelMap[key];
if (label && !label.classList.contains('top_control') && !label.classList.contains('category')) {
label.dataset.isInCategory = 'other';
container.appendChild(label);
}
});
// favorite always goes to top of important category
let importantCategory = document.querySelector('label[data-category-name="important"]');
let favoriteLabel = document.getElementById('favorite_label');
importantCategory.after(favoriteLabel);
}
}
function sortTagsByCount() {
var useCategories = document.querySelector('input[name="use_categories"]').checked;
let container = document.getElementById('toggles');
let labels = Array.from(container.getElementsByTagName('label'));
if (!useCategories) {
labels.sort(function(a, b) {
var numA = parseInt(a.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2),10);
var numB = parseInt(b.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2),10);
return numB - numA;
});
labels.forEach(function(label) {
let isTop = label.classList.contains('top_control');
if(!isTop) {
// appendChild will move the element to the end of the container
// "favorite" tag always stays at top
if(label.querySelector('input').name != 'favorite') {
container.appendChild(label);
}
}
});
// "added" tags always goes to bottom
labels.forEach(function(label) {
let name = label.querySelector('input').name;
if(name.indexOf('added-') > -1) {
// appendChild will move the element to the end of the container
container.appendChild(label);
}
});
} else {
let labelMap = labels.reduce((acc, label) => {
// map: keys are checkbox names, values are corresponding parent label element
let checkboxName = label.querySelector('input[type="checkbox"]').name;
acc[checkboxName.toLowerCase()] = label;
return acc;
}, {});
tagCategories.forEach(arrayOfTags => {
let categoryName = arrayOfTags[0];
let categoryLabel = labelMap[categoryName.toLowerCase()];
if (categoryLabel) {
container.appendChild(categoryLabel);
}
// get the list of tags from the category array
let arrayOfTagsLower = arrayOfTags.slice(1).map(tag => tag.toLowerCase());
// Sort by the number in each label
arrayOfTagsLowerExisting = [];
arrayOfTagsLower.forEach(function(tag) {
if(labelMap[tag]) {
arrayOfTagsLowerExisting.push(tag);
}
});
arrayOfTagsLowerExisting.sort((a, b) => {
let labelA = labelMap[a];
let labelB = labelMap[b];
if(labelA && labelB){
let numA = parseInt(labelA.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2), 10);
let numB = parseInt(labelB.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2), 10);
return numB - numA;
} else {
return 0;
}
});
arrayOfTagsLowerExisting.forEach(tag => {
let label = labelMap[tag];
if (label) {
let isTop = label.classList.contains('top_control');
if (!isTop) {
// appendChild will move the element to the end of the container
label.dataset.isInCategory = categoryLabel.dataset.categoryName;
container.appendChild(label);
}
// remove this label from the map
delete labelMap[tag];
}
});
if(categoryName == 'important') {
container.appendChild(document.getElementById('edit_most_used'));
}
});
let leftoverLabelsKeys = Object.keys(labelMap);
// Sort the leftover labels keys by the number in each label
leftoverLabelsKeys.sort((a, b) => {
let labelA = labelMap[a];
let labelB = labelMap[b];
if(labelA && labelB){
let numA = parseInt(labelA.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2), 10);
let numB = parseInt(labelB.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2), 10);
return numB - numA;
} else {
return 0;
}
});
leftoverLabelsKeys.forEach(key => {
let label = labelMap[key];
if (label && !label.classList.contains('top_control') && !label.classList.contains('category')) {
label.dataset.isInCategory = 'other';
container.appendChild(label);
}
});
// favorite always goes to top of important category
let importantCategory = document.querySelector('label[data-category-name="important"]');
let favoriteLabel = document.getElementById('favorite_label');
importantCategory.after(favoriteLabel);
}
}
async function loadMostUsedTags() {
// aka the important category
await loadItemBasedOnAccessType('mustUsedTags').then(state => {
let mostUsedCategory = document.querySelector('[data-category-name="important"]');
for(let tag in state) {
if(state[tag]) {
let label = document.querySelector('input[name="'+ tag +'"]');
if(label) {
label = label.parentNode;
label.classList.add('is_most_used');
label.querySelectorAll('.most_used_indicator')[0].textContent = '-';
mostUsedCategory.after(label);
updateTagArrayToMatchMostUsed(true,label,tag);
}
}
}
// favorite is always most used
let favoriteLabel = document.getElementById('favorite_label');
favoriteLabel.classList.add('is_most_used');
favoriteLabel.querySelectorAll('.most_used_indicator')[0].textContent = '';
updateTagArrayToMatchMostUsed(true,favoriteLabel,'favorite');
});
}
function updateTagArrayToMatchMostUsed(isAdding,label,tag) {
// need to updated tagCategories because it's used to show sums of the categories
// the first category in tagCategories stores the important tags unless the database is messed up
if(isAdding) {
tagCategories[0].push(tag);
// remove tag from its original category
for(i=0,il<tagCategories.length; i<il; i++) {
if(tagCategories[i][0] == label.dataset.isInCategory) {
tagCategories[i] = tagCategories[i].filter(function(ele){
return ele != tag;
});
break;
}
}
} else {
tagCategories[0] = tagCategories[0].filter(function(ele){
return ele != tag;
});
// add tag back to it's original category
for(i=0,il<tagCategories.length; i<il; i++) {
if(tagCategories[i][0] == label.dataset.isInCategory) {
tagCategories[i].push(tag);
break;
}
}
}
}
function storeMostUsedState(label) {
var name = label.querySelector('input').name;
storeItemBasedOnAccessType('mustUsedTags',false,name,label.classList.contains('is_most_used'));
}
function enterExitEditMostUsedMode(doExit) {
if(storingAccessType == 'none') {
alertNoStoringAccess(0)
} else {
let inputs = Array.from(document.querySelectorAll('input'));
if(editMostUsedMode || doExit) {
// exit edit mode
editMostUsedMode = false;
document.getElementById('edit_most_used').textContent = 'edit these';
document.getElementById('layout').classList.remove('edit_mode');
inputs.forEach(function(input) {
input.disabled = false;
});
let labels = Array.from(document.querySelectorAll('.was_moved'));
labels.forEach(function(label) {
// clean up classes added to track moved tags during edit mode
label.classList.remove('was_moved');
});
document.getElementById('toggles').style.width = 'calc(' + gutterEndPercentX + '% + 20px)';
document.getElementById('gutter').style.left = gutterEndPercentX + '%';
document.getElementById('image-container').style.marginLeft = 'calc(' + gutterEndPercentX + '% + 50px)';
updateArtistsCountPerCategory();
sortTags();
} else {
// enter edit mode
editMostUsedMode = true;
document.getElementById('edit_most_used').textContent = 'exit editing';
document.getElementById('layout').classList.add('edit_mode');
inputs.forEach(function(input) {
input.disabled = true;
});
document.getElementById('toggles').style.width = '';
document.getElementById('gutter').style.left = '';
document.getElementById('image-container').style.marginLeft = '';
}
}
}
function addRemoveIsMostUsed(label) {
let mostUsedCategory = document.querySelector('[data-category-name="important"]');
if(label.classList.contains('is_most_used')) {
// remove it
label.classList.remove('is_most_used');
label.querySelectorAll('.most_used_indicator')[0].textContent = '+';
let originalCategory = document.querySelector('[data-category-name="' + label.dataset.isInCategory + '"]');
originalCategory.after(label);
updateTagArrayToMatchMostUsed(false,label,label.querySelector('input').name);
} else {
// add it
label.classList.add('is_most_used');
label.querySelectorAll('.most_used_indicator')[0].textContent = '-';
mostUsedCategory.after(label);
updateTagArrayToMatchMostUsed(true,label,label.querySelector('input').name);
}
label.classList.add('was_moved');
}
function sortArtists() {
if(document.getElementById('sortAR').classList.contains('selected')) {
sortArtistsByRandom();
} else {
sortArtistsByAlpha();
}
}
function sortArtistsByAlpha() {
var imageItems = Array.from(document.querySelectorAll('.image-item'));
imageItems.sort(function(a, b) {
var aValue = a.querySelector('.lastN').textContent;
var bValue = b.querySelector('.lastN').textContent;
return aValue.localeCompare(bValue);
});
imageItems.forEach(function(item) {
// appendChild will move the element to the end of the container
document.getElementById('image-container').appendChild(item);
});
}
function sortArtistsByRandom() {
var imageItems = Array.from(document.querySelectorAll('.image-item'));
imageItems.forEach(function(item) {
item.dataset.randomRank = Math.random();
});
imageItems.sort(function(a, b) {
var aValue = a.dataset.randomRank;
var bValue = b.dataset.randomRank;
return bValue - aValue;
});
imageItems.forEach(function(item) {
// appendChild will move the element to the end of the container
document.getElementById('image-container').appendChild(item);
});
}
function hideToggles() {
document.getElementById('toggles').classList.add('hide');
}
function showToggles() {
document.getElementById('toggles').classList.remove('hide');
}
function addOrRemoveFavorite(artist) {
if(artist.classList.contains('favorite')) {
artist.classList.remove('favorite');
} else {
artist.classList.add('favorite');
}
}
async function loadFavoritesState() {
await loadItemBasedOnAccessType('favoritedArtists').then(state => {
let artists = document.getElementsByClassName('image-item');
for(let artist of artists) {
let artistName = artist.getElementsByClassName('firstN')[0].textContent + '|' + artist.getElementsByClassName('lastN')[0].textContent;
if(state[artistName]) {
artist.classList.add('favorite');
} else {
artist.classList.remove('favorite');
}
}
updateFavoritesCount();
});
}
function storeFavoriteState(artist) {
if(storingAccessType == 'none') {
alertNoStoringAccess(0)
} else {
var artistName = artist.getElementsByClassName('firstN')[0].textContent + '|' + artist.getElementsByClassName('lastN')[0].textContent;
var isFavorited = artist.classList.contains('favorite');
storeItemBasedOnAccessType('favoritedArtists',false,artistName,isFavorited);
}
}
function updateFavoritesCount() {
var favoritedArtists = document.getElementsByClassName('favorite');
var favoriteCount = favoritedArtists.length;
var favoriteCounter = document.getElementById('favorite_label').querySelector('.count');
favoriteCounter.textContent = ' - ' + favoriteCount;
}
function doAlert(str,location) {
var alert = document.getElementById('alert');
alert.textContent = str;
// remove show and cleartimeout to redo anim if alert called multiple times
alert.classList.remove('show');
window.clearTimeout(timer);
if(location == 0) {
alert.classList.add('left');
} else {
alert.classList.remove('left');
// CSS defaults to right
}
timer = setTimeout(showAlert, 100);
}
function showAlert() {
var alert = document.getElementById('alert');
alert.classList.add('show');
if(alert.classList.contains('left')) {
// shorter display time because it covers the enlarged image
timer = setTimeout(hideAlert, 1000);
} else {
timer = setTimeout(hideAlert, 2500);
}
}
function hideAlert() {
var alert = document.getElementById('alert');
alert.classList.remove('show');
}
function copyStuffToClipboard(item,stuff) {
if(stuff == 'name') {
var str = item.closest('.image-item').getElementsByClassName('firstN')[0].textContent +
' ' + item.closest('.image-item').getElementsByClassName('lastN')[0].textContent;
navigator.clipboard.writeText(str)
.then(() => {
doAlert('Copied to name clipboard!',1);
})
.catch(() => {
doAlert('😭😭 Can\'t access clipboard',1);
});
} else if(stuff == 'tags') {
var str = item.textContent;
navigator.clipboard.writeText(str)
.then(() => {
doAlert('Copied to tags clipboard!',1);
})
.catch(() => {
doAlert('😭😭 Can\'t access clipboard',1);
});
} else if(stuff == 'copyAllNames') {
let str = '';
let count = 0;
let imageItems = document.querySelectorAll('.image-item:not(.hidden)');
let imageItemsArr = Array.from(imageItems).sort(function (a, b) {
return a.querySelectorAll('h3 span')[1].textContent.toLowerCase().localeCompare(
b.querySelectorAll('h3 span')[1].textContent.toLowerCase());
});
for(i=0,il=imageItemsArr.length;i<il;i++) {
let item = imageItemsArr[i];
str += item.querySelectorAll('h3 span')[0].textContent + ' ';
str += item.querySelectorAll('h3 span')[1].textContent + '\n';
count++;
}
if(count > 0) {
navigator.clipboard.writeText(str)
.then(() => {
doAlert('Copied ' + count.toLocaleString() + ' names to clipboard!',1);
})
.catch(() => {
doAlert('😭😭 Can\'t access clipboard',1);
});
} else {
doAlert('No artists are visible!',1);
}
} else if(stuff == 'prompt') {
let prompt_result = document.getElementById('prompt_result').querySelector('div');
let prompt = prompt_result.innerText.trim();
prompt = prompt.replace(/(\r\n|\n|\r)/gm, '');
navigator.clipboard.writeText(prompt)
.then(() => {
doAlert('Copied prompt to clipboard!',1);
})
.catch(() => {
doAlert('😭😭 Can\'t access clipboard',1);
});
}
}
function toggleThisArtistsTags(tagsStr) {
let names = tagsStr.split(', ');
let allChecked = true;
for(i=0,il=names.length;i<il;i++) {
if(!document.querySelector('input[name="'+names[i]+'"]').checked) {
allChecked = false;
break;
}
}
for(i=0,il=names.length;i<il;i++) {
var checkbox = document.querySelector('input[name="'+names[i]+'"]');
if(allChecked) {
checkbox.checked = false;
} else {
checkbox.checked = true;
}
storeCheckboxState(checkbox);
}
}
function showHideCategories() {
let useCategories = document.querySelectorAll('input[name="use_categories"]')[0].checked;
let categories = document.getElementsByClassName('category');
for(let category of categories) {
if(useCategories) {
category.classList.remove('hidden');
} else {
category.classList.add('hidden');
}
}
let editLink = document.getElementById('edit_most_used');
if(useCategories) {
editLink.classList.remove('hidden');
} else {
editLink.classList.add('hidden');
}
}
function showHideLowCountTags() {
var hideLowCount = document.querySelector('input[name="low_count"]').checked;
var checkAll = document.querySelector('input[name="check-all"]').checked;
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(function(checkbox) {
if(hideLowCount) {
var classes = checkbox.parentNode.classList;
if(!classes.contains('category')
&& !classes.contains('no_matches')
&& !classes.contains('top_control')) {
let count = parseInt(checkbox.parentNode.querySelector('.count').textContent.replace(/,/g, '').trim().substring(2),10);
if(count <= lowCountThreshold) {
if(checkbox.checked && checkAll == false) {
// low-count checkboxes that are checked aren't unchecked
// unless all checkboxes are checked
checkbox.parentNode.dataset.hideDeferred = true;
} else {
if(!checkbox.parentNode.classList.contains('is_most_used')) {
checkbox.parentNode.classList.add('hidden');
}
}
}
}
} else {
checkbox.parentNode.classList.remove('hidden');
}
});
showHideCategories();
}
function hideLowCountSingle(checkbox) {
let hideLowCount = document.querySelector('input[name="low_count"]').checked;
let hideDeferred = checkbox.parentNode.dataset.hideDeferred;
if(hideLowCount && hideDeferred) {
// only present if the tag is below the hide threshhold but not hidden because the checkbox was checked
checkbox.parentNode.classList.add('hidden');
checkbox.parentNode.dataset.hideDeferred = false;
doAlert('Low-use tag hidden',0);
}
}
function showLargerImages(imageItem) {
imageItem.classList.add('hover');
let images = imageItem.querySelectorAll('img');
let imagePromises = [];
images.forEach(function(img){
if(img.src.indexOf('_thumbs') > -1 && img.dataset.thumbSrc == undefined) {
// don't try to load if we tried before
if(!img.dataset.deprecated) {
let first = img.closest('.image-item').querySelector('.firstN').textContent;
let last = img.closest('.image-item').querySelector('.lastN').textContent;
img.dataset.thumbSrc = img.src;
let model = img.closest('.imgBox').dataset.model;
let src = 'images/'
if(model == 0) {
src += models[0][0] + '/';
} else {
src += models[secondModelSelected][0] + '/';
}
if(first == '') {
src += last.replaceAll(' ', '_');
} else {
src += first.replaceAll(' ', '_') + '_' + last.replaceAll(' ', '_');
}
let p = new Promise((resolve, reject) => {
if(img.classList.contains('img_artwork')) {
img.src = src + '-artwork.webp';
} else if(img.classList.contains('img_portrait')) {
img.src = src + '-portrait.webp';
} else if(img.classList.contains('img_landscape')) {
img.src = src + '-landscape.webp';
}
if(img.complete) {
resolve();
return;
}
img.onload = () => {
img.onload = null;
img.onerror = null;
resolve();
}
img.onerror = () => {
missingFiles += img.src + '\n';
img.onload = null;
img.onerror = null;
reject(new Error('Image loading error'));
};
});
imagePromises.push(p);
}
}
});
if(imagePromises.length > 0) {
Promise.allSettled(imagePromises).then(() => {
});
}
}
function hideLargerImages(imageItem) {
imageItem.classList.remove('hover');
}
function hideLargerImageBackup(imageItem) {
// very fast mouse movement from the thumbnail to the larger image can
// cause the browser to fail to detect that CSS imageItem:hover is no longer true
// therefore we need this backup, but we minimize mousemove listening
windowWidth = window.innerWidth;
let layout = document.getElementById('layout');
// store a reference to the bound function, allowing it to be removed
imageItem.boundMouseMoveFunc = mouseMoveFunc.bind(null, imageItem);
layout.addEventListener('mousemove', imageItem.boundMouseMoveFunc);
timer = setTimeout(function() {
cleanupEventListener(imageItem);
}, 200);
}
function mouseMoveFunc(imageItem, e) {
if (e.clientX < (windowWidth * 0.4)) {
imageItem.getElementsByClassName('imgBox')[0].style.position = 'relative';
}
}
function cleanupEventListener(imageItem) {
imageItem.getElementsByClassName('imgBox')[0].style.position = '';
let layout = document.getElementById('layout');
// remove the previously bound function
layout.removeEventListener('mousemove', imageItem.boundMouseMoveFunc);
}
function makeStyleRuleForDrag() {
style = document.createElement('style');
document.head.appendChild(style);
stylesheet = style.sheet;
let index = stylesheet.insertRule('.image-item.hover .imgBox { width: 40%; }', 0);
imgHoverRule = stylesheet.cssRules[index];
}
function movePartition(e) {
let newPos = gutterStartPosX + e.pageX - mouseStartPosX;
if(newPos < 240) {
newPos = 240;
} else if(newPos > window.innerWidth - 350) {
newPos = window.innerWidth - 350;
}
let gutterEndPercentX = (newPos / window.innerWidth) * 100;
document.getElementById('toggles').style.width = 'calc(' + gutterEndPercentX + '% + 20px)';
document.getElementById('gutter').style.left = gutterEndPercentX + '%';
document.getElementById('image-container').style.marginLeft = 'calc(' + gutterEndPercentX + '% + 50px)';
imgHoverRule.style.width = gutterEndPercentX + '%';
// prevent text from being selected during drag
clearSelection();
}
function clearSelection() {
if (window.getSelection) {
if (window.getSelection().empty) {
// Chrome
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) {
// Firefox
window.getSelection().removeAllRanges();
}
} else if (document.selection) {
// IE?
document.selection.empty();
}
}
function teasePartition() {
tempStyle = document.createElement('style');
tempStyle.id = 'teaseDragStyle';
document.head.appendChild(tempStyle);
tempStylesheet = tempStyle.sheet;
// apply temporary rules
window.setTimeout(function() {
tempStylesheet.insertRule('#gutter div { '
+ 'animation-name: gutter_tease;'
+ 'animation-duration: 800ms;'
+ 'animation-timing-function: ease-out;'
+ 'animation-iteration-count: 1;'
+ 'animation-direction: forward;'
+ '}', 0);
},1000);
window.setTimeout(function() {
document.getElementById('teaseDragStyle').remove();
},2000);
}
function editTagsClicked(clickedImageItem) {
if(storingAccessType == 'none') {
alertNoStoringAccess(0);
} else {
let indicatorEl = clickedImageItem.querySelector('.art_edit span');
if(indicatorEl.textContent == '✍️') {
let artistWasInEditMode = editTagsFindArtistInEditMode(clickedImageItem);
if(!artistWasInEditMode) {
doAlert('Read help ⁉️ first',1);
}
editTagsEnterEditMode(clickedImageItem);
} else {
editTagsFindArtistInEditMode();
}
}
}
function editTagsEnterEditMode(imageItem) {
// enter edit mode for item
let indicatorEl = imageItem.querySelector('.art_edit span');
indicatorEl.textContent = '❌';
let tagArea = imageItem.querySelector('h4');
tagArea.title = '';
tagArea.classList.add('edit_mode');
imageItem.classList.add('edit_mode');
let firstN = imageItem.querySelector('.firstN').textContent;
let lastN = imageItem.querySelector('.lastN').textContent;
let tagList = [];
for (let i=0, il=artistsData.length; i<il; i++) {
let artist = artistsData[i];
if(artist[0] == lastN && artist[1] == firstN) {
let tagListStr = artist[2].replace(/\|added-(\d|-)*/g,'');
tagList = tagListStr.split('|');
tagList.unshift(artist[3]);
break;
}
}
tagArea.textContent = '';
for (var i=0, il=tagList.length; i<il; i++) {
addTagToEditor(tagArea,tagList[i]);
}
var adder = document.createElement('input');
adder.type = 'text';
adder.name = 'new_tag';
adder.placeholder = 'add another tag';
adder.dataset.match = '';
adder.style.marginTop = '10px';
tagArea.appendChild(adder);
// add event listeners
adder.addEventListener('focus', function(e) {
var helper = document.createElement('span');
helper.id = 'edit_mode_helper';
this.parentNode.appendChild(helper);
});
adder.addEventListener('keyup', function(e) {
searchForTags(this,e,tagList);
});
adder.addEventListener('blur', function(e) {
this.value = '';
window.setTimeout(function() {
// need delay to allow helper row to be clicked
if(document.getElementById('edit_mode_helper')) {
document.getElementById('edit_mode_helper').remove();
}
}, 100);
});
}
function editTagsFindArtistInEditMode(clickedImageItem) {
let imageItems = document.querySelectorAll('.image-item');
imageItems.forEach(function(imageItem) {
if(imageItem !== clickedImageItem) {
// for any other other artist in editing mode, exit
let indicatorEl = imageItem.querySelector('.art_edit span');
if(indicatorEl.textContent == '❌') {
editTagsExitEditMode(imageItem);
// let caller know that an artistWasInEditMode
return true;
}
}
});
}
function editTagsExitEditMode(imageItem) {
// exit item edit mode for item
let indicatorEl = imageItem.querySelector('.art_edit span');
indicatorEl.textContent = '✍️';
let tagArea = imageItem.querySelector('h4');
tagArea.title = 'copy to clipboard';
tagArea.classList.remove('edit_mode');
imageItem.classList.remove('edit_mode');
let tagList = '';
let tagLabels = tagArea.querySelectorAll('label');
tagLabels.forEach(function(label) {
let input = label.querySelector('input');
if(input.checked && input.value != 'known' && input.value != 'unknown') {
tagList += input.value + ', ';
label.remove();
}
});
tagArea.querySelector('input').remove();
tagArea.textContent = tagList.substring(0,tagList.length-2);
}
function addTagToEditor(tagArea, tagName) {
var label = document.createElement('label');
var input = document.createElement('input');
input.type = 'checkbox';
if(tagName === true || tagName === false) {
input.name = 'known'
input.value = 'known';
// in db, true = hide unknown, but here true = known
if(tagName) {
input.checked = false;
} else {
input.checked = true;
}
tagName = 'known to SDXL'
} else {
input.name = tagName
input.value = tagName;
input.checked = true;
}
var span = document.createElement('span');
span.textContent = tagName;
label.appendChild(input);
label.appendChild(span);
tagArea.appendChild(label);
// event listener
input.addEventListener('change', function(e) {
saveTagsForArtist(tagArea);
});
}
function searchForTags(input, event, tagList) {
if(input.dataset.match != '') {
event.preventDefault();
if(event.key === 'Backspace' || event.keyCode === 8) {
input.value = '';
input.dataset.match = '';
} else if (event.key === 'Return' || event.keyCode === 13) {
input.value = '';
input.dispatchEvent(new Event('blur'));
insertTag(input,input.dataset.match);
input.dataset.match = '';
} else {
input.value = input.dataset.match;
}
return;
}
let helper = document.getElementById('edit_mode_helper');
helper.innerHTML = '';
let matches = 0;
let match = '';
let range = 'start'
let tagsConcatenatedArray = Array.from(tagsConcatenated);
for(i=0,il=tagsConcatenatedArray.length; i<il; i++) {
let tag = tagsConcatenatedArray[i];
for (var j=0, jl=tagList.length; j<jl; j++) {
if(typeof tagList[i] == 'string') {
// first tagList item is boolean
if(tag.toLowerCase() == tagList[i].toLowerCase()) {
break;
}
}
}
if(tag.toLowerCase().indexOf(input.value.toLowerCase()) > -1) {
range = 'continue';
let matchSpan = document.createElement('span');
matchSpan.textContent = tag;
helper.appendChild(matchSpan);
matchSpan.addEventListener('click', function(e) {
insertTag(e.target,e.target.textContent);
});
match = tag;
matches++;
} else {
if(range != 'start') {
range = 'stop';
}
}
if(range == 'stop') {
break;
}
}
if(matches == 1) {
input.value = match;
event.preventDefault();
input.dataset.match = match;
}
}
function insertTag(matchSpan,tag) {
let tagArea = matchSpan.closest('h4');
let input = tagArea.querySelector('input[type="text"]');
addTagToEditor(tagArea,tag);
tagArea.appendChild(input);
document.getElementById('edit_mode_helper').remove();
saveTagsForArtist(tagArea);
timer = setTimeout(focusInput.bind(this, input), 100);
}
function focusInput(input) {
input.focus();
}
function saveTagsForArtist(tagArea) {
// get new tags
let tagLabels = tagArea.querySelectorAll('label');
let newTagsArr = [];
let artistKnown = true;
tagLabels.forEach(function(label) {
let input = label.querySelector('input');
if(input.value == 'known') {
artistKnown = input.checked;
} else {
if(input.checked) {
newTagsArr.push(input.value);
}
}
});
// find match in artistsData
let firstN = tagArea.closest('.image-item').querySelector('.firstN').textContent;
let lastN = tagArea.closest('.image-item').querySelector('.lastN').textContent;
let edit = [];
for (let i=0, il=artistsData.length; i<il; i++) {
let artist = artistsData[i];
if(artist[0] == lastN && artist[1] == firstN) {
// artists can have a tag in the format of "added-YYYY-MM-DD"
// this was stripped earlier, so we need to add it back in
let oldTagsArr = artist[2].split('|');
for (let j=oldTagsArr.length-1; j>=0; j--) {
// loop backwards because it should be at the end
if(oldTagsArr[j].match(/added-(\d|-)*/)) {
newTagsArr.push(oldTagsArr[j]);
}
}
let newTagsStr = newTagsArr.join('|');
artist[2] = newTagsStr;
// in db, true = hide unknown, but here true = known
if(artistKnown) {
artist[3] = false;
} else {
artist[3] = true;
}
edit = artist;
break;
}
}
// replace old edits with new edits
for (let i=0, il=editedArtists.length; i<il; i++) {
let oldEdit = editedArtists[i];
if(edit[0] == oldEdit[0] && edit[1] == oldEdit[1]) {
editedArtists.delete(oldEdit);
}
}
editedArtists.add(edit)
// save edited artists locally
storeItemBasedOnAccessType('editedArtists',Array.from(editedArtists),false,false);
}
function deleteAllEdits() {
if(storingAccessType != 'none') {
if(confirm('This will delete all of your edits. Are you sure?')) {
deleteItemBasedOnAccessType('editedArtists');
alert('official database restored! this page will reload...');
location.reload();
} else {
alert('restore was cancelled!');
}
}
}
function promptBuilderAddArtist(isStart) {
let ogPart = document.querySelector('.prompt_artist');
let part = ogPart.cloneNode(true);
document.querySelector('#prompt_artist_add').before(part);
let input = part.querySelector('.prompt_artist_name input');
input.value = '';
delete input.dataset.match;
delete input.dataset.isPhoto;
input.addEventListener('focus', function(e) {
this.dataset.hasFocus = 'yes';
setXPosOfSearchOutput();
});
input.addEventListener('keyup', function(e) {
promptBuilderSearch(this,e);
});
input.addEventListener('blur', function(e) {
// need to give time for search result row click event
timer = setTimeout(promptBuilderBlur.bind(this, this), 100);
if(this.dataset.match === undefined) {
this.value = '';
}
});
let intensity = part.querySelector('.prompt_artist_intensity select');
intensity.selectedIndex = 'x1';
intensity.addEventListener('change', function(e) {
writePrompt();
});
let combine = part.querySelector('.prompt_artist_combine select');
combine.selectedIndex = 'mix';
combine.addEventListener('change', function(e) {
writePrompt();
});
let remove = part.querySelector('.prompt_artist_remove');
remove.addEventListener('click', function(e) {
promptBuilderRemoveArtist(this);
writePrompt();
});
let left = part.querySelector('.prompt_artist_left');
left.addEventListener('click', function(e) {
promptBuilderMove(this.parentNode,'left');
writePrompt();
});
let right = part.querySelector('.prompt_artist_right');
right.addEventListener('click', function(e) {
promptBuilderMove(this.parentNode,'right');
writePrompt();
});
if(isStart) {
// start copies then removes the HTML part so that
// the event listeners don't need defined twice in the code
ogPart.remove();
}
updatePromptBuilderParts();
writePrompt();
}
function promptBuilderBlur(input) {
delete input.dataset.hasFocus;
document.getElementById('prompt_artist_search').classList.remove('show');
writePrompt();
}
function updatePromptBuilderParts() {
let count = 1;
let parts = Array.from(document.querySelectorAll('.prompt_artist'));
if(parts.length == 1) {
let part = parts[0];
let intensity = part.querySelector('.prompt_artist_intensity');
let combine = part.querySelector('.prompt_artist_combine');
let left = part.querySelector('.prompt_artist_left');
let right = part.querySelector('.prompt_artist_right');
let remove = part.querySelector('.prompt_artist_remove');
intensity.style.display = 'none';
combine.style.display = 'none';
left.style.display = 'none';
right.style.display = 'none';
remove.style.display = 'none';
} else {
for(i=0,il=parts.length; i<il; i++) {
let part = parts[i];
let countEl = part.querySelector('.prompt_artist_count div');
let intensity = part.querySelector('.prompt_artist_intensity');
let combine = part.querySelector('.prompt_artist_combine');
let left = part.querySelector('.prompt_artist_left');
let right = part.querySelector('.prompt_artist_right');
let remove = part.querySelector('.prompt_artist_remove');
countEl.textContent = count;
count++;
intensity.style.display = '';
combine.style.display = '';
left.style.display = '';
right.style.display = '';
remove.style.display = '';
if(i==0) {
left.style.display = 'none';
combine.style.display = 'none';
if(il==1) {
right.style.display = 'none';
}
} else if(i==il-1) {
right.style.display = 'none';
}
}
}
}
function promptBuilderMove(part,direction) {
if(direction == 'left') {
part.previousElementSibling.before(part);
} else if(direction == 'right') {
part.nextElementSibling.after(part);
}
updatePromptBuilderParts();
}
function promptBuilderRemoveArtist(removeButton) {
if(removeButton.textContent.trim() == 'X') {
removeButton.textContent = 'again';
timer = setTimeout(cleanupRemoveButton.bind(this, removeButton), 1000);
} else {
removeButton.parentNode.remove();
updatePromptBuilderParts();
}
}
function cleanupRemoveButton(removeButton) {
removeButton.textContent = 'X';
}
function promptBuilderFillArtist(item,e) {
var name = item.closest('.image-item').getElementsByClassName('firstN')[0].textContent +
' ' + item.closest('.image-item').getElementsByClassName('lastN')[0].textContent;
let inputs = Array.from(document.querySelectorAll('.prompt_artist_name input'));
for(i=0,il=inputs.length; i<il; i++) {
if(inputs[i].value == '') {
inputs[i].value = name;
promptBuilderSearch(inputs[i],e);
break;
}
}
}
function promptBuilderHide() {
document.querySelector('#prompt_builder').classList.remove('show');
}
function promptBuilderShow() {
document.querySelector('#prompt_builder').classList.add('show');
}
function promptBuilderSearch(input,event) {
if(input.dataset.match !== undefined) {
event.preventDefault();
if(event.key === 'Backspace' || event.keyCode === 8) {
input.value = '';
delete input.dataset.match;
delete input.dataset.isPhoto;
} else {
input.value = input.dataset.match;
}
} else {
let matches = 0;
let output = document.getElementById('prompt_artist_search');
output.innerHTML = '';
let match = '';
let isPhoto = false;
for(i=0,il=artistsData.length; i<il; i++) {
let artistName = artistsData[i][1] + ' ' + artistsData[i][0];
if(artistName.toLowerCase().indexOf(input.value.toLowerCase()) > -1) {
let outputRow = document.createElement('div');
outputRow.textContent = artistName;
outputRow.addEventListener('click', function(e) {
let input = document.querySelector('input[data-has-focus="yes"]');
input.value = this.textContent;
promptBuilderSearch(input,e);
input.focus();
});
output.appendChild(outputRow);
matches++;
match = artistName;
if(artistsData[i][2].toLowerCase().indexOf('photography') > -1) {
isPhoto = true;
}
}
}
if(matches == 0) {
let noneFound = document.createElement('div');
noneFound.textContent = 'no matching names';
output.appendChild(noneFound);
} else if(matches == 1) {
input.value = match;
event.preventDefault();
input.dataset.match = match;
if(isPhoto) {
input.dataset.isPhoto = 'yes';
} else {
input.dataset.isPhoto = 'no';
}
output.classList.remove('show');
writePrompt();
} else {
output.classList.add('show');
promptBuilderSearchSortOutput(output);
}
}
}
function setXPosOfSearchOutput() {
let input = document.querySelector('.prompt_artist input:focus');
if(input) {
let output = document.getElementById('prompt_artist_search');
let xPos = input.getBoundingClientRect().left;
output.style.left = xPos + 'px';
}
}
function promptBuilderSearchSortOutput(output) {
let rows = Array.from(output.querySelectorAll('div'));
rows.sort(function(a, b) {
var aValue = a.textContent;
var bValue = b.textContent;
return aValue.localeCompare(bValue);
});
rows.forEach(function(row) {
output.appendChild(row);
});
}
function writePrompt() {
let prompt = '';
let edited = true;
let editable = document.querySelector('#prompt_result_editable').textContent.trim();
let editMe = ['you can edit me','pick an artist, then edit me',''];
if(editable == editMe[0] || editable == editMe[1] || editable == editMe[2]) {
edited = false;
}
let parts = Array.from(document.querySelectorAll('.prompt_artist'));
let nextCombine = 'start';
let startAt = 0;
let missingName = false;
if(parts.length == 1) {
let part = parts[0];
let name = part.querySelector('input').value;
if(name == '') {
missingName = true;
}
let style = promptStyleWords[0];
let isPhoto = part.querySelector('input').dataset.isPhoto;
if(isPhoto == 'yes') {
style = promptStyleWords[1];
}
if(name != '') {
prompt = style + ' ' + name;
}
} else {
for(pCount=1,pLength=parts.length; pCount<pLength; pCount++) {
// i starts at 1 because first part's combine value is ignored
let part = parts[pCount];
let thisCombine = part.querySelector('.prompt_artist_combine select').value;
if(parts[pCount+1]) {
if(nextCombine == 'start') {
nextCombine = parts[pCount+1].querySelector('.prompt_artist_combine select').value;
}
} else {
nextCombine = 'end';
}
if(thisCombine != nextCombine || nextCombine == 'end' || thisCombine == 'swap') {
if(thisCombine == 'loop') {
prompt = '[' + prompt;
} else if(thisCombine == 'swap') {
prompt = '[' + prompt;
}
// loop through artists with matching combine
for(j=startAt,jl=pCount+1; j<jl; j++) {
part = parts[j];
let name = part.querySelector('input').value;
if(name == '') {
missingName = true;
break;
}
let style = promptStyleWords[0];
let isPhoto = part.querySelector('input').dataset.isPhoto;
if(isPhoto == 'yes') {
style = promptStyleWords[1];
}
let intensityNum = parseInt(part.querySelector('.prompt_artist_intensity select').value);
// repeat based on intensity
for(k=0,kl=intensityNum; k<kl; k++) {
if(thisCombine == 'add') {
prompt += style + ' ' + name + ',';
} else if(thisCombine == 'loop') {
prompt += style + ' ' + name + '|';
} else if(thisCombine == 'swap') {
prompt += style + ' ' + name + ',';
}
}
if(thisCombine == 'swap') {
prompt = prompt.substring(0,prompt.length-1);
prompt += ':';
}
}
prompt = prompt.substring(0,prompt.length-1);
if(thisCombine == 'loop') {
prompt += ']'
} else if(thisCombine == 'swap') {
prompt += ':0.5]'
}
startAt = pCount;
}
}
}
if(missingName) {
// no artists are selected
if(!edited) {
editable = editMe[1];
}
prompt = '<span id="prompt_result_editable" contenteditable="true">' + editable + '</span>';
} else {
// 1 or more artists selected
if(!edited) {
editable = editMe[0];
}
prompt = formatPrompt(prompt);
prompt = '<span><b>(</b>' + prompt + '<b>:1.5)</b></span>, ' +
'<span><b>(</b>an image<b>:0.5)</b>, </span>' +
'<span><b>(</b><span id="prompt_result_editable" contenteditable="true">' + editable + '</span><b>:1.0)</b></span>';
}
document.querySelector('#prompt_result div').innerHTML = prompt;
document.getElementById('prompt_result_editable').addEventListener('blur', function(e) {
let str = this.innerText;
this.innerHTML = str;
});
}
function formatPrompt(prompt) {
let promptArr = [];
let style = promptStyleWords[0];
if(prompt.indexOf(promptStyleWords[0]) > -1 && prompt.indexOf(promptStyleWords[1]) < 0) {
// prompt contains only non-photographers
// so use the style words for st
promptArr = prompt.split(promptStyleWords[0]);
/*
} else if(prompt.indexOf(promptStyleWords[0]) < 0 && prompt.indexOf(promptStyleWords[1]) > -1) {
// prompt contains only photographers
promptArr = prompt.split(promptStyleWords[1]);
style = promptStyleWords[1];
*/
} else {
// prompt contains only both photographers and non
// using the shorter prompt event though it makes the style weaker
// because it uses for fewer tokens for multiple artists
let regStr = new RegExp(promptStyleWords[0],'g');
prompt = prompt.replace(regStr,promptStyleWords[1]);
promptArr = prompt.split(promptStyleWords[1]);
style = promptStyleWords[1];
}
if(promptArr.length > 0) {
prompt = style + ' ';
for(i=0,il=promptArr.length; i<il; i++) {
prompt += promptArr[i];
}
}
prompt = prompt.replace('|||','');
prompt = prompt.replace(/\[ |\[/g,'<i>[</i>');
prompt = prompt.replace(/\| |\|/g,'<i>|</i>');
prompt = prompt.replace(/: |:/g,'<i>:</i>');
prompt = prompt.replace(/]/g,'<i>]</i>');
return prompt;
}
function checkMissingInterval() {
// if the broken image is cached, the error event won't fire
// so we periodically check naturalHeight
// if 0, the image is broken and make it prettier
let images = document.querySelectorAll('.img');
images.forEach(function(img) {
if(img.alt !== undefined) {
// because alt is added async
let str = 'Missing image >>> ';
if(img.naturalHeight == 0) {
if(img.alt.indexOf(str) < 0) {
img.alt = str + img.alt;
img.classList.add('missing');
}
} else {
img.alt = img.alt.replace(str,'');
img.classList.remove('missing');
}
}
})
}
function debouncer(func, delay) {
let debounceTimer;
return function() {
const context = this;
const args = arguments;
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => func.apply(context, args), delay);
};
}
/*
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
*/
function addAllListeners() {
// global
document.addEventListener('keydown', function(event) {
if(event.key === 'Escape' || event.keyCode === 27) {
// event.key for modern browsers, event.keyCode for older ones
enterExitEditMostUsedMode('exit');
editTagsFindArtistInEditMode();
hideInfo();
}
});
document.addEventListener('keyup', function(event) {
if(event.key === '/') {
showInfo();
showInformation('actions');
}
});
document.querySelector('#layout').addEventListener('click', function(e) {
if(informationMode) {
e.preventDefault();
if(!e.target.closest('#information')) {
hideInfo();
}
}
});
// checkboxes
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(function(checkbox) {
let isTop = checkbox.parentNode.classList.contains('top_control');
if(!isTop || checkbox.name == 'favorite') {
// normal checkboxes
checkbox.addEventListener('change', function(e) {
checkAllInCategory(e.target);
hideAllArtists();
unhideBasedOnPermissiveSetting();
updateTags('click');
hideLowCountSingle(e.target);
});
} else {
// top checkboxes
if(checkbox.name == 'check-all') {
checkbox.addEventListener('change', function(e) {
checkOrUncheckAll(this.checked);
storeCheckboxStateAll(this.checked);
hideAllArtists();
unhideBasedOnPermissiveSetting();
updateTags('click');
});
} else if(checkbox.name == 'mode') {
checkbox.addEventListener('change', function(e) {
uncheckedAllStrictMode(this.checked);
hideAllArtists();
unhideBasedOnPermissiveSetting();
updateTags('permissivenessClick');
});
} else if(checkbox.name == 'use_categories') {
checkbox.addEventListener('change', function(e) {
showHideCategories();
sortTags();
});
} else if(checkbox.name == 'low_count') {
checkbox.addEventListener('change', function(e) {
showHideLowCountTags();
});
} else if(checkbox.name == 'deprecated') {
checkbox.addEventListener('change', function(e) {
hideAllArtists();
unhideBasedOnPermissiveSetting();
updateTags('click');
});
} else if(checkbox.name == 'nudity') {
checkbox.addEventListener('change', function(e) {
blurUnblurNudity();
});
}
}
// all checkboxes
checkbox.addEventListener('change', function(e) {
styleLabelToCheckbox(this);
clearSelection();
storeCheckboxState(e.target);
window.setTimeout(function() {
updateArtistsImgSrc(false,false);
})
});
});
// information
var options_info = document.getElementById('options_info');
options_info.addEventListener('click', function(e) {
showInfo();
showInformation('actions');
e.stopPropagation();
});
var info_actions = document.getElementById('info_actions');
info_actions.addEventListener('click', function(e) {
showInformation('actions');
});
var info_help = document.getElementById('info_help');
info_help.addEventListener('click', function(e) {
showInformation('help');
});
var info_tips = document.getElementById('info_tips');
info_tips.addEventListener('click', function(e) {
showInformation('tips');
});
var info_about = document.getElementById('info_about');
info_about.addEventListener('click', function(e) {
showInformation('about');
});
var info_export = document.getElementById('info_export');
info_export.addEventListener('click', function(e) {
showInformation('export');
});
var info_closer = document.getElementById('info_closer');
info_closer.addEventListener('click', function(e) {
hideInfo();
});
var info_search = document.getElementById('info_search_input')
info_search.addEventListener('keyup', function(e) {
searchForTagsInfo(e);
});
var infoToggleAll = document.getElementById('info-toggle-all');
infoToggleAll.addEventListener('click', function(e) {
let checkAll = document.querySelector('input[name="check-all"]');
if(checkAll.checked) {
checkAll.checked = false;
} else {
checkAll.checked = true;
}
checkAll.dispatchEvent(new Event('change'));
});
var copyAllNames = document.getElementById('copy-all-names');
copyAllNames.addEventListener('click', function(e) {
copyStuffToClipboard(this, 'copyAllNames')
});
var randomTags = document.getElementById('random-tags');
randomTags.addEventListener('click', function(e) {
searchShowRandomTags();
});
var export_favorites = document.getElementById('export_favorites_button');
export_favorites.addEventListener('click', function(e) {
exportTextarea('favorites');
});
var import_favorites = document.getElementById('import_favorites_button');
import_favorites.addEventListener('click', function(e) {
importFavorites();
});
var export_edits = document.getElementById('export_edits_button');
export_edits.addEventListener('click', function(e) {
exportTextarea('edits');
});
var delete_edits = document.getElementById('delete_edits_button');
delete_edits.addEventListener('click', function(e) {
deleteAllEdits();
});
var export_artists = document.getElementById('export_artists_button');
export_artists.addEventListener('click', function(e) {
exportTextarea('artists');
});
// prompts
/*
var promptA = document.getElementById('promptA');
promptA.addEventListener('click', function(e) {
highlightSelectedOption('promptA');
rotatePromptsImages();
storeOptionsState();
});
var promptP = document.getElementById('promptP');
promptP.addEventListener('click', function(e) {
highlightSelectedOption('promptP');
rotatePromptsImages();
storeOptionsState();
});
var promptL = document.getElementById('promptL');
promptL.addEventListener('click', function(e) {
highlightSelectedOption('promptL');
rotatePromptsImages();
storeOptionsState();
});
*/
// sorting
var sortTA = document.getElementById('sortTA');
sortTA.addEventListener('click', function(e) {
sortTagsByAlpha();
highlightSelectedOption('sortTA');
storeOptionsState();
});
var sortTC = document.getElementById('sortTC');
sortTC.addEventListener('click', function(e) {
sortTagsByCount();
highlightSelectedOption('sortTC');
storeOptionsState();
});
var sortAA = document.getElementById('sortAA');
sortAA.addEventListener('click', function(e) {
sortArtistsByAlpha();
window.setTimeout(function() {
updateArtistsImgSrc(false,false);
})
highlightSelectedOption('sortAA');
storeOptionsState();
});
var sortAR = document.getElementById('sortAR');
sortAR.addEventListener('click', function(e) {
sortArtistsByRandom();
window.setTimeout(function() {
updateArtistsImgSrc(false,false);
})
highlightSelectedOption('sortAR');
storeOptionsState();
});
// second model selector
let secondModelSelector = document.querySelector('#second_model select');
secondModelSelector.addEventListener('change', function(e) {
setSecondModelSelected(this);
blurUnblurNudity();
});
// most used mode
var mostUsed = document.getElementById('edit_most_used');
mostUsed.addEventListener('click', function(e) {
enterExitEditMostUsedMode();
});
var labels = document.querySelectorAll('label');
Array.from(labels).forEach(function(label) {
let name = label.querySelector('input').name;
if(name != 'favorite') {
// favorite can't be removed from most used
label.addEventListener('click', function(e) {
if(editMostUsedMode) {
addRemoveIsMostUsed(this);
storeMostUsedState(this);
}
});
}
});
// artists
var imageItems = document.getElementsByClassName('image-item');
Array.from(imageItems).forEach(function(imageItem) {
imageItem.addEventListener('mouseenter', function(e) {
let imgTime = new Date;
let imgHoverTime = imgTime.getTime();
if(imgHoverTime > startUpTime + 1000) {
// this gives time for the startup animation to finish
hideToggles();
showLargerImages(e.target);
timer = setTimeout(hideLargerImageBackup.bind(this, this), 200);
}
});
imageItem.addEventListener('mouseleave', function(e) {
showToggles();
hideLargerImages(e.target);
});
imageItem.querySelector('.art_star').addEventListener('click', function(e) {
addOrRemoveFavorite(this.closest('.image-item'));
storeFavoriteState(this.closest('.image-item'));
updateFavoritesCount();
});
imageItem.querySelector('.art_prev').addEventListener('click', function(e) {
highlightSelectedOption('prev');
rotatePromptsImages();
storeOptionsState();
});
imageItem.querySelector('.art_next').addEventListener('click', function(e) {
highlightSelectedOption('next');
rotatePromptsImages();
storeOptionsState();
});
imageItem.querySelector('.art_edit').addEventListener('click', function(e) {
editTagsClicked(this.closest('.image-item'));
});
imageItem.querySelector('.art_set').addEventListener('click', function() {
rotateModelsImages();
blurUnblurNudity();
});
imageItem.getElementsByTagName('h3')[0].addEventListener('click', function(e) {
copyStuffToClipboard(this,'name');
promptBuilderFillArtist(this,e);
});
imageItem.getElementsByTagName('h4')[0].addEventListener('click', function(e) {
if(!this.classList.contains('edit_mode')) {
copyStuffToClipboard(this, 'tags')
// toggleCensored(this);
// toggleThisArtistsTags(this.textContent);
}
});
});
// gutter
var gutter = document.getElementById('gutter');
gutter.addEventListener('mousedown', function(e) {
e.preventDefault();
gutterStartPosX = this.offsetLeft;
mouseStartPosX = e.pageX;
this.addEventListener('mousemove', movePartition, false);
window.addEventListener('mouseup', function() {
gutter.removeEventListener('mousemove', movePartition, false);
}, false);
}, false);
// prompt builder
var prompt_builder = document.getElementById('prompt_builder');
prompt_builder.addEventListener('click', function(e) {
promptBuilderShow();
});
var prompt_builder_hide = document.getElementById('prompt_builder_hide');
prompt_builder_hide.addEventListener('click', function(e) {
promptBuilderHide();
e.stopPropagation();
});
var prompt_result_copy = document.getElementById('prompt_result_copy');
prompt_result_copy.addEventListener('click', function(e) {
copyStuffToClipboard(null,'prompt');
});
var prompt_artist_add = document.getElementById('prompt_artist_add');
prompt_artist_add.addEventListener('click', function(e) {
promptBuilderAddArtist();
});
var prompt_selector_div = document.querySelector('#prompt_selector > div');
prompt_selector_div.addEventListener('scroll', debouncer(function() {
setXPosOfSearchOutput();
}, 100));
// lazy loader
var rows = document.querySelector('#rows');
rows.addEventListener('scroll', debouncer(function() {
lazyLoad();
}, 50));
} |