You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

167 regels
4.4 KiB

  1. <html lang="en" class="notranslate" translate="no">
  2. <head>
  3. <meta name="google" content="notranslate" />
  4. <title><%= title %></title>
  5. <link rel="icon" type="image/png" href="../favicon.png">
  6. <style>
  7. body {
  8. font-family: 'Segoe UI', Arial;
  9. background-color: #aaa;
  10. padding: 0;
  11. margin: 0;
  12. }
  13. .bg-0 {
  14. background-image: url("https://github.com/benc-uk/icon-collection/raw/master/_tools/background.png")
  15. }
  16. .bg-1 {
  17. background-color: #333;
  18. }
  19. .bg-2 {
  20. background-color: #fff;
  21. }
  22. .imgbox img {
  23. width: 10.5rem;
  24. height: 10.5rem;
  25. object-fit: contain;
  26. cursor: pointer;
  27. }
  28. .imgbox {
  29. margin: 0.6rem;
  30. padding: 0.5rem;
  31. text-align: center;
  32. width: 12rem;
  33. height: 12rem;
  34. background-color: #e0e0e0;
  35. }
  36. h1 {
  37. font-size: 1.8rem;
  38. }
  39. .find, .find input {
  40. font-size: 1.1rem;
  41. }
  42. .top {
  43. position: -webkit-sticky;
  44. position: sticky;
  45. top: 0;
  46. background-color: rgb(211, 211, 211);
  47. padding: 0.2rem;
  48. padding-top: 0;
  49. box-shadow: 0px 5px 18px 3px rgba(0,0,0,0.59);
  50. }
  51. .top button {
  52. float: right;
  53. position: absolute;
  54. top: 0.2rem;
  55. right: 0.2rem;
  56. font-size: 1rem;
  57. border-radius: 4px;
  58. }
  59. .pngbox {
  60. position: absolute;
  61. top: 2rem;
  62. right: 1rem;
  63. font-size: 0.9rem;
  64. }
  65. input[type="checkbox"] {
  66. width: 1.6em;
  67. height: 1.6em;
  68. }
  69. .label {
  70. height: 2.5em;
  71. line-height: 1em;
  72. overflow: hidden;
  73. font-size: 0.9rem;
  74. }
  75. .grid {
  76. display: flex;
  77. flex-wrap: wrap;
  78. width: 100%;
  79. }
  80. h1 {
  81. display:inline;
  82. }
  83. .home {
  84. font-size: 2rem;
  85. text-decoration: none;
  86. color:rgb(99, 99, 99);
  87. }
  88. </style>
  89. </head>
  90. <body>
  91. <div class="top">
  92. <a href=".." class="home">&#129093;</a> &nbsp; <h1><%= title %></h1>
  93. <br/>
  94. <span class="find">Finder: <input onkeyup="search()" id="finder">&nbsp; Icons: <span id="count">...</span></span>
  95. <div class="pngbox"><input type="checkbox" id="pngcheck"><label for="pngcheck">Download as PNG</label></div>
  96. <button onclick="toggleBg()">Toggle Background</button>
  97. </div>
  98. <div class="grid">
  99. <% for(let imgFile of images) { %>
  100. <div id="<%= imgFile.toLowerCase() %>" class="imgbox"><img src="<%= imgFile %>" class="bg-0" onclick="download('<%= imgFile %>', this)"/><div class="label"><%= imgFile %></div></div>
  101. <% } %>
  102. </div>
  103. <script>
  104. var bgSetting = 0;
  105. function toggleBg() {
  106. bgSetting++
  107. if(bgSetting > 2) bgSetting = 0;
  108. for(let img of document.getElementsByTagName("img")) {
  109. img.className = `bg-${bgSetting}`;
  110. }
  111. }
  112. function search() {
  113. let query = document.getElementById('finder').value.trim().toLowerCase()
  114. if(query.length <= 0) {
  115. for(let imgbox of document.getElementsByClassName("imgbox")) {
  116. imgbox.style.display = "inline-block"
  117. }
  118. }
  119. for(let imgbox of document.getElementsByClassName("imgbox")) {
  120. imgbox.style.display = "inline-block"
  121. if(!imgbox.id.includes(query)) {
  122. imgbox.style.display = "none"
  123. }
  124. }
  125. }
  126. function download(f, e) {
  127. if(document.getElementById("pngcheck").checked) {
  128. var data = getBase64Image(e);
  129. let a = document.createElement('a')
  130. a.href = "data:application/octet-stream;base64," + data
  131. a.download = f.replace('.svg', '.png')
  132. a.click()
  133. } else {
  134. let a = document.createElement('a')
  135. a.href = f
  136. a.download = f
  137. a.click()
  138. }
  139. }
  140. // Actual magic
  141. function getBase64Image(img) {
  142. var canvas = document.createElement("canvas");
  143. canvas.width = img.naturalWidth;
  144. canvas.height = img.naturalHeight;
  145. console.log(canvas.width , canvas.height)
  146. var ctx = canvas.getContext("2d");
  147. ctx.drawImage(img, 0, 0);
  148. var dataURL = canvas.toDataURL("image/png");
  149. return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
  150. }
  151. function updateCount() {
  152. document.querySelector('#count').innerHTML = ''+document.querySelectorAll(".imgbox").length
  153. }
  154. updateCount()
  155. </script>
  156. </body>
  157. </html>