filter_engines.js (2409B)
1 /* Script for selecting fallback Search Engine ------------------------------ */
2
3 make_fallback = function(selection) {
4
5 // Set a cookie for the selection
6 document.cookie = "fallback=" + selection + ";" +
7 "Max-Age=31536000;" + // 60 x 60 x 24 x 365 = 1 year
8 "Domain=" + document.domain + ";" +
9 "SameSite=Strict;";
10
11 // Set value in searchbar
12 document.querySelector("input[name=fallback]").value = selection;
13
14 // Gather Entries of Search Engines list
15 var entries = document.querySelectorAll("article");
16
17 // Remove pre-existing "Fallback" Markers
18 document.querySelectorAll("#fallback_marker").forEach(
19 function(obj){ obj.remove(); }
20 );
21
22 // Create "Fallback" Marker
23 let marker = document.createElement("mark");
24 marker.id = "fallback_marker";
25 marker.innerText = "#Fallback";
26
27 // Update Search Engines List
28 for (let i = 0; i < entries.length; i++) {
29 if (entries[i].id == selection) {
30 entries[i].classList.add("selected");
31 entries[i].querySelector(".categories").prepend(marker);
32 } else {
33 entries[i].classList.remove("selected");
34 }
35 }
36
37 }
38
39 /* Script to filter through the list of search engines ---------------------- */
40
41 filter_engines = function(bar) {
42
43 // Get text from filter bar
44 var pat = document.getElementById(bar).value.toLowerCase();
45
46 // Gather article objects that contain the search engines
47 var entries = document.querySelectorAll("article");
48
49 // Compare text in article objects with text in filter bar
50 // Mark those hidden that do not match
51 for (let i = 0; i < entries.length; i++) {
52 if (entries[i].innerText.toLowerCase().match(pat) === null) {
53 entries[i].classList.add("hidden");
54 } else {
55 entries[i].classList.remove("hidden");
56 }
57 }
58
59 }
60
61 /* Script to search through search engines via category buttons ------------- */
62
63 filter_category = function(category) {
64
65 // Insert category name into category-filterbar
66 document.getElementById("engines_filterbar").value = "#" + category;
67
68 // collapse category summary
69 document.getElementById("categories").open = false;
70
71 // filter through search engines list
72 filter_engines("engines_filterbar");
73
74 // Scroll back to search bar
75 setTimeout(function() { document.location = "#engines"; }, 10);
76
77 }
78