mirror of
https://github.com/torappinfo/uweb.git
synced 2024-08-14 23:54:59 +00:00
ebrowser 1.0.45: sitejs/sitecss support
This commit is contained in:
parent
e28838f738
commit
6fc7d22514
12 changed files with 64 additions and 27 deletions
|
@ -6,6 +6,7 @@ Ebrowser is designed with the philosophy of [Android uweb browser](https://githu
|
|||
- keyboard friendly with vim-style keymaps and command line support in address bar.
|
||||
- [global redirection](https://uweb.surge.sh/en/redirect/index.html#) to bypass censorship.
|
||||
- user scripts at will. Ex. pressing "md" in no-focus mode to preview markdown file.
|
||||
- CSS/JS for domains, similar to [uweb](https://jamesfengcao.gitlab.io/uweb/en/sitejs/index.html), but use sitejs/[domain].js or sitecss/[domain].css, not [domain root].js/css.
|
||||
- customizable.
|
||||
|
||||
Note: Usually electron apps are heavyweight as they use browsers for simple things. Ebrowser uses core chromium effectively and very lightweight. Recommend to install electron separately.
|
||||
|
@ -99,7 +100,7 @@ The other commands are defined in "mapkeys.json", which will map keys to address
|
|||
- "uas.json" : name-useragent pairs
|
||||
|
||||
#### Javascript at three levels
|
||||
- Web page: urls like "javascript:" or bookmarklet command ":bml" run in web page.
|
||||
- Web page: url like "javascript:" or bookmarklet command ":bml" runs in web page.
|
||||
- Browser (or renderer process) :
|
||||
- ":bjs" to execute the following js code at browser level.
|
||||
- "!xx" evaluates "xx.js", which could manipulate address bar etc.
|
||||
|
|
|
@ -69,6 +69,10 @@ You should have received a copy of the GNU General Public License along with thi
|
|||
var historyFile = path.join(__dirname,'history.rec');
|
||||
var bHistory = false;
|
||||
var bQueryHistory = false;
|
||||
let sitecssP = path.join(__dirname,"sitecss");
|
||||
let sitejsP = path.join(__dirname,"sitejs");
|
||||
var bDomainJS = fs.existsSync(sitejsP);
|
||||
var bDomainCSS = fs.existsSync(sitecssP);
|
||||
var autocMode = 0; //0 for substring, 1 for startsWith
|
||||
const BML_head = "(async ()=>{let d=document;async function _loadJs(u){var a=d.createElement('script');a.type='text/javascript';a.async=false;a.src=u;d.body.appendChild(a);await new Promise(resolve=>a.onload=resolve)}";
|
||||
const BML_tail = "})()";
|
||||
|
@ -136,20 +140,52 @@ You should have received a copy of the GNU General Public License along with thi
|
|||
iTab = i;
|
||||
tabs.children[iTab].classList.add('curWV');
|
||||
}
|
||||
async function loadJSFile(tab,jsF){
|
||||
if(fs.existsSync(jsF)){
|
||||
try {
|
||||
let js = await fs.promises.readFile(jsF,'utf8');
|
||||
tab.executeJavaScript(js,false);
|
||||
}catch(e){}
|
||||
}
|
||||
}
|
||||
function cbStartLoading(e){
|
||||
if(!bDomainCSS) return;
|
||||
let tab = e.target;
|
||||
let domain = new URL(tab.getURL()).hostname;
|
||||
let jsF = path.join(sitecssP, domain+".js");
|
||||
loadJSFile(tab,jsF);
|
||||
jsF = path.join(sitecssP, domain+".css");
|
||||
if(fs.existsSync(jsF)){
|
||||
(async ()=>{
|
||||
try {
|
||||
let css = await fs.promises.readFile(jsF,'utf8');
|
||||
tab.insertCSS(css);
|
||||
}catch(e){}
|
||||
})();
|
||||
}
|
||||
}
|
||||
function cbFinishLoad(e){
|
||||
let tab = e.target;
|
||||
let url = tab.getURL();
|
||||
if(bHistory){
|
||||
let histItem = tab.getTitle()+" "+url+"\n";
|
||||
fs.appendFile(historyFile, histItem, (err) => {});
|
||||
}
|
||||
let js = tab.dataset.jsonce;
|
||||
if(js){
|
||||
tab.dataset.jsonce = null;
|
||||
tab.executeJavaScript(js,false);
|
||||
}
|
||||
if(!bHistory) return;
|
||||
let histItem = tab.getTitle()+" "+tab.getURL()+"\n";
|
||||
fs.appendFile(historyFile, histItem, (err) => {});
|
||||
if(bDomainJS){
|
||||
let domain = new URL(url).hostname;
|
||||
let jsF = path.join(sitejsP, domain+".js");
|
||||
loadJSFile(tab,jsF);
|
||||
}
|
||||
}
|
||||
function initTab(tab){
|
||||
tab.allowpopups = true;
|
||||
tab.addEventListener('did-finish-load',cbFinishLoad);
|
||||
tab.addEventListener('did-start-loading',cbStartLoading);
|
||||
}
|
||||
function newTab(){
|
||||
var tab = document.createElement('webview');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{"version":"1.0.44",
|
||||
{"version":"1.0.45",
|
||||
"name": "ebrowser",
|
||||
"description": "The keyboard-friendly minimal suckless web browser",
|
||||
"main": "webview.js",
|
||||
|
|
1
misc/ebrowser/sitecss/baidu.com.css
Normal file
1
misc/ebrowser/sitecss/baidu.com.css
Normal file
|
@ -0,0 +1 @@
|
|||
.ec_wise_ad,.ec_wise_pp,.na-like-container{transform:scale(0)!important;display:none!important}
|
12
misc/ebrowser/sitejs/mypikpak.net.js
Normal file
12
misc/ebrowser/sitejs/mypikpak.net.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
(function() {
|
||||
const originFetch = fetch;
|
||||
window.fetch = (...arg) => {
|
||||
if (arg[0].indexOf('area_accessible') > -1) {
|
||||
return new Promise(() => {
|
||||
throw new Error();
|
||||
});
|
||||
} else {
|
||||
return originFetch(...arg);
|
||||
}
|
||||
}
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue