mirror of
https://github.com/torappinfo/uweb.git
synced 2024-08-14 23:54:59 +00:00
update AI engines
This commit is contained in:
parent
7792c764b2
commit
b2e9cd1d31
20 changed files with 107 additions and 79 deletions
|
@ -99,6 +99,7 @@ The other commands are defined in "mapkeys.json", which will map keys to address
|
|||
- "mapkeys.json": keys-addressbarCommands pairs. The addressbar commands are multiple lines of address bar command separated by "\n".
|
||||
- "proxy.json": name-[ProxyConfig](https://www.electronjs.org/docs/latest/api/structures/proxy-config) pairs
|
||||
- "uas.json" : name-useragent pairs
|
||||
- "menu.json": array of strings for [user-defined menus](https://jamesfengcao.gitlab.io/uweb/en/urls/index.html). The array has submenu name and address bar commands alternately.
|
||||
- "download.json" : array of strings to define buttons for downloading dialog. The even-indexed strings are texts to show on the button. The odd-indexed strings are address bar commands with "%u" as the downloaded url.
|
||||
|
||||
#### Javascript at three levels
|
||||
|
|
|
@ -531,14 +531,16 @@ You should have received a copy of the GNU General Public License along with thi
|
|||
function internalLink(url){
|
||||
let cmd = url.charCodeAt(2);
|
||||
let subcmd = url.charCodeAt(3);
|
||||
let iColon = url.indexOf(':',5);
|
||||
let name = decodeURIComponent(url.slice(4,iColon));
|
||||
let rurl = url.substring(iColon+1);
|
||||
switch(cmd){
|
||||
case 48://'0' i:0
|
||||
switch(subcmd){
|
||||
case 47://'/' i:0/
|
||||
if(106===url.charCodeAt(4) && 115===url.charCodeAt(5) && 47===url.charCodeAt(6)){
|
||||
//i:0/js/xx:[url]
|
||||
let iColon = url.indexOf(':',7);
|
||||
let fname = url.slice(4,iColon);
|
||||
let fname = name;
|
||||
let pname = path.join(__dirname,fname);
|
||||
if(fs.existsSync(pname)){
|
||||
(async ()=>{
|
||||
|
@ -546,7 +548,7 @@ You should have received a copy of the GNU General Public License along with thi
|
|||
let js = await fs.promises.readFile(pname,'utf8');
|
||||
let t=tabs.children[iTab];
|
||||
t.dataset.jsonce=js;
|
||||
t.src = url.substring(iColon+1);
|
||||
t.src = rurl;
|
||||
}catch(e){}
|
||||
})();
|
||||
}
|
||||
|
@ -554,7 +556,6 @@ You should have received a copy of the GNU General Public License along with thi
|
|||
return;
|
||||
case 48: //i:00
|
||||
{
|
||||
let iColon = url.indexOf(':',5);
|
||||
let endS;
|
||||
let is = url.indexOf('%s',iColon+1);
|
||||
if(is<0)
|
||||
|
@ -562,11 +563,19 @@ You should have received a copy of the GNU General Public License along with thi
|
|||
else
|
||||
endS = '"\n';
|
||||
let pname = path.join(__dirname,"search.json");
|
||||
let str = '"'+url.slice(4,iColon)+'":"'+url.substring(iColon+1)+
|
||||
let str = '"'+name+'":"'+rurl+
|
||||
endS;
|
||||
jsonAppend(pname,125,str);
|
||||
}
|
||||
return;
|
||||
case 49: //i:01
|
||||
{
|
||||
let pname = path.join(__dirname,"menu.json");
|
||||
let str = '"'+name+'",":bjs handleQuery(`'+
|
||||
rurl+'${tabs.children[iTab].getURL()}`)"\n';
|
||||
jsonAppend(pname,93,str);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{"version":"1.0.54",
|
||||
{"version":"1.0.56",
|
||||
"name": "ebrowser",
|
||||
"description": "The keyboard-friendly minimal suckless web browser",
|
||||
"main": "webview.js",
|
||||
|
@ -8,9 +8,7 @@
|
|||
"package.json",
|
||||
"README.md",
|
||||
"translate.*",
|
||||
"mapkeys.json",
|
||||
"js/*.js",
|
||||
"config"
|
||||
"js/*.js"
|
||||
],
|
||||
"scripts": {
|
||||
"release": "electron-builder"
|
||||
|
|
|
@ -22,5 +22,6 @@
|
|||
"csdn":"i:0/js/s2ta.js:https://chat.csdn.net?%s",
|
||||
"bdc":"i:0/js/s2editable.js:https://chat.baidu.com/?%s",
|
||||
"miku":"i:0/js/s2ta.js:https://www.hellomiku.com?%s",
|
||||
"fl":"https://felo.ai/search?q=%s",
|
||||
"bd":"https://baidu.com/s?wd=%s"
|
||||
}
|
||||
|
|
|
@ -27,19 +27,20 @@ else {
|
|||
createWindow();
|
||||
})
|
||||
}
|
||||
Menu.setApplicationMenu(null);
|
||||
const fs = require('fs');
|
||||
const path = require('path')
|
||||
var translateRes;
|
||||
{
|
||||
let langs = app.getPreferredSystemLanguages();
|
||||
if(langs.length==0 || langs[0].startsWith('en') || !initTranslateRes(langs[0]))
|
||||
if(langs.length==0 || langs[0].startsWith('en'))
|
||||
topMenu();
|
||||
else
|
||||
Menu.setApplicationMenu(null);
|
||||
initTranslateRes(langs[0]);
|
||||
}
|
||||
|
||||
var repositoryurl = "https://gitlab.com/jamesfengcao/uweb/-/raw/master/misc/ebrowser/";
|
||||
const fs = require('fs');
|
||||
const readline = require('readline');
|
||||
const path = require('path')
|
||||
const process = require('process')
|
||||
var gredirects = [];
|
||||
var gredirect;
|
||||
|
@ -401,8 +402,28 @@ function onContextMenu(event, params){
|
|||
contextMenu.popup();
|
||||
}
|
||||
|
||||
function topMenu(){
|
||||
const menuTemplate = [
|
||||
async function topMenu(){
|
||||
const menuTemplate = [];
|
||||
try {
|
||||
let json = await fs.promises.readFile(path.join(__dirname,'menu.json'), 'utf8');
|
||||
let menus = JSON.parse(json);
|
||||
if(menus.length>1){
|
||||
let submenu = [];
|
||||
for(let i=0;i<menus.length-1; i=i+2){
|
||||
let cmd = menus[i+1];
|
||||
let js = `handleQuery("${cmd}")`;
|
||||
submenu.push({
|
||||
label: menus[i], click: ()=>{
|
||||
win.webContents.executeJavaScript(js,false);
|
||||
}});
|
||||
}
|
||||
menuTemplate.push({
|
||||
label: translate('Tools'),
|
||||
submenu: submenu,
|
||||
});
|
||||
}
|
||||
}catch(e){console.log(e)}
|
||||
menuTemplate.push(
|
||||
{
|
||||
label: translate('Edit'),
|
||||
submenu: [
|
||||
|
@ -498,7 +519,7 @@ if(e)e.blur();try{tabs.children[iTab].stopFindInPage('clearSelection')}catch(er)
|
|||
|
||||
],
|
||||
},
|
||||
];
|
||||
);
|
||||
const menu = Menu.buildFromTemplate(menuTemplate);
|
||||
Menu.setApplicationMenu(menu);
|
||||
}
|
||||
|
@ -649,20 +670,16 @@ function help(){
|
|||
win.webContents.executeJavaScript(js,false)
|
||||
}
|
||||
|
||||
function initTranslateRes(lang){
|
||||
async function initTranslateRes(lang){
|
||||
let basename=path.join(__dirname,"translate.");
|
||||
let fname = basename+lang;
|
||||
if(!fs.existsSync(fname))
|
||||
fname = basename+lang.slice(0,2);
|
||||
if(!fs.existsSync(fname)) return false;
|
||||
(async ()=>{
|
||||
try {
|
||||
let json = await fs.promises.readFile(fname,'utf8');
|
||||
translateRes = JSON.parse(json);
|
||||
} catch (e){}
|
||||
topMenu();
|
||||
})();
|
||||
return true;
|
||||
try {
|
||||
let json = await fs.promises.readFile(fname,'utf8');
|
||||
translateRes = JSON.parse(json);
|
||||
} catch (e){}
|
||||
topMenu();
|
||||
}
|
||||
|
||||
function translate(str){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue