Compare commits

...

2 commits

Author SHA1 Message Date
James Feng Cao
093a4ef3ff ebrowser v1.0.53 2024-07-01 12:15:39 +08:00
James Feng Cao
5d062edbfa ebrowser v1.0.52 2024-07-01 10:11:01 +08:00
4 changed files with 44 additions and 13 deletions

View file

@ -56,6 +56,7 @@ You should have received a copy of the GNU General Public License along with thi
} }
</style> </style>
<script> <script>
const { ipcRenderer } = require('electron');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const readline = require('readline'); const readline = require('readline');
@ -352,7 +353,7 @@ You should have received a copy of the GNU General Public License along with thi
return se.replace('%s',query); return se.replace('%s',query);
} }
function coloncommand(q){ function coloncommand(q){
document.title = q; ipcRenderer.send("command",q);
} }
function coloncommand_render(cmd){ function coloncommand_render(cmd){
args = cmd.substring(1).split(/\s+/); args = cmd.substring(1).split(/\s+/);
@ -453,6 +454,7 @@ You should have received a copy of the GNU General Public License along with thi
function handleQuery(q){ function handleQuery(q){
if(q.length>1){ if(q.length>1){
let c0=q.charCodeAt(0); let c0=q.charCodeAt(0);
let c1=q.charCodeAt(1);
switch(c0){ switch(c0){
case 33://"!" case 33://"!"
bangcommand(q); bangcommand(q);
@ -462,7 +464,6 @@ You should have received a copy of the GNU General Public License along with thi
tabs.children[iTab].findInPage(q.substring(1)); tabs.children[iTab].findInPage(q.substring(1));
return; return;
case 58://':' case 58://':'
let c1=q.charCodeAt(1);
if(c1>98 && 112!=c1) if(c1>98 && 112!=c1)
coloncommand(q); coloncommand(q);
else else
@ -470,16 +471,18 @@ You should have received a copy of the GNU General Public License along with thi
recQueryHistory(q); recQueryHistory(q);
return; return;
} }
if(58===c1){
console.log(q)
internalLink(q);
return;
}
} }
var url=q; var url=q;
NOREC: do{ NOREC: do{
do { do {
if(q.length>12){ if(q.length>12){
let c6 = q.charCodeAt(6); let c6 = q.charCodeAt(6);
if(58===q.charCodeAt(1)){ if(47===c6){// '/'
internalLink(q);
return;
}else if(47===c6){// '/'
let c5 = q.charCodeAt(5); let c5 = q.charCodeAt(5);
if(47===c5 && 58===q.charCodeAt(4))//http/file urls if(47===c5 && 58===q.charCodeAt(4))//http/file urls
break NOREC; break NOREC;

View file

@ -1,4 +1,4 @@
{"version":"1.0.51", {"version":"1.0.53",
"name": "ebrowser", "name": "ebrowser",
"description": "The keyboard-friendly minimal suckless web browser", "description": "The keyboard-friendly minimal suckless web browser",
"main": "webview.js", "main": "webview.js",

View file

@ -19,10 +19,10 @@
"gt":"https://kkgithub.com/search?type=Repositories&q=%s", "gt":"https://kkgithub.com/search?type=Repositories&q=%s",
"360":"https://so.360.com/s?q=%s", "360":"https://so.360.com/s?q=%s",
"tg":"https://www.tiangong.cn/result?q=%s", "tg":"https://www.tiangong.cn/result?q=%s",
"cg":"i:0/js/hash2textarea.js:https://chatglm.cn/main/detail#%s", "cg":"i:0/js/s2ta.js:https://chatglm.cn/main/detail?%s",
"s100":"i:0/js/hash2input.js:https://www.sou100.com/#%s", "s100":"i:0/js/s2input.js:https://www.sou100.com/?%s",
"csdn":"i:0/js/hash2textarea.js:https://chat.csdn.net#%s", "csdn":"i:0/js/s2ta.js:https://chat.csdn.net?%s",
"bdc":"i:0/js/hash2editable.js:https://chat.baidu.com/#%s", "bdc":"i:0/js/s2editable.js:https://chat.baidu.com/?%s",
"miku":"i:0/js/hash2textarea.js:https://www.hellomiku.com#%s", "miku":"i:0/js/s2ta.js:https://www.hellomiku.com?%s",
"bd":"https://baidu.com/s?wd=%s" "bd":"https://baidu.com/s?wd=%s"
} }

View file

@ -7,7 +7,7 @@ You should have received a copy of the GNU General Public License along with thi
*/ */
const { const {
app, BrowserWindow, Menu, shell, clipboard, app, BrowserWindow, Menu, shell, clipboard,
session, protocol, net, dialog session, protocol, net, dialog, ipcMain
} = require('electron') } = require('electron')
let win; let win;
@ -184,6 +184,10 @@ app.on ('web-contents-created', (event, contents) => {
} }
}); });
ipcMain.on('command', (event, cmd) => {
addrCommand(cmd);
});
function addrCommand(cmd){ function addrCommand(cmd){
if(cmd.length<3) return; if(cmd.length<3) return;
let c0 = cmd.charCodeAt(0); let c0 = cmd.charCodeAt(0);
@ -677,3 +681,27 @@ function translate(str){
if(translateRes && (result=translateRes[str])) return result; if(translateRes && (result=translateRes[str])) return result;
return str; return str;
} }
async function jsonAppend(filePath, charcode, str){
try{
const fd = await fs.promises.open(filePath, 'r+');
const stats = await fd.stat();
const fileSize = stats.size;
const buffer = Buffer.alloc(1);
let position = fileSize-1;
while (position >= 0) {
await fd.read(buffer, 0, 1, position);
if (buffer[0] === charcode) break;
}
let endS = String.fromCharCode(charcode);
if(position<0){//re-write whole file
str = String.fromCharCode(charcode-2)+str+endS;
position = 0;
}else
str = ","+str+endS;
await fd.truncate(position);
const buf = Buffer.from(str);
await fd.write(buf, 0, buf.length, position);
await fd.close();
}catch(e){console.log(e)}
}