Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Mar 15, 2023
0 parents commit e642f2b
Show file tree
Hide file tree
Showing 67 changed files with 14,469 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"react/react-in-jsx-scope": "off"
},
"ignorePatterns": ["build/**", "build.mjs", "src/utils/is-mobile.mjs"],
"settings": {
"react": {
"version": "detect"
}
}
}
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "chore"
include: "scope"
24 changes: 24 additions & 0 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: pr-tests

on:
pull_request:
types:
- "opened"
- "reopened"
- "synchronize"
paths:
- "src/**"
- "build.mjs"

jobs:
tests:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run lint
- run: npm run build
61 changes: 61 additions & 0 deletions .github/workflows/pre-release-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: pre-release
on:
workflow_dispatch:
# push:
# branches:
# - main
# paths:
# - "src/**"
# - "!src/**/*.json"
# - "build.mjs"
# tags-ignore:
# - "v*"

jobs:
build_and_release:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run build

- uses: josStorer/get-current-time@v2
id: current-time
with:
format: YYYY_MMDD_HHmm

- uses: actions/upload-artifact@v3
with:
name: Chromium_Build_${{ steps.current-time.outputs.formattedTime }}
path: build/chromium/*

- uses: actions/upload-artifact@v3
with:
name: Firefox_Build_${{ steps.current-time.outputs.formattedTime }}
path: build/firefox/*

- uses: actions/upload-artifact@v3
with:
name: Chromium_Build_WithoutKatex_${{ steps.current-time.outputs.formattedTime }}
path: build/chromium-without-katex/*

- uses: actions/upload-artifact@v3
with:
name: Firefox_Build_WithoutKatex_${{ steps.current-time.outputs.formattedTime }}
path: build/firefox-without-katex/*

- uses: marvinpinto/[email protected]
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
title: "Development Build"
files: |
build/chromium.zip
build/firefox.zip
build/chromium-without-katex.zip
build/firefox-without-katex.zip
187 changes: 187 additions & 0 deletions .github/workflows/scripts/verify-search-engine-configs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import { JSDOM } from 'jsdom'
import fetch, { Headers } from 'node-fetch'

const config = {
google: {
inputQuery: ["input[name='q']"],
sidebarContainerQuery: ['#rhs'],
appendContainerQuery: ['#rcnt'],
resultsContainerQuery: ['#rso'],
},
bing: {
inputQuery: ["[name='q']"],
sidebarContainerQuery: ['#b_context'],
appendContainerQuery: [],
resultsContainerQuery: ['#b_results'],
},
yahoo: {
inputQuery: ["input[name='p']"],
sidebarContainerQuery: ['#right', '.Contents__inner.Contents__inner--sub'],
appendContainerQuery: ['#cols', '#contents__wrap'],
resultsContainerQuery: [
'#main-algo',
'.searchCenterMiddle',
'.Contents__inner.Contents__inner--main',
'#contents',
],
},
duckduckgo: {
inputQuery: ["input[name='q']"],
sidebarContainerQuery: ['.results--sidebar.js-results-sidebar'],
appendContainerQuery: ['#links_wrapper'],
resultsContainerQuery: ['.results'],
},
startpage: {
inputQuery: ["input[name='query']"],
sidebarContainerQuery: ['.layout-web__sidebar.layout-web__sidebar--web'],
appendContainerQuery: ['.layout-web__body.layout-web__body--desktop'],
resultsContainerQuery: ['.mainline-results'],
},
baidu: {
inputQuery: ["input[id='kw']"],
sidebarContainerQuery: ['#content_right'],
appendContainerQuery: ['#container'],
resultsContainerQuery: ['#content_left', '#results'],
},
kagi: {
inputQuery: ["input[name='q']"],
sidebarContainerQuery: ['.right-content-box._0_right_sidebar'],
appendContainerQuery: ['#_0_app_content'],
resultsContainerQuery: ['#main', '#app'],
},
yandex: {
inputQuery: ["input[name='text']"],
sidebarContainerQuery: ['#search-result-aside'],
appendContainerQuery: [],
resultsContainerQuery: ['#search-result'],
},
naver: {
inputQuery: ["input[name='query']"],
sidebarContainerQuery: ['#sub_pack'],
appendContainerQuery: ['#content'],
resultsContainerQuery: ['#main_pack', '#ct'],
},
brave: {
inputQuery: ["input[name='q']"],
sidebarContainerQuery: ['#side-right'],
appendContainerQuery: [],
resultsContainerQuery: ['#results'],
},
searx: {
inputQuery: ["input[name='q']"],
sidebarContainerQuery: ['#sidebar_results', '#sidebar'],
appendContainerQuery: [],
resultsContainerQuery: ['#urls', '#main_results', '#results'],
},
ecosia: {
inputQuery: ["input[name='q']"],
sidebarContainerQuery: ['.sidebar.web__sidebar'],
appendContainerQuery: ['#main'],
resultsContainerQuery: ['.mainline'],
},
neeva: {
inputQuery: ["input[name='q']"],
sidebarContainerQuery: ['.result-group-layout__stickyContainer-iDIO8'],
appendContainerQuery: ['.search-index__searchHeaderContainer-2JD6q'],
resultsContainerQuery: ['.result-group-layout__component-1jzTe', '#search'],
},
}

const urls = {
google: ['https://www.google.com/search?q=hello'],
bing: ['https://www.bing.com/search?q=hello', 'https://cn.bing.com/search?q=hello'],
yahoo: ['https://search.yahoo.com/search?p=hello', 'https://search.yahoo.co.jp/search?p=hello'],
duckduckgo: ['https://duckduckgo.com/s?q=hello'],
startpage: [], // need redirect and post https://www.startpage.com/do/search?query=hello
baidu: ['https://www.baidu.com/s?wd=hello'],
kagi: [], // need login https://kagi.com/search?q=hello
yandex: [], // need cookie https://yandex.com/search/?text=hello
naver: ['https://search.naver.com/search.naver?query=hello'],
brave: ['https://search.brave.com/search?q=hello'],
searx: ['https://searx.tiekoetter.com/search?q=hello'],
ecosia: [], // unknown verify method https://www.ecosia.org/search?q=hello
neeva: [], // unknown verify method(FetchError: maximum redirect reached) https://neeva.com/search?q=hello
}

const commonHeaders = {
Accept:
'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',
Connection: 'keep-alive',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7', // for baidu
}

const desktopHeaders = new Headers({
'User-Agent':
'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',
...commonHeaders,
})

const mobileHeaders = {
'User-Agent':
'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',
...commonHeaders,
}

const desktopQueryNames = [
'inputQuery',
'sidebarContainerQuery',
'appendContainerQuery',
'resultsContainerQuery',
]

const mobileQueryNames = ['inputQuery', 'resultsContainerQuery']

let errors = ''

async function verify(errorTag, urls, headers, queryNames) {
await Promise.all(
Object.entries(urls).map(([siteName, urlArray]) =>
Promise.all(
urlArray.map((url) =>
fetch(url, {
method: 'GET',
headers: headers,
})
.then((response) => response.text())
.then((text) => {
const dom = new JSDOM(text)
for (const queryName of queryNames) {
const queryArray = config[siteName][queryName]
if (queryArray.length === 0) continue

let foundQuery
for (const query of queryArray) {
const element = dom.window.document.querySelector(query)
if (element) {
foundQuery = query
break
}
}
if (foundQuery) {
console.log(`${siteName} ${url} ${queryName}: ${foundQuery} passed`)
} else {
const error = `${siteName} ${url} ${queryName} failed`
errors += errorTag + error + '\n'
}
}
})
.catch((error) => {
errors += errorTag + error + '\n'
}),
),
),
),
)
}

async function main() {
console.log('Verify desktop search engine configs:')
await verify('desktop: ', urls, desktopHeaders, desktopQueryNames)
console.log('\nVerify mobile search engine configs:')
await verify('mobile: ', urls, mobileHeaders, mobileQueryNames)

if (errors.length > 0) throw new Error('\n' + errors)
else console.log('\nAll passed')
}

main()
59 changes: 59 additions & 0 deletions .github/workflows/tagged-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: tagged-release
on:
push:
tags:
- "v*"

jobs:
build_and_release:
runs-on: macos-12

steps:
- run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
ref: main

- name: Update manifest.json version
uses: jossef/[email protected]
with:
file: src/manifest.json
field: version
value: ${{ env.VERSION }}

- name: Update manifest.v2.json version
uses: jossef/[email protected]
with:
file: src/manifest.v2.json
field: version
value: ${{ env.VERSION }}

- name: Push files
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git commit -am "release v${{ env.VERSION }}"
git push
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run build

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 14.2
- run: sed -i '' "s/0.0.0/${{ env.VERSION }}/g" safari/project.patch
- run: npm run build:safari

- uses: marvinpinto/[email protected]
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
build/chromium.zip
build/firefox.zip
build/safari.dmg
build/chromium-without-katex.zip
build/firefox-without-katex.zip
17 changes: 17 additions & 0 deletions .github/workflows/verify-configs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: verify-configs
on:
workflow_dispatch:
schedule:
- cron: "0 6 * * *"

jobs:
verify_configs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm run verify
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea/
.vscode/
node_modules/
build/
.DS_Store
*.zip
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
src/manifest.json
src/manifest.v2.json
Loading

0 comments on commit e642f2b

Please sign in to comment.