This repository was archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
116 lines (110 loc) · 2.98 KB
/
index.js
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
// 创建一个URL模板数组,其中 {{content}} 是占位符
const searchEngines = [
{
url: "https://cn.bing.com/search?q={{content}}",
name: "Bing",
isSelected: true,
},
{
url: "https://www.google.com/search?q={{content}}",
name: "Google",
isSelected: true,
},
{
url: "https://www.baidu.com/s?wd={{content}}",
name: "百度",
isSelected: true,
},
{
url: "https://search.bilibili.com/all?keyword={{content}}",
name: "Bilibili",
isSelected: true,
},
{
url: "https://www.zhihu.com/search?type=content&q={{content}}",
name: "知乎",
isSelected: true,
},
{
url: "https://www.xiaohongshu.com/search_result?keyword={{content}}&source=unknown",
name: "小红书",
isSelected: true,
},
{
url: "https://kaifa.baidu.com/searchPage?wd={{content}}",
name: "百度开发者",
isSelected: true,
},
{
url: "https://so.csdn.net/so/search?q={{content}}&t=all&u=",
name: "CSDN",
isSelected: true,
},
{
url: "https://www.jianshu.com/search?q={{content}}&page=1&type=note",
name: "简书",
isSelected: true,
},
{
url: "https://github.com/search?q={{content}}&type=repositories",
name: "GitHub",
isSelected: true,
},
{
url: "https://www.loc.gov/collections/world-digital-library/?q={{content}}",
name: "LOC World Digital Library",
isSelected: true,
},
{
url: "https://www.fastsoso.cc/search?k={{content}}",
name: "Fastsoso网盘搜索",
isSelected: true,
},
{
url: "https://zh.annas-archive.org/search?index=&page=1&q={{content}}&sort=",
name: "书籍搜索-安娜的档案",
isSelected: true,
},
{
url: "https://www.pdfdrive.com/search?q={{content}}&pagecount=&pubyear=&searchin=&em=",
name: "书籍搜索-pdfDrive",
isSelected: true,
},
];
window.onload = function () {
// 渲染搜索列表
const searchList = document.getElementById("search-list");
searchEngines.forEach((url) => {
/**
* 每一项创建成一个多选框,并绑定事件
*
*/
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = url.isSelected;
checkbox.id = `checkbox-${url.name}`;
checkbox.addEventListener("change", function () {
url.isSelected = this.checked;
});
const label = document.createElement("label");
label.htmlFor = `checkbox-${url.name}`;
label.textContent = url.name;
const li = document.createElement("li");
li.appendChild(checkbox);
li.appendChild(label);
searchList.appendChild(li);
});
};
function startSearch() {
const contentAll = document.getElementById("text").value;
const selectedEngines = searchEngines.filter((engine) => engine.isSelected);
for (let content of contentAll.split("\n")) {
if (content.trim() === "") {
continue;
}
selectedEngines.forEach((engine) => {
let url = engine.url.replace("{{content}}", encodeURIComponent(content));
window.open(url);
});
}
}