| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>Cards</title> |
| <style> |
| html{ |
| font-family: system-ui, sans-serif; |
| } |
| |
| #cards{ |
| display: flex; |
| flex-wrap: wrap; |
| gap: 0.5em; |
| } |
| .card{ |
| width: 256px; |
| height: 384px; |
| background-size: cover; |
| background-position: center; |
| position: relative; |
| overflow: hidden; |
| box-shadow: 2px 2px 3px rgba(0,0,0,0.5); |
| cursor: pointer; |
| background-color: #575757; |
| } |
| |
| .card .cardname{ |
| padding: 0.5em; |
| background-color: rgba(0,0,0,0.65); |
| box-shadow: 0px 0px 10px 10px rgba(0,0,0,0.65); |
| color: white; |
| } |
| |
| .card .cardbottom{ |
| padding: 0.5em; |
| position: absolute; |
| bottom: 0; |
| left: 0; |
| right: 0; |
| background-color: rgba(0,0,0,0.65); |
| box-shadow: 0px 0px 10px 10px rgba(0,0,0,0.65); |
| color: white; |
| } |
| |
| .card .carddesc{ |
| overflow: hidden; |
| display: -webkit-box; |
| -webkit-line-clamp: 2; |
| line-clamp: 2; |
| -webkit-box-orient: vertical; |
| } |
| |
| .topctl{ |
| display: inline-block; |
| margin: 0 3em 0 0; |
| } |
| |
| #tags{ |
| display: flex; |
| flex-wrap: wrap; |
| gap: 0.5em; |
| margin: 0.5em 0; |
| } |
| |
| #tags .tag{ |
| border: 1px solid #ccc; |
| padding: 0.25em 0.5em; |
| cursor: pointer; |
| user-select: none; |
| } |
| |
| #tags .tag.enable{ |
| color: white; |
| background: green; |
| } |
| |
| #tags .tag.disable{ |
| color: white; |
| background: red; |
| } |
| |
| .order-options{ |
| display: inline-block; |
| } |
| |
| .pagination { |
| margin: 0.5em 0; |
| } |
| |
| .pagination span{ |
| padding: 0.25em 0.5em; |
| user-select: none; |
| margin: 0.15em 0; |
| display: inline-block; |
| } |
| |
| .pagination span.active{ |
| border: 1px solid #ccc; |
| cursor: pointer; |
| } |
| |
| #cardview{ |
| position: fixed; |
| margin: 2em; |
| padding: 0 2em; |
| } |
| |
| #cardview .cardview{ |
| margin: 4em 0em 2em 0; |
| height: 100%; |
| } |
| |
| ::backdrop { |
| background-image: linear-gradient( 65deg, black, #3e3e3e, #133e40, black ); |
| opacity: 0.90; |
| } |
| |
| #cardviewDownload{ |
| display: flex; |
| align-items: center; |
| justify-content: center; |
| } |
| |
| .dlhere{ |
| font-size: 64pt; |
| font-weight: bold; |
| color: #b5b5b5; |
| } |
| |
| .dlmsg{ |
| text-align: center; |
| font-size: 85%; |
| color: #555; |
| } |
| |
| .closebutton{ |
| position: fixed; |
| right: 4.5em; |
| top: 3.5em; |
| display: block; |
| color: white; |
| background: #b76666; |
| border: none; |
| padding: 0.5em 0.6em; |
| cursor: pointer; |
| } |
| |
| .closebutton:hover{ |
| background: #c77676; |
| } |
| |
| .cardinfo .header{ |
| font-size: 120%; |
| text-decoration: underline; |
| margin: 1.75em 0 0.5em 0; |
| } |
| |
| .cardinfo .notes{ |
| padding: 1em; |
| } |
| |
| .cardinfo .aitext{ |
| font-family: monospace, monospace; |
| padding: 1em; |
| border: 2px solid #ccc; |
| } |
| |
| .modal-open { |
| overflow: initial; |
| } |
| |
| .load-all-loading{ |
| font-style: italic; |
| } |
| |
| |
| </style> |
| <script src="html/cards.js"></script> |
| <script src="html/cardsmeta.js"></script> |
| <script> |
| cardsPerPage = 60 |
| currentPage = 0 |
| |
| function setup(){ |
| document.getElementById('loadedCardsCount').textContent = cards.length |
| |
| var tagsDiv = document.getElementById('tags') |
| |
| for(var tag of tags){ |
| let tagDiv = document.createElement('DIV') |
| tagDiv.innerText = tag[0] |
| tagDiv.classList.add('tag') |
| tagsDiv.appendChild(tagDiv) |
| |
| tagDiv.addEventListener('click', function(){ |
| if(tagDiv.classList.contains('enable')){ |
| tagDiv.classList.remove('enable'); |
| tagDiv.classList.add('disable'); |
| } else if(tagDiv.classList.contains('disable')){ |
| tagDiv.classList.remove('disable'); |
| } else{ |
| tagDiv.classList.add('enable'); |
| } |
| |
| update() |
| }); |
| } |
| } |
| |
| var currentSort = ""; |
| var currentFilter = ""; |
| var filteredCards = null; |
| |
| function createPages(pagesDiv){ |
| pagesDiv.innerHTML='' |
| |
| var totalPages = Math.floor(filteredCards.length / cardsPerPage) |
| if(currentPage >= totalPages) currentPage = totalPages - 1 |
| if(currentPage < 0) currentPage = 0 |
| |
| var addedEllipsisBefore = false; |
| var addedEllipsisAfter = false; |
| |
| var add = function(text, className){ |
| var elem = document.createElement('SPAN') |
| elem.classList.add(className) |
| elem.innerText = text |
| pagesDiv.appendChild(elem) |
| pagesDiv.appendChild(document.createTextNode(' ')) |
| |
| return elem; |
| } |
| |
| for(let i=0; i<totalPages; i++){ |
| var skip = true; |
| |
| if(i<3) skip = false; |
| if(i+3>=totalPages) skip = false; |
| if(i>=currentPage-8 && i<currentPage+8+1) skip = false; |
| |
| if(skip){ |
| if (i < currentPage && !addedEllipsisBefore){ |
| add('...', 'inactive') |
| addedEllipsisBefore = true |
| } |
| if (i > currentPage && !addedEllipsisAfter){ |
| add('...', 'inactive') |
| addedEllipsisAfter = true |
| } |
| |
| continue; |
| } |
| |
| button = add(i+1, i==currentPage ? 'inactive' : 'active') |
| button.addEventListener('click', function(){ |
| currentPage = i |
| update() |
| window.scrollTo(0,0) |
| }); |
| } |
| } |
| |
| |
| function createCard(card){ |
| var cardDiv = document.createElement('DIV') |
| cardDiv.style.backgroundImage = "url('cards/" + card.id[0] + "/" + card.id + ".png')" |
| cardDiv.classList.add('card') |
| |
| var cardTitle = document.createElement('DIV') |
| cardTitle.innerText = card.name |
| cardTitle.classList.add('cardname') |
| cardDiv.appendChild(cardTitle) |
| |
| var cardBottom = document.createElement('DIV') |
| cardBottom.classList.add('cardbottom') |
| cardDiv.appendChild(cardBottom) |
| |
| var cardDesc = document.createElement('DIV') |
| cardDesc.innerText = card.creator_notes |
| cardDesc.classList.add('carddesc') |
| cardBottom.appendChild(cardDesc) |
| |
| return cardDiv |
| } |
| |
| function update(){ |
| var sortBy = document.querySelector('input[name="sortby"]:checked').value; |
| var sortAsc = (document.querySelector('input[name="sortorder"]:checked').value == "ascending"); |
| var sortKey = sortBy + "-" + sortAsc; |
| |
| if(sortKey != currentSort){ |
| currentSort = sortKey; |
| |
| var compare = function(a, b){ |
| var aa = a[sortBy]; |
| var bb = b[sortBy]; |
| if (aa < bb) { |
| return sortAsc ? -1 : 1; |
| } if (aa > bb) { |
| return sortAsc ? 1 : -1; |
| } |
| |
| return 0; |
| } |
| |
| cards.sort(compare) |
| filteredCards = null; |
| } |
| |
| var enabledTags = {} |
| var disabledTags = {} |
| var searchTags = 0 |
| for(var elem of document.querySelectorAll('#tags .tag')){ |
| if(elem.classList.contains('enable')){ |
| enabledTags[elem.textContent] = 1 |
| searchTags += 1 |
| } else if(elem.classList.contains('disable')){ |
| disabledTags[elem.textContent] = 1 |
| } |
| } |
| |
| var searchText = document.getElementById('searchEdit').value.toLowerCase() |
| var searchContent = document.getElementById('searchContent').checked |
| var searchAuthor = document.getElementById('searchAuthor').checked |
| |
| var newFilter = searchText + "|" + searchContent + "|" + searchAuthor + "|" + JSON.stringify(enabledTags) + "|" + JSON.stringify(disabledTags); |
| |
| if (filteredCards == null || currentFilter != newFilter){ |
| currentFilter = newFilter |
| |
| filteredCards = cards.filter(function(card){ |
| if(searchText != ""){ |
| if(searchAuthor){ |
| if(card.creator.toLowerCase().indexOf(searchText) == -1) return false; |
| } else if (searchContent){ |
| var found = false; |
| for(var field of ["creator_notes", "description", "first_mes", "mes_example", "scenario", "name"]){ |
| if(card[field].toLowerCase().indexOf(searchText) != -1){ |
| found = true; |
| break; |
| } |
| } |
| |
| if(! found) return false; |
| } else{ |
| if(card.name.toLowerCase().indexOf(searchText) == -1) return false; |
| } |
| } |
| |
| var matches = 0; |
| |
| for(var tag of card.tags){ |
| if(disabledTags[tag]) return false; |
| if(searchTags && enabledTags[tag]) matches += 1; |
| } |
| |
| if(searchTags == matches) return true; |
| |
| return false; |
| }); |
| } |
| |
| createPages(document.getElementById('pages')) |
| createPages(document.getElementById('pagesAfter')) |
| |
| var cardsDiv = document.getElementById('cards') |
| cardsDiv.innerHTML='' |
| |
| for(var index=0; index<cardsPerPage;index++){ |
| let cardIndex = currentPage * cardsPerPage + index |
| let card = filteredCards[cardIndex] |
| if(! card) return |
| |
| var cardDiv = createCard(card) |
| cardsDiv.appendChild(cardDiv) |
| |
| cardDiv.addEventListener('click', function(){ |
| var cardview = document.getElementById('cardview') |
| |
| var cardPlaceholder = document.getElementById('cardviewCard'); |
| cardPlaceholder.innerHTML = '' |
| cardPlaceholder.appendChild(createCard(card)) |
| cardPlaceholder.href = "cards/" + card.id[0] + "/" + card.id + ".png" |
| |
| var content = document.getElementById('cardviewContent'); |
| content.innerHTML = '' |
| |
| var addSection = function(style, title, text){ |
| var sectionHeader = document.createElement('DIV') |
| sectionHeader.innerText = title |
| sectionHeader.classList.add('header') |
| content.appendChild(sectionHeader) |
| |
| var sectionContent = document.createElement('DIV') |
| sectionContent.innerText = text |
| sectionContent.classList.add(style) |
| content.appendChild(sectionContent) |
| } |
| |
| addSection('notes', card.name, card.tags.join(", ")) |
| addSection('notes', "Creator's notes - by" + card.creator, card.creator_notes) |
| addSection('notes', "Metadata", |
| "Created: " + card.created_at + "\n" + |
| "Updated: " + card.updated_at + "\n" + |
| "Messages: " + card.messages + "\n" + |
| "Chats: " + card.chats + "\n" |
| ) |
| |
| addSection('aitext', "Description", card.description) |
| addSection('aitext', "First message", card.first_mes) |
| addSection('aitext', "Scenario", card.scenario) |
| addSection('aitext', "Message examples", card.mes_example) |
| |
| |
| cardview.showModal() |
| cardview.scrollTo(0, 0) |
| }) |
| } |
| } |
| |
| var updateGeneration = 0; |
| function delayedUpdate(){ |
| var targetGeneration = ++updateGeneration; |
| window.setTimeout(function(){ |
| if(targetGeneration != updateGeneration) return; |
| |
| update() |
| }, 500) |
| } |
| |
| function loadAll(){ |
| var script = document.createElement('script'); |
| script.onload = function () { |
| document.querySelector('.load-options').style.display='none'; |
| currentSort = ""; |
| update(); |
| }; |
| |
| document.querySelector('.load-all-button').style.display='none'; |
| document.querySelector('.load-all-loading').textContent="Loading..."; |
| |
| document.head.appendChild(script); |
| script.src = 'html/allcards.js'; |
| } |
| |
| document.addEventListener("DOMContentLoaded", function(){ |
| setup(); |
| update(); |
| }); |
| |
| </script> |
| </head> |
| <body> |
|
|
| <meta charset="utf8"> |
|
|
| <div id="filter"> |
| <div id="topcontrols"> |
| <div class="topctl search-options"> |
| <input id="searchEdit" type="text" placeholder="Search..." onkeyup="delayedUpdate()" /> |
|
|
| <input type="radio" id="searchTitle" checked="checked" name="searchType" value="Title" onchange="delayedUpdate()"> |
| <label for="searchTitle">Title</label> |
| <input type="radio" id="searchContent" name="searchType" value="Content" onchange="delayedUpdate()"> |
| <label for="searchContent">Content</label> |
| <input type="radio" id="searchAuthor" name="searchType" value="Author" onchange="delayedUpdate()"> |
| <label for="searchAuthor">Author</label> |
| </div> |
|
|
| <div class="topctl sortby-options"> |
| Sort by: |
|
|
| <input type="radio" checked="checked" id="orderPopularity" name="sortby" value="messages" onchange="delayedUpdate()"> |
| <label for="orderPopularity">Popularity</label> |
|
|
| <input type="radio" id="orderName" name="sortby" value="name" onchange="delayedUpdate()"> |
| <label for="orderName">Name</label> |
|
|
| <input type="radio" id="orderCreated" name="sortby" value="created_at" onchange="delayedUpdate()"> |
| <label for="orderCreated">Date</label> |
| </div> |
|
|
| <div class="topctl order-options"> |
| Order: |
| <input type="radio" id="sortAscending" name="sortorder" value="ascending" onchange="delayedUpdate()"> |
| <label for="sortAscending">Ascending</label> |
|
|
| <input type="radio" checked="checked" id="sortDescending" name="sortorder" value="descending" onchange="delayedUpdate()"> |
| <label for="sortDescending">Descending</label> |
| </div> |
|
|
| <div class="topctl load-options"> |
| Loaded: <span id="loadedCardsCount">0</span> |
| <button class="load-all-button" onclick="loadAll()">Load all</button> |
| <span class="load-all-loading"></span> |
| </div> |
| </div> |
|
|
| <div id="tags"></div> |
|
|
| <div id="pages" class="pagination"></div> |
| </div> |
|
|
| <div id="cards"> |
|
|
| </div> |
|
|
| <div id="pagesAfter" class="pagination"></div> |
|
|
| <dialog id="cardview"> |
| <button class="closebutton" onclick="document.getElementById('cardview').close()">🞪</button> |
|
|
| <div class="cardview"> |
|
|
| <div id="cardviewDownload"> |
| <div class="dlhere">⋙</div> |
|
|
| <div> |
| <a id="cardviewCard" target="_blank" download></a> |
| <div class="dlmsg">click image to download</div> |
| </div> |
| <div class="dlhere">⋘</div> |
| </div> |
|
|
| <div class="cardinfo" id="cardviewContent"> |
| </div> |
| </div> |
| </dialog> |
|
|
|
|
| </body> |
| </html> |
|
|