@@ -209,58 +209,71 @@ for (let i = latestMinor + 1; i > latestMinor - 4; i--) {
209209
210210 element.classList.remove("hidden-by-type", "hidden-by-changed", "hidden-by-supported");
211211
212- switch (attribute) {
213- case "type":
214- if (filter.types.length === 0) {
215- return;
216- }
212+ checkType(element);
213+ checkSupported(element);
214+ checkSince(element);
215+ });
216+ }
217+
218+ /**
219+ * Check if the element matches the current type filter.
220+ * @param element The element to check.
221+ */
222+ function checkType(element: Element) {
223+ if (filter.types.length === 0) {
224+ return;
225+ }
217226
218- for (const t of filter.types) {
219- if (element.getAttribute("data-type")?.includes(types[t])) {
220- return;
221- }
222- }
227+ for (const t of filter.types) {
228+ if (element.getAttribute("data-type")?.includes(types[t])) {
229+ return;
230+ }
231+ }
223232
224- element.classList.add("hidden-by-type");
225- break;
226- case "supported":
227- if (filter.supported === "") {
228- return;
229- }
230-
231- const since1 = element.getAttribute("data-since");
232- if (since1 === null) {
233- return;
234- }
235-
236- const minor1 = parseInt(filter.supported.match(/\d+\.(\d+)/)!![1], 10);
237- since1.matchAll(/\d+\.(\d+)/g).forEach((match) => {
238- const otherMinor = parseInt(match[1], 10);
239-
240- if (otherMinor > minor1) {
241- element.classList.add("hidden-by-supported");
242- return;
243- }
244- });
245- break;
246- case "changed":
247- const since = element.getAttribute("data-since");
248- if (since === null) {
249- return;
250- }
251-
252- if (!since.includes(filter.changed)) {
253- element.classList.add("hidden-by-changed");
254- return;
255- }
256- break;
257- default:
258- console.warn(`Unknown filter type: ${button.getAttribute("data-type")}`);
259- return;
233+ element.classList.add("hidden-by-type");
234+ }
235+
236+ /**
237+ * Check if the element matches the current supported filter.
238+ * @param element The element to check.
239+ */
240+ function checkSupported(element: Element) {
241+ if (filter.supported === "") {
242+ return;
243+ }
244+
245+ const since1 = element.getAttribute("data-since");
246+ if (since1 === null) {
247+ return;
248+ }
249+
250+ const minor1 = parseInt(filter.supported.match(/\d+\.(\d+)/)!![1], 10);
251+ since1.matchAll(/\d+\.(\d+)/g).forEach((match) => {
252+ const otherMinor = parseInt(match[1], 10);
253+
254+ if (otherMinor > minor1) {
255+ element.classList.add("hidden-by-supported");
256+ return;
260257 }
261258 });
262259 }
263-
260+
261+ /**
262+ * Check if the element matches the current since filter.
263+ * @param element The element to check.
264+ */
265+ function checkSince(element: Element) {
266+ const since = element.getAttribute("data-since");
267+ if (since === null) {
268+ return;
269+ }
270+
271+ if (!since.includes(filter.changed)) {
272+ element.classList.add("hidden-by-changed");
273+ return;
274+ }
275+ }
276+
264277 /**
265278 * Reset all filter buttons to their default state.
266279 */
@@ -324,8 +337,8 @@ for (let i = latestMinor + 1; i > latestMinor - 4; i--) {
324337 button.addEventListener("click", () => handleClick(button as HTMLButtonElement));
325338 });
326339
327- (buttons[0 ] as HTMLButtonElement).click();
328- (buttons[0 ] as HTMLButtonElement).click();
340+ (buttons[1 ] as HTMLButtonElement).click();
341+ (buttons[1 ] as HTMLButtonElement).click();
329342 });
330343</script >
331344
0 commit comments