ebrowser 1.0.45: sitejs/sitecss support

This commit is contained in:
James Feng Cao 2024-06-29 21:27:48 +08:00
parent e28838f738
commit 6fc7d22514
12 changed files with 64 additions and 27 deletions

View file

@ -60,10 +60,3 @@
- 网页矢量长截屏允许通过mermaid等设计矢量图案。 - 网页矢量长截屏允许通过mermaid等设计矢量图案。
- 可用网页设计代替Adobe Illustrator平面设计。 - 可用网页设计代替Adobe Illustrator平面设计。
- 完全开源,共同探索浏览新技术。 - 完全开源,共同探索浏览新技术。
- nodejs 下安装:
npm install ebrowser
- nodejs 下运行:
electron ~/node_modules/ebrowser

View file

@ -60,10 +60,3 @@
- 网页矢量长截屏允许通过mermaid等设计矢量图案。 - 网页矢量长截屏允许通过mermaid等设计矢量图案。
- 可用网页设计代替Adobe Illustrator平面设计。 - 可用网页设计代替Adobe Illustrator平面设计。
- 完全开源,共同探索浏览新技术。 - 完全开源,共同探索浏览新技术。
- nodejs 下安装:
npm install ebrowser
- nodejs 下运行:
electron ~/node_modules/ebrowser

View file

@ -51,6 +51,7 @@
<li>keyboard friendly with vim-style keymaps and command line support in address bar.</li> <li>keyboard friendly with vim-style keymaps and command line support in address bar.</li>
<li><a href="https://uweb.surge.sh/en/redirect/index.html#">global redirection</a> to bypass censorship.</li> <li><a href="https://uweb.surge.sh/en/redirect/index.html#">global redirection</a> to bypass censorship.</li>
<li>user scripts at will. Ex. pressing &quot;md&quot; in no-focus mode to preview markdown file.</li> <li>user scripts at will. Ex. pressing &quot;md&quot; in no-focus mode to preview markdown file.</li>
<li>CSS/JS for domains, similar to <a href="https://jamesfengcao.gitlab.io/uweb/en/sitejs/index.html">uweb</a>, but use sitejs/[domain].js or sitecss/[domain].css, not [domain root].js/css.</li>
<li>customizable.</li> <li>customizable.</li>
</ul> </ul>
<p>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.</p> <p>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.</p>
@ -149,7 +150,7 @@ npm install ebrowser
</ul> </ul>
<h4 id="javascript-at-three-levels">Javascript at three levels</h4> <h4 id="javascript-at-three-levels">Javascript at three levels</h4>
<ul> <ul>
<li>Web page: urls like &quot;javascript:&quot; or bookmarklet command &quot;:bml&quot; run in web page.</li> <li>Web page: url like &quot;javascript:&quot; or bookmarklet command &quot;:bml&quot; runs in web page.</li>
<li>Browser (or renderer process) : <li>Browser (or renderer process) :
<ul> <ul>
<li>&quot;:bjs&quot; to execute the following js code at browser level.</li> <li>&quot;:bjs&quot; to execute the following js code at browser level.</li>

View file

@ -6,7 +6,7 @@
<description>Recent content on uweb browser: unlimited power</description> <description>Recent content on uweb browser: unlimited power</description>
<generator>Hugo</generator> <generator>Hugo</generator>
<language>en</language> <language>en</language>
<lastBuildDate>Sat, 29 Jun 2024 08:47:08 +0800</lastBuildDate> <lastBuildDate>Sat, 29 Jun 2024 21:05:42 +0800</lastBuildDate>
<atom:link href="/en/index.xml" rel="self" type="application/rss+xml" /> <atom:link href="/en/index.xml" rel="self" type="application/rss+xml" />
<item> <item>
<title>Text selection/processing</title> <title>Text selection/processing</title>
@ -216,7 +216,7 @@
<link>/en/ebrowserreadme/</link> <link>/en/ebrowserreadme/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>/en/ebrowserreadme/</guid> <guid>/en/ebrowserreadme/</guid>
<description>Ebrowser: keyboard-friendly minimal suckless web browser Ebrowser is designed with the philosophy of Android uweb browser (gitlab).&#xA;lightweight (less than 20k bytes) without bundled electron. much less memory footprint than edge/chrome browser and highly performant. keyboard friendly with vim-style keymaps and command line support in address bar. global redirection to bypass censorship. user scripts at will. Ex. pressing &amp;quot;md&amp;quot; in no-focus mode to preview markdown file. customizable. Note: Usually electron apps are heavyweight as they use browsers for simple things.</description> <description>Ebrowser: keyboard-friendly minimal suckless web browser Ebrowser is designed with the philosophy of Android uweb browser (gitlab).&#xA;lightweight (less than 20k bytes) without bundled electron. much less memory footprint than edge/chrome browser and highly performant. keyboard friendly with vim-style keymaps and command line support in address bar. global redirection to bypass censorship. user scripts at will. Ex. pressing &amp;quot;md&amp;quot; in no-focus mode to preview markdown file. CSS/JS for domains, similar to uweb, but use sitejs/[domain].</description>
</item> </item>
<item> <item>
<title></title> <title></title>

View file

