Skip to content

Commit e642f2b

Browse files
committed
first commit
0 parents  commit e642f2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+14469
-0
lines changed

.eslintrc.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": ["eslint:recommended", "plugin:react/recommended"],
7+
"overrides": [],
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"rules": {
13+
"react/react-in-jsx-scope": "off"
14+
},
15+
"ignorePatterns": ["build/**", "build.mjs", "src/utils/is-mobile.mjs"],
16+
"settings": {
17+
"react": {
18+
"version": "detect"
19+
}
20+
}
21+
}

.github/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
commit-message:
8+
prefix: "chore"
9+
include: "scope"

.github/workflows/pr-tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: pr-tests
2+
3+
on:
4+
pull_request:
5+
types:
6+
- "opened"
7+
- "reopened"
8+
- "synchronize"
9+
paths:
10+
- "src/**"
11+
- "build.mjs"
12+
13+
jobs:
14+
tests:
15+
runs-on: ubuntu-22.04
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-node@v3
20+
with:
21+
node-version: 18
22+
- run: npm ci
23+
- run: npm run lint
24+
- run: npm run build
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: pre-release
2+
on:
3+
workflow_dispatch:
4+
# push:
5+
# branches:
6+
# - main
7+
# paths:
8+
# - "src/**"
9+
# - "!src/**/*.json"
10+
# - "build.mjs"
11+
# tags-ignore:
12+
# - "v*"
13+
14+
jobs:
15+
build_and_release:
16+
runs-on: ubuntu-22.04
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
- uses: actions/setup-node@v3
21+
with:
22+
node-version: 18
23+
- run: npm ci
24+
- run: npm run build
25+
26+
- uses: josStorer/get-current-time@v2
27+
id: current-time
28+
with:
29+
format: YYYY_MMDD_HHmm
30+
31+
- uses: actions/upload-artifact@v3
32+
with:
33+
name: Chromium_Build_${{ steps.current-time.outputs.formattedTime }}
34+
path: build/chromium/*
35+
36+
- uses: actions/upload-artifact@v3
37+
with:
38+
name: Firefox_Build_${{ steps.current-time.outputs.formattedTime }}
39+
path: build/firefox/*
40+
41+
- uses: actions/upload-artifact@v3
42+
with:
43+
name: Chromium_Build_WithoutKatex_${{ steps.current-time.outputs.formattedTime }}
44+
path: build/chromium-without-katex/*
45+
46+
- uses: actions/upload-artifact@v3
47+
with:
48+
name: Firefox_Build_WithoutKatex_${{ steps.current-time.outputs.formattedTime }}
49+
path: build/firefox-without-katex/*
50+
51+
- uses: marvinpinto/[email protected]
52+
with:
53+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
54+
automatic_release_tag: "latest"
55+
prerelease: true
56+
title: "Development Build"
57+
files: |
58+
build/chromium.zip
59+
build/firefox.zip
60+
build/chromium-without-katex.zip
61+
build/firefox-without-katex.zip
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import { JSDOM } from 'jsdom'
2+
import fetch, { Headers } from 'node-fetch'
3+
4+
const config = {
5+
google: {
6+
inputQuery: ["input[name='q']"],
7+
sidebarContainerQuery: ['#rhs'],
8+
appendContainerQuery: ['#rcnt'],
9+
resultsContainerQuery: ['#rso'],
10+
},
11+
bing: {
12+
inputQuery: ["[name='q']"],
13+
sidebarContainerQuery: ['#b_context'],
14+
appendContainerQuery: [],
15+
resultsContainerQuery: ['#b_results'],
16+
},
17+
yahoo: {
18+
inputQuery: ["input[name='p']"],
19+
sidebarContainerQuery: ['#right', '.Contents__inner.Contents__inner--sub'],
20+
appendContainerQuery: ['#cols', '#contents__wrap'],
21+
resultsContainerQuery: [
22+
'#main-algo',
23+
'.searchCenterMiddle',
24+
'.Contents__inner.Contents__inner--main',
25+
'#contents',
26+
],
27+
},
28+
duckduckgo: {
29+
inputQuery: ["input[name='q']"],
30+
sidebarContainerQuery: ['.results--sidebar.js-results-sidebar'],
31+
appendContainerQuery: ['#links_wrapper'],
32+
resultsContainerQuery: ['.results'],
33+
},
34+
startpage: {
35+
inputQuery: ["input[name='query']"],
36+
sidebarContainerQuery: ['.layout-web__sidebar.layout-web__sidebar--web'],
37+
appendContainerQuery: ['.layout-web__body.layout-web__body--desktop'],
38+
resultsContainerQuery: ['.mainline-results'],
39+
},
40+
baidu: {
41+
inputQuery: ["input[id='kw']"],
42+
sidebarContainerQuery: ['#content_right'],
43+
appendContainerQuery: ['#container'],
44+
resultsContainerQuery: ['#content_left', '#results'],
45+
},
46+
kagi: {
47+
inputQuery: ["input[name='q']"],
48+
sidebarContainerQuery: ['.right-content-box._0_right_sidebar'],
49+
appendContainerQuery: ['#_0_app_content'],
50+
resultsContainerQuery: ['#main', '#app'],
51+
},
52+
yandex: {
53+
inputQuery: ["input[name='text']"],
54+
sidebarContainerQuery: ['#search-result-aside'],
55+
appendContainerQuery: [],
56+
resultsContainerQuery: ['#search-result'],
57+
},
58+
naver: {
59+
inputQuery: ["input[name='query']"],
60+
sidebarContainerQuery: ['#sub_pack'],
61+
appendContainerQuery: ['#content'],
62+
resultsContainerQuery: ['#main_pack', '#ct'],
63+
},
64+
brave: {
65+
inputQuery: ["input[name='q']"],
66+
sidebarContainerQuery: ['#side-right'],
67+
appendContainerQuery: [],
68+
resultsContainerQuery: ['#results'],
69+
},
70+
searx: {
71+
inputQuery: ["input[name='q']"],
72+
sidebarContainerQuery: ['#sidebar_results', '#sidebar'],
73+
appendContainerQuery: [],
74+
resultsContainerQuery: ['#urls', '#main_results', '#results'],
75+
},
76+
ecosia: {
77+
inputQuery: ["input[name='q']"],
78+
sidebarContainerQuery: ['.sidebar.web__sidebar'],
79+
appendContainerQuery: ['#main'],
80+
resultsContainerQuery: ['.mainline'],
81+
},
82+
neeva: {
83+
inputQuery: ["input[name='q']"],
84+
sidebarContainerQuery: ['.result-group-layout__stickyContainer-iDIO8'],
85+
appendContainerQuery: ['.search-index__searchHeaderContainer-2JD6q'],
86+
resultsContainerQuery: ['.result-group-layout__component-1jzTe', '#search'],
87+
},
88+
}
89+
90+
const urls = {
91+
google: ['https://www.google.com/search?q=hello'],
92+
bing: ['https://www.bing.com/search?q=hello', 'https://cn.bing.com/search?q=hello'],
93+
yahoo: ['https://search.yahoo.com/search?p=hello', 'https://search.yahoo.co.jp/search?p=hello'],
94+
duckduckgo: ['https://duckduckgo.com/s?q=hello'],
95+
startpage: [], // need redirect and post https://www.startpage.com/do/search?query=hello
96+
baidu: ['https://www.baidu.com/s?wd=hello'],
97+
kagi: [], // need login https://kagi.com/search?q=hello
98+
yandex: [], // need cookie https://yandex.com/search/?text=hello
99+
naver: ['https://search.naver.com/search.naver?query=hello'],
100+
brave: ['https://search.brave.com/search?q=hello'],
101+
searx: ['https://searx.tiekoetter.com/search?q=hello'],
102+
ecosia: [], // unknown verify method https://www.ecosia.org/search?q=hello
103+
neeva: [], // unknown verify method(FetchError: maximum redirect reached) https://neeva.com/search?q=hello
104+
}
105+
106+
const commonHeaders = {
107+
Accept:
108+
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
109+
Connection: 'keep-alive',
110+
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7', // for baidu
111+
}
112+
113+
const desktopHeaders = new Headers({
114+
'User-Agent':
115+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/108.0.1462.76',
116+
...commonHeaders,
117+
})
118+
119+
const mobileHeaders = {
120+
'User-Agent':
121+
'Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Mobile Safari/537.36 Edg/108.0.1462.76',
122+
...commonHeaders,
123+
}
124+
125+
const desktopQueryNames = [
126+
'inputQuery',
127+
'sidebarContainerQuery',
128+
'appendContainerQuery',
129+
'resultsContainerQuery',
130+
]
131+
132+
const mobileQueryNames = ['inputQuery', 'resultsContainerQuery']
133+
134+
let errors = ''
135+
136+
async function verify(errorTag, urls, headers, queryNames) {
137+
await Promise.all(
138+
Object.entries(urls).map(([siteName, urlArray]) =>
139+
Promise.all(
140+
urlArray.map((url) =>
141+
fetch(url, {
142+
method: 'GET',
143+
headers: headers,
144+
})
145+
.then((response) => response.text())
146+
.then((text) => {
147+
const dom = new JSDOM(text)
148+
for (const queryName of queryNames) {
149+
const queryArray = config[siteName][queryName]
150+
if (queryArray.length === 0) continue
151+
152+
let foundQuery
153+
for (const query of queryArray) {
154+
const element = dom.window.document.querySelector(query)
155+
if (element) {
156+
foundQuery = query
157+
break
158+
}
159+
}
160+
if (foundQuery) {
161+
console.log(`${siteName} ${url} ${queryName}: ${foundQuery} passed`)
162+
} else {
163+
const error = `${siteName} ${url} ${queryName} failed`
164+
errors += errorTag + error + '\n'
165+
}
166+
}
167+
})
168+
.catch((error) => {
169+
errors += errorTag + error + '\n'
170+
}),
171+
),
172+
),
173+
),
174+
)
175+
}
176+
177+
async function main() {
178+
console.log('Verify desktop search engine configs:')
179+
await verify('desktop: ', urls, desktopHeaders, desktopQueryNames)
180+
console.log('\nVerify mobile search engine configs:')
181+
await verify('mobile: ', urls, mobileHeaders, mobileQueryNames)
182+
183+
if (errors.length > 0) throw new Error('\n' + errors)
184+
else console.log('\nAll passed')
185+
}
186+
187+
main()

.github/workflows/tagged-release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: tagged-release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
7+
jobs:
8+
build_and_release:
9+
runs-on: macos-12
10+
11+
steps:
12+
- run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
13+
- uses: actions/checkout@v3
14+
with:
15+
ref: main
16+
17+
- name: Update manifest.json version
18+
uses: jossef/[email protected]
19+
with:
20+
file: src/manifest.json
21+
field: version
22+
value: ${{ env.VERSION }}
23+
24+
- name: Update manifest.v2.json version
25+
uses: jossef/[email protected]
26+
with:
27+
file: src/manifest.v2.json
28+
field: version
29+
value: ${{ env.VERSION }}
30+
31+
- name: Push files
32+
run: |
33+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
34+
git config --global user.name "github-actions[bot]"
35+
git commit -am "release v${{ env.VERSION }}"
36+
git push
37+
38+
- uses: actions/setup-node@v3
39+
with:
40+
node-version: 18
41+
- run: npm ci
42+
- run: npm run build
43+
44+
- uses: maxim-lobanov/setup-xcode@v1
45+
with:
46+
xcode-version: 14.2
47+
- run: sed -i '' "s/0.0.0/${{ env.VERSION }}/g" safari/project.patch
48+
- run: npm run build:safari
49+
50+
- uses: marvinpinto/[email protected]
51+
with:
52+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
53+
prerelease: false
54+
files: |
55+
build/chromium.zip
56+
build/firefox.zip
57+
build/safari.dmg
58+
build/chromium-without-katex.zip
59+
build/firefox-without-katex.zip

.github/workflows/verify-configs.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: verify-configs
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: "0 6 * * *"
6+
7+
jobs:
8+
verify_configs:
9+
runs-on: ubuntu-22.04
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 16
16+
- run: npm ci
17+
- run: npm run verify

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea/
2+
.vscode/
3+
node_modules/
4+
build/
5+
.DS_Store
6+
*.zip

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
src/manifest.json
3+
src/manifest.v2.json

0 commit comments

Comments
 (0)