aboutsummaryrefslogtreecommitdiff
path: root/index.html
blob: e5e1af4209d7881eca96798c3ac17aa6fb8defbd (plain) (blame)
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
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>💻 Windows XP All Editions Universal Product Keys Collection</title>

    <style>
      body {
        font-family:
          -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
          sans-serif;
        line-height: 1.6;
        max-width: 900px;
        margin: 0 auto;
        padding: 2rem;
        color: #24292e;
      }

      img {
        max-width: 100%;
        height: auto;
      }

      h1 {
        border-bottom: 1px solid #eaecef;
        padding-bottom: 0.3em;
      }

      h2 {
        border-bottom: 1px solid #eaecef;
        padding-bottom: 0.3em;
      }

      ul {
        padding-left: 2em;
      }

      li {
        font-family: monospace;
      }

      p {
        margin: 1em 0;
      }

      #search {
        width: 100%;
        padding: 0.75rem;
        font-size: 1rem;
        border: 1px solid #ddd;
        border-radius: 6px;
        margin-bottom: 1.5rem;
        box-sizing: border-box;
      }

      #search:focus {
        outline: none;
        border-color: #0366d6;
        box-shadow: 0 0 0 3px rgba(3, 102, 214, 0.1);
      }

      .no-results {
        color: #666;
        font-style: italic;
      }
    </style>
  </head>

  <body>
    <div id="content"></div>

    <script type="module">
      const markdownBoldToHtml = (text) =>
        text.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");

      const keysData = await fetch("./keys.json").then((response) =>
        response.json(),
      );
      const { header, footer } = keysData.content;

      const render = (searchQuery = "") => {
        const normalizedQuery = searchQuery.toLowerCase().trim();

        const textContainsQuery = (text) =>
          normalizedQuery === "" ||
          text.toLowerCase().includes(normalizedQuery);

        const editionsMarkup = Object.values(keysData.editions)
          .map((edition) => {
            const editionNameMatchesQuery = textContainsQuery(edition.name);

            const categoriesMarkup = Object.values(edition.categories)
              .map((category) => {
                const categoryNameMatchesQuery = textContainsQuery(
                  category.name,
                );
                const matchingKeys = category.keys.filter(
                  (key) =>
                    textContainsQuery(key) ||
                    categoryNameMatchesQuery ||
                    editionNameMatchesQuery,
                );

                if (!matchingKeys.length) return "";

                const categoryHeading =
                  category.name !== "Default"
                    ? `<h2>${category.name}</h2>`
                    : "";
                const keysListMarkup = `<ul>${matchingKeys.map((key) => `<li>${key}</li>`).join("")}</ul>`;

                return categoryHeading + keysListMarkup;
              })
              .join("");

            return categoriesMarkup
              ? `<h1>${edition.name}</h1>${categoriesMarkup}`
              : "";
          })
          .join("");

        const noResultsMessage =
          normalizedQuery && !editionsMarkup
            ? `<p class="no-results">No keys found matching "${searchQuery}"</p>`
            : "";

        document.getElementById("content").innerHTML = `
          <p><img src="${header.logo}" alt="Windows XP Logo"></p>
          <p>${header.intro}</p>
          <p>${header.description}</p>
          <p><img src="${header.setup_image}" alt="Windows XP Setup"></p>
          <input type="text" id="search" placeholder="Search keys or sections ..." value="${searchQuery}">
          ${editionsMarkup}
          ${noResultsMessage}
          <h1>${footer.title}</h1>
          <p>${markdownBoldToHtml(footer.vol_explanation)}</p>
          <p>${markdownBoldToHtml(footer.vlk_explanation)}</p>
          <p>${footer.license_info}</p>
        `;

        const searchInput = document.getElementById("search");

        searchInput.addEventListener("input", (event) =>
          render(event.target.value),
        );
        searchInput.focus();
        searchInput.setSelectionRange(searchQuery.length, searchQuery.length);
      };

      render();
    </script>
  </body>
</html>