@ -71,7 +71,7 @@
/> />
</url><url> </url><url>
<loc>/en/</loc> <loc>/en/</loc>
<lastmod>2024-06-29T08:47:08+08:00</lastmod> <lastmod>2024-06-29T21:05:42+08:00</lastmod>
<xhtml:link <xhtml:link
rel="alternate" rel="alternate"
hreflang="zh" hreflang="zh"
@ -508,7 +508,7 @@
/> />
</url><url> </url><url>
<loc>/en/ebrowserreadme/</loc> <loc>/en/ebrowserreadme/</loc>
<lastmod>2024-06-29T08:47:08+08:00</lastmod> <lastmod>2024-06-29T21:05:42+08:00</lastmod>
</url><url> </url><url>
<loc>/en/mirrors/</loc> <loc>/en/mirrors/</loc>
<lastmod>2024-06-18T23:17:17+08:00</lastmod> <lastmod>2024-06-18T23:17:17+08:00</lastmod>
@ -539,7 +539,7 @@
/> />
</url><url> </url><url>
<loc>/en/unlist/</loc> <loc>/en/unlist/</loc>
<lastmod>2024-06-29T08:47:08+08:00</lastmod> <lastmod>2024-06-29T21:05:42+08:00</lastmod>
<xhtml:link <xhtml:link
rel="alternate" rel="alternate"
hreflang="zh" hreflang="zh"

View file

@ -12,7 +12,7 @@
<link>/en/ebrowserreadme/</link> <link>/en/ebrowserreadme/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>/en/ebrowserreadme/</guid> <guid>/en/ebrowserreadme/</guid>
<description>Ebrowser: keyboard-friendly minimal suckless web browser Ebrowser is designed with the philosophy of Android uweb browser (gitlab).&#xA;lightweight (less than 20k bytes) without bundled electron. much less memory footprint than edge/chrome browser and highly performant. keyboard friendly with vim-style keymaps and command line support in address bar. global redirection to bypass censorship. user scripts at will. Ex. pressing &amp;quot;md&amp;quot; in no-focus mode to preview markdown file. customizable. Note: Usually electron apps are heavyweight as they use browsers for simple things.</description> <description>Ebrowser: keyboard-friendly minimal suckless web browser Ebrowser is designed with the philosophy of Android uweb browser (gitlab).&#xA;lightweight (less than 20k bytes) without bundled electron. much less memory footprint than edge/chrome browser and highly performant. keyboard friendly with vim-style keymaps and command line support in address bar. global redirection to bypass censorship. user scripts at will. Ex. pressing &amp;quot;md&amp;quot; in no-focus mode to preview markdown file. CSS/JS for domains, similar to uweb, but use sitejs/[domain].</description>
</item> </item>
<item> <item>
<title></title> <title></title>

View file

@ -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. - 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. - [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. - 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. - 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. 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 - "uas.json" : name-useragent pairs
#### Javascript at three levels #### 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) : - Browser (or renderer process) :
- ":bjs" to execute the following js code at browser level. - ":bjs" to execute the following js code at browser level.
- "!xx" evaluates "xx.js", which could manipulate address bar etc. - "!xx" evaluates "xx.js", which could manipulate address bar etc.

View file

@ -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 historyFile = path.join(__dirname,'history.rec');
var bHistory = false; var bHistory = false;
var bQueryHistory = 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 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_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 = "})()"; const BML_tail = "})()";
@ -136,20 +140,52 @@ You should have received a copy of the GNU General Public License along with thi
iTab = i; iTab = i;
tabs.children[iTab].classList.add('curWV'); 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){ function cbFinishLoad(e){
let tab = e.target; 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; let js = tab.dataset.jsonce;
if(js){ if(js){
tab.dataset.jsonce = null; tab.dataset.jsonce = null;
tab.executeJavaScript(js,false); tab.executeJavaScript(js,false);
} }
if(!bHistory) return; if(bDomainJS){
let histItem = tab.getTitle()+" "+tab.getURL()+"\n"; let domain = new URL(url).hostname;
fs.appendFile(historyFile, histItem, (err) => {}); let jsF = path.join(sitejsP, domain+".js");
loadJSFile(tab,jsF);
}
} }
function initTab(tab){ function initTab(tab){
tab.allowpopups = true; tab.allowpopups = true;
tab.addEventListener('did-finish-load',cbFinishLoad); tab.addEventListener('did-finish-load',cbFinishLoad);
tab.addEventListener('did-start-loading',cbStartLoading);
} }
function newTab(){ function newTab(){
var tab = document.createElement('webview'); var tab = document.createElement('webview');

View file

@ -1,4 +1,4 @@
{"version":"1.0.44", {"version":"1.0.45",
"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

@ -0,0 +1 @@
.ec_wise_ad,.ec_wise_pp,.na-like-container{transform:scale(0)!important;display:none!important}

View 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);
}
}
})();

View file

@ -4,7 +4,7 @@
<sitemap> <sitemap>
<loc>/en/sitemap.xml</loc> <loc>/en/sitemap.xml</loc>
<lastmod>2024-06-29T08:47:08+08:00</lastmod> <lastmod>2024-06-29T21:05:42+08:00</lastmod>
</sitemap> </sitemap>