library.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ---
  2. layout: default
  3. ---
  4. <script>
  5. // Main Library-printing function
  6. function printLibrary(sheet) {
  7. const store = new SteinStore(
  8. "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
  9. );
  10. const backendUrl = "/api/get_rules";
  11. var rules = "";
  12. fetch(backendUrl, {
  13. method: 'GET',
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. // Add any other headers you may need, such as authorization headers
  17. },
  18. }).then(response => {
  19. if (!response.ok) {
  20. throw new Error('Network response was not ok');
  21. }
  22. return response.json(); // This returns another Promise
  23. }).then(data => {
  24. libHTML = "";
  25. rules = JSON.parse(data.rules)
  26. // console.log(JSON.parse(rules))
  27. // iterating over all the rules
  28. for (var i = 0; i < rules.length; i++) {
  29. libHTML += "<div class='library-item'>\n";
  30. // icon if there is one
  31. var icon = rules[i]["icon"];
  32. var iconHTML = "";
  33. if (icon != null) {
  34. iconHTML = "<span class='icon'><img src='" + icon + "' /></span>";
  35. }
  36. // first the titles
  37. var title = rules[i]["name"];
  38. if (title == null) { title = "Untitled"; }
  39. libHTML += "<h2 class='library-rule-name'>" +
  40. "<a href='/create/?r=" + rules[i]["rule_id"] + "'>" + iconHTML +
  41. title + "</a></h2>\n";
  42. // then the authors
  43. var author = rules[i]["creatorName"];
  44. if (author != null) {
  45. libHTML += "<div class='library-rule-author'>" + author + "</div>";
  46. }
  47. // then the structures
  48. var structure = rules[i]["summary"];
  49. if (structure != null) {
  50. libHTML += "<p class='library-rule-structure'>" + structure;
  51. libHTML += "</p>\n\n";
  52. }
  53. // then the modules
  54. var modulesRaw = rules[i]["modules"];
  55. try {
  56. var modulesRaw = JSON.parse(modulesRaw)
  57. // console.log(modulesRaw)
  58. if (modulesRaw != null || modulesRaw != undefined) {
  59. libHTML += "<div class='library-module-list modules__grid'>";
  60. var modulesDOM = document.createElement("DIV");
  61. modulesDOM.innerHTML = "<div>" + modulesRaw + "</div>";
  62. var modules = modulesDOM.getElementsByClassName("module");
  63. for (var x = 0; x < modules.length; x++) {
  64. var moduleName = modules[x].children.item("module-name").innerHTML;
  65. libHTML += "<div class='module library-module'>" +
  66. moduleName + "</div>\n";
  67. }
  68. moduleName + "</div>\n";
  69. }
  70. } catch {
  71. }
  72. libHTML += "</div>\n</div>\n";
  73. }
  74. libHTML += "</div>\n";
  75. document.getElementById("librarylist").innerHTML = libHTML;
  76. console.log(libHTML)
  77. });
  78. }
  79. // allows for using alt sheets
  80. var source = "";
  81. window.onload = function () {
  82. printLibrary('rules');
  83. }
  84. </script>
  85. <article class="post">
  86. <header class="post-header">
  87. <h1 class="post-title">{{ page.title }}</h1>
  88. </header>
  89. <div class="post-content">
  90. {{ content }}
  91. <div id="librarylist">
  92. </div>
  93. </div>
  94. </article>