From 9acd6f4a243818ce1a1036f12b7fb095d67de4c0 Mon Sep 17 00:00:00 2001 From: James Feng Cao Date: Wed, 19 Jun 2024 21:58:58 +0800 Subject: [PATCH] add search.json --- misc/ebrowser/index.html | 5 ++++- misc/ebrowser/package.json | 14 +++++++------- misc/ebrowser/search.json | 21 +++++++++++++++++++++ misc/ebrowser/webview.js | 17 ++++++++++++----- 4 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 misc/ebrowser/search.json diff --git a/misc/ebrowser/index.html b/misc/ebrowser/index.html index 77ae33be..6eee6dac 100644 --- a/misc/ebrowser/index.html +++ b/misc/ebrowser/index.html @@ -35,7 +35,10 @@ Copyright (C) 2024 Richard Hao Cao let lastKeys_millis = 0; fs.readFile(path.join(__dirname,'search.json'), 'utf8', (err, jsonString) => { - if (err) return; + if (err) { + coloncommand(":js fetch2file(repositoryurl,'search.json')"); + return; + } initSearchEngines(jsonString,false); }); fs.readFile(path.join(__dirname,'mapkeys.json'), 'utf8', (err, jsonStr) => { diff --git a/misc/ebrowser/package.json b/misc/ebrowser/package.json index 88a3d0c9..d6a941a1 100644 --- a/misc/ebrowser/package.json +++ b/misc/ebrowser/package.json @@ -1,7 +1,13 @@ -{"version":"1.0.27", +{"version":"1.0.28", "name": "ebrowser", "description": "The keyboard-friendly minimal suckless web browser", "main": "webview.js", + "files": [ + "webview.js", + "index.html", + "package.json", + "README.md" + ], "scripts": { "release": "electron-builder" }, @@ -16,12 +22,6 @@ "appId": "torapp.eweb", "publish": "github", "asar": false, - "files": [ - "webview.js", - "index.html", - "package.json", - "README.md" - ], "directories": { "output": "release" }, diff --git a/misc/ebrowser/search.json b/misc/ebrowser/search.json new file mode 100644 index 00000000..5b2ca899 --- /dev/null +++ b/misc/ebrowser/search.json @@ -0,0 +1,21 @@ +{ + "b":"https://www.bing.com/search?q=%s", + "bdic":"http://cn.bing.com/dict/search?q=%s", + "ms":"https://metaso.cn?q=%s", + "gc":"https://gitcode.com/aisearch?q=%s", + "ta":"https://thinkany.so/search?q=%s", + "ks":"https://kaisouai.com?q=%s", + "exa":"https://exa.ai/search?c=all&q=%s", + "andi":"https://andisearch.com/?q=%s", + "ph":"https://phind-ai.com/search?q=%s", + "gf":"https://greasyfork.org/en/scripts?filter_locale=0&sort=updated&q=%s", + "dev":"https://devv.ai/search?agentMode=false&q=%s", + "you":"https://you.com/search?tbm=youchat&q=%s", + "p":"https://www.perplexity.ai/?q=%s", + "brave":"https://search.brave.com/search?q=%s", + "g":"https://google.com/search?q=%s", + "git":"https://github.com/search?type=Repositories&q=%s", + "gt":"https://kkgithub.com/search?type=Repositories&q=%s", + "360":"https://so.360.com/s?q=%s", + "bd":"https://m.baidu.com/s?wd=%s" +} diff --git a/misc/ebrowser/webview.js b/misc/ebrowser/webview.js index 28bc78e2..82e7807f 100644 --- a/misc/ebrowser/webview.js +++ b/misc/ebrowser/webview.js @@ -24,6 +24,7 @@ else { } topMenu(); +const repositoryurl = "https://gitlab.com/jamesfengcao/uweb/-/raw/master/misc/ebrowser/"; const fs = require('fs'); const readline = require('readline'); const path = require('path') @@ -188,6 +189,9 @@ function addrCommand(cmd){ else gredirect_disable(); return; + case "js"://exetute js + eval(cmd.slice(4)); + return; case "nc": bForwardCookie = false; msgbox_info("Cookie forwarding disabled"); @@ -232,7 +236,7 @@ function addrCommand(cmd){ case "update": let updateurl; if(1==args.length) - updateurl = "https://gitlab.com/jamesfengcao/uweb/-/raw/master/misc/ebrowser/"; + updateurl = repositoryurl; else { updateurl = args[1]; if(!updateurl.endsWith("/")) updateurl = updateurl +"/"; @@ -579,21 +583,24 @@ async function updateApp(url){//url must ending with "/" }) } -async function fetch2file(urlFolder, filename){ +async function fetch2file(urlFolder, filename, bOverwritten=true){ + let pathname=path.join(__dirname,filename); + if(!bOverwritten && fs.existsSync(pathname)) return; let res = await fetch(urlFolder+filename); let str = await res.text(); - writeFile(filename, str); + writeFile(pathname, str); } async function writeFile(filename, str){ - let pathname=path.join(__dirname,filename+".new"); + let pathname=filename+".new"; fs.writeFile(pathname, str, (err) => { if(err) throw "Fail to write"; - fs.rename(pathname,path.join(__dirname,filename),(e1)=>{ + fs.rename(pathname,filename,(e1)=>{ if(e1) throw "Fail to rename"; }); }); } + function help(){ const readme = "README.md"; const htmlFN = path.join(__dirname,readme+".html");