Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
82 lines (81 loc) · 2.02 KB
/
Copy pathindex.html
File metadata and controls
82 lines (81 loc) · 2.02 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Quick Search</title>
<script>
// Define patterns first for immediate availability
const PATTERNS = [
{ pattern: /^gh(?:\s+)?(.*)/, url: "https://github.com/search?q=$1" },
{
pattern: /^npm(?:\s+)?(.*)/,
url: "https://www.npmjs.com/search?q=$1",
},
{
pattern: /^mdn(?:\s+)?(.*)/,
url: "https://developer.mozilla.org/search?q=$1",
},
];
// Execute search immediately
(function () {
const searchParam = new URLSearchParams(window.location.search).get(
"q"
);
if (searchParam) {
for (const { pattern, url } of PATTERNS) {
const match = searchParam.match(pattern);
if (match) {
window.location.href = url.replace(
"$1",
encodeURIComponent(match[1] || "")
);
return;
}
}
}
})();
</script>
<style>
#patterns {
padding: 5rem 2rem;
width: 100%;
box-sizing: border-box;
}
table {
border-collapse: collapse;
max-width: 50rem;
margin: auto;
width: 100%;
}
td,
th {
border: 1px solid #ddd;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<div id="patterns"></div>
<script>
// Only execute if we haven't redirected
const table = document.createElement("table");
table.innerHTML = `
<tr>
<th>Pattern</th>
<th>URL Template</th>
</tr>
${PATTERNS.map(
({ pattern, url }) => `
<tr>
<td>${pattern.toString()}</td>
<td>${url}</td>
</tr>
`
).join("")}
`;
document.getElementById("patterns").appendChild(table);
</script>
</body>
</html>