uweb 1.0.49 to use s2ta.js instead of hash2textarea.js

This commit is contained in:
James Feng Cao 2024-07-01 19:54:24 +08:00
parent 093a4ef3ff
commit 9d005633c8
13 changed files with 87 additions and 57 deletions

View file

@ -176,6 +176,16 @@ You should have received a copy of the GNU General Public License along with thi
loadJSFile(tab,jsF);
});
}
function cbNavigate(e){
let url = e.url;
if(58===url.charCodeAt(1)){
e.preventDefault();
if(confirm("Proceed to execute risky operations: "+url))
internalLink(url);
else
document.forms[0].q.value = url;
}
}
function cbFinishLoad(e){
let tab = e.target;
let url = tab.getURL();
@ -202,6 +212,7 @@ You should have received a copy of the GNU General Public License along with thi
tab.allowpopups = true;
tab.addEventListener('did-finish-load',cbFinishLoad);
tab.addEventListener('did-start-loading',cbStartLoading);
tab.addEventListener('will-navigate',cbNavigate);
}
function newTab(){
var tab = document.createElement('webview');
@ -472,7 +483,6 @@ You should have received a copy of the GNU General Public License along with thi
return;
}
if(58===c1){
console.log(q)
internalLink(q);
return;
}
@ -541,9 +551,53 @@ You should have received a copy of the GNU General Public License along with thi
})();
}
}
case 48: //i:00
let iColon = url.indexOf(':',5);
let endS;
let is = url.indexOf('%s',iColon+1);
if(is<0)
endS = '%s"\n';
else
endS = '"\n';
let pname = path.join(__dirname,"search.json");
let str = '"'+url.slice(4,iColon)+'":"'+url.substring(iColon+1)+
endS;
jsonAppend(pname,125,str);
default:
}
}
}
async function jsonAppend(filePath, charcode, str){
let fd;
try{
fd = await fs.promises.open(filePath, 'r+');
}catch(e){
try {
fd = await fs.promises.open(filePath, 'w+');
}catch(e1){return}
}
try{
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;
position--;
}
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)}
}
function autocomplete(inp,container,arr) {
var currentFocus;
function clickItem(e){inp.value = arr[e.target.dataset.index];}

View file

@ -681,27 +681,3 @@ function translate(str){
if(translateRes && (result=translateRes[str])) return result;
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)}
}