From 7eccedfeccdefb465426b8b731c3168bcdbda0f4 Mon Sep 17 00:00:00 2001 From: James Feng Cao Date: Tue, 11 Jun 2024 18:42:38 +0800 Subject: [PATCH] adaptable ebrowser links --- README.md | 2 +- README.zh-Hans.md | 2 +- README.zh.md | 2 +- ebrowser.md | 83 +++++++ en/_posts/index.xml | 4 +- en/bookmarklet/index.html | 6 +- en/ebrowserreadme/index.html | 178 +++++++++++++++ en/index.xml | 11 +- en/readme/index.html | 6 +- en/sitemap.xml | 17 +- en/tags/index.xml | 2 +- en/tags/javascript/index.xml | 4 +- en/unlist/index.xml | 7 + misc/ebrowser/index.html | 337 ++++++++++++++++++++++++++++ misc/ebrowser/webview.js | 419 +++++++++++++++++++++++++++++++++++ sitemap.xml | 4 +- zh/index.xml | 2 +- zh/readme/index.html | 6 +- zh/sitemap.xml | 6 +- 19 files changed, 1066 insertions(+), 32 deletions(-) create mode 100644 ebrowser.md create mode 100644 en/ebrowserreadme/index.html create mode 100644 misc/ebrowser/index.html create mode 100644 misc/ebrowser/webview.js diff --git a/README.md b/README.md index 2c014a7..47826b8 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Custom paper size PDF export and long vector screenshot, TTS, text reflow, resou ![](https://i.postimg.cc/XJ58ysdN/option1.png) ![](https://i.postimg.cc/0NFnQT6H/option2.png) -#### [Ebrowser](https://github.com/torappinfo/ebrowser) for Windows, MacOS and Linux +#### Ebrowser for Windows, MacOS and Linux Ebrowser is a simple verison of uweb browser on the desktop. - Fully open source. - Capture long screenshot as vector graphics. diff --git a/README.zh-Hans.md b/README.zh-Hans.md index aa05e91..a15d334 100644 --- a/README.zh-Hans.md +++ b/README.zh-Hans.md @@ -53,7 +53,7 @@ 配套安装uWeb定制Termux应用,可用地址栏作图(类似matlab功能)、超级计算器(无限精度/π的前万位或更多、无限函数、无限常量)、符号演算(解方程、分解因式、求积分导数)、离线字典查找等。譬如地址栏输入sin(x)**5就直接得到函数图形。利用好第三方代码,才能真正发挥出uWeb的潜能。 -#### [Ebrowser](https://github.com/torappinfo/ebrowser) for Windows, MacOS and Linux +#### Ebrowser for Windows, MacOS and Linux 可看作超微浏览器台式机简易版,用于弥补普通浏览器访问痛点。 - 支持网站自动镜像,可以使用国内镜像自动访问github等网站,可与国际搜索引擎无缝衔接。 - 同样允许直接访问英文技术网站。 diff --git a/README.zh.md b/README.zh.md index aa05e91..a15d334 100644 --- a/README.zh.md +++ b/README.zh.md @@ -53,7 +53,7 @@ 配套安装uWeb定制Termux应用,可用地址栏作图(类似matlab功能)、超级计算器(无限精度/π的前万位或更多、无限函数、无限常量)、符号演算(解方程、分解因式、求积分导数)、离线字典查找等。譬如地址栏输入sin(x)**5就直接得到函数图形。利用好第三方代码,才能真正发挥出uWeb的潜能。 -#### [Ebrowser](https://github.com/torappinfo/ebrowser) for Windows, MacOS and Linux +#### Ebrowser for Windows, MacOS and Linux 可看作超微浏览器台式机简易版,用于弥补普通浏览器访问痛点。 - 支持网站自动镜像,可以使用国内镜像自动访问github等网站,可与国际搜索引擎无缝衔接。 - 同样允许直接访问英文技术网站。 diff --git a/ebrowser.md b/ebrowser.md new file mode 100644 index 0000000..64f65c5 --- /dev/null +++ b/ebrowser.md @@ -0,0 +1,83 @@ +### [Ebrowser](https://github.com/torappinfo/ebrowser) as alternative to [uweb browser](https://github.com/torappinfo/uweb) +Ebrowser is the minimal browser with the philosophy of [Android uweb browser](https://gitlab.com/jamesfengcao/uweb). + +- lightweight (less than 20k bytes) without bundled electron. +- much less memory footprint than edge/chrome browser and highly performant. +- keyboard (command line) friendly. +- 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. + +#### Install (for Windows, macOS and Linux) +Install ebrowser with nodejs installed + + npm install ebrowser + +Run ebrowser + + electron ~/node_modules/ebrowser + +#### Key shortcuts +- CTRL+G: address bar to show page url +- CTRL+L: focus to address bar +- CTRL+T: new Tab +- CTRL+TAB: switch to next tab +- CTRL+SHIFT+TAB: switch to previous tab +- CTRL+W: close Tab +- CTRL+<-: go backward +- CTRL+->: go forward +- CTRL+SHIFT+R: enable global redirection ("gredirect.json") +- CTRL+R: disable global redirection +- ESC: remove focus. similar to vi normal mode. +- F5: page refresh/reload +- F12: devtools +- ":" for address bar commands +- "/" for find-in-page with address bar +- "!" for ":!" address bar commands + +#### Address bar commands +- "/" for find-in-page +- ":" for address bar commands + - autoc [bookmark/history path w/o ext] : load ".rec" file for autocomplete. + - b [bookmarkfilename w/o ext] : bookmark current page in file. + - bml [filename w/o extension]: load/execute the javascript file. + - cert : allow invalid certificates w/o arguments, otherwise restore to default. + - clear : the arguments could be + - cache : clear cache + - dns : clear dns cache + - storage: clear site storage data. + - ext [extension path]: load unpacked Chrome extension. + - nh/uh for No/Use url history. + - nj/uj for No/Use external Javascript files. + - nr/ur for No/Use "redirect.json" for domain redirection. + - np : no proxy + - up [proxyName] : use proxy. privous proxy or the first proxy in proxy.json w/o [proxyName]. + - ua [useragentName] : set user agent for future tabs. default user agent w/o arguments. + - pdf [filename w/o extension] {[options](https://www.electronjs.org/docs/latest/api/web-contents#contentsprinttopdfoptions)} : print to PDF file. All arguments are optional; empty option "{}" to capture long screenshot as vector graphics. +- ":!" address bar commands + +#### Commands in no-focus mode (this mode is similar to vi Normal mode) +Pressing "ESC" to enter no-focus mode if not sure. +The commands are defined in "mapkeys.json", which will map keys to address bar commands. + +#### Configuration files +- "config": lines of address bar commands. +- "search.json": search engines as shortcut-queryUrl pairs. +- "default.autoc": predefined strings for address bar auto completion. +- "gredirect.json": global redirection urls as array of urls +- "redirect.json": domain-replacementDomain pairs, default to be applied. +- "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 + +#### New usages +- Vector designing with web tech to replace Adobe Illustrator/Inkscape. + - Design with web tech. + + - Printing to pdf with customized paper size. + - Magnify the pdf paper size to the required size. + + OR + + - Adjust window width and use addressbar command line ":Pdf {}" to export vector graphics. + - Use imageMagick to convert to any other vector graphics format. \ No newline at end of file diff --git a/en/_posts/index.xml b/en/_posts/index.xml index f3be4ca..46fe72d 100644 --- a/en/_posts/index.xml +++ b/en/_posts/index.xml @@ -6,7 +6,7 @@ Recent content in _Posts on uweb browser: unlimited power Hugo en - Fri, 24 May 2024 09:50:14 +0800 + Tue, 11 Jun 2024 08:12:27 +0800 Text selection/processing @@ -111,7 +111,7 @@ /en/bookmarklet/ Fri, 24 Jun 2022 00:00:00 +0000 /en/bookmarklet/ - With a href=&quot;../index.html#&quot;&gt;uweb browser, long pressing any bookmarklet link, click &quot;Open in new tab&quot;, the bookmarklet will be run on the last other tab. List all script urls User agent Cookie Source code Last modified date Eruda: mobile console QR code generation Use &quot;GET&quot; method for &quot;POST&quot; Shows all form elements Enables all form elements Toggle checkboxes Check all checkboxes Uncheck all checkboxes Toggle all checkboxes in forms Enable selection + With uweb browser, long pressing any bookmarklet link, click &quot;Open in new tab&quot;, the bookmarklet will be run on the last other tab. List all script urls User agent Cookie Source code Last modified date Eruda: mobile console QR code generation Use &quot;GET&quot; method for &quot;POST&quot; Shows all form elements Enables all form elements Toggle checkboxes Check all checkboxes Uncheck all checkboxes Toggle all checkboxes in forms Enable selection Restore context menu CSS styles diff --git a/en/bookmarklet/index.html b/en/bookmarklet/index.html index 2ced4d3..da4c486 100644 --- a/en/bookmarklet/index.html +++ b/en/bookmarklet/index.html @@ -49,7 +49,7 @@
  • javascript
  • -

    With a href="../index.html#">uweb browser, long pressing any bookmarklet link, click "Open in new tab", the bookmarklet will be run on the last other tab.

    +

    With uweb browser, long pressing any bookmarklet link, click "Open in new tab", the bookmarklet will be run on the last other tab.

    List all script urls

    User agent
    Cookie
    @@ -71,8 +71,8 @@

    BugMeNot

    -

    Last Modified: 2 April 2024
    -add js function in README
    +

    Last Modified: 11 June 2024
    +fix typos

    
     

    diff --git a/en/ebrowserreadme/index.html b/en/ebrowserreadme/index.html new file mode 100644 index 0000000..4cf59e9 --- /dev/null +++ b/en/ebrowserreadme/index.html @@ -0,0 +1,178 @@ + + + + + + + + + + + +
    + + + +
    +
    + +
    +

    +
    + +

    +
      + +
    +

    Ebrowser as alternative to uweb browser

    +

    Ebrowser is the minimal browser with the philosophy of Android uweb browser.

    +
      +
    • lightweight (less than 20k bytes) without bundled electron.
    • +
    • much less memory footprint than edge/chrome browser and highly performant.
    • +
    • keyboard (command line) friendly.
    • +
    • 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.

    +

    Install (for Windows, macOS and Linux)

    +

    Install ebrowser with nodejs installed

    +
    npm install ebrowser
    +
    +

    Run ebrowser

    +
    electron ~/node_modules/ebrowser
    +
    +

    Key shortcuts

    +
      +
    • CTRL+G: address bar to show page url
    • +
    • CTRL+L: focus to address bar
    • +
    • CTRL+T: new Tab
    • +
    • CTRL+TAB: switch to next tab
    • +
    • CTRL+SHIFT+TAB: switch to previous tab
    • +
    • CTRL+W: close Tab
    • +
    • CTRL+<-: go backward
    • +
    • CTRL+->: go forward
    • +
    • CTRL+SHIFT+R: enable global redirection ("gredirect.json")
    • +
    • CTRL+R: disable global redirection
    • +
    • ESC: remove focus. similar to vi normal mode.
    • +
    • F5: page refresh/reload
    • +
    • F12: devtools
    • +
    • ":" for address bar commands
    • +
    • "/" for find-in-page with address bar
    • +
    • "!" for ":!" address bar commands
    • +
    +

    Address bar commands

    +
      +
    • "/" for find-in-page
    • +
    • ":" for address bar commands +
        +
      • autoc [bookmark/history path w/o ext] : load ".rec" file for autocomplete.
      • +
      • b [bookmarkfilename w/o ext] : bookmark current page in file.
      • +
      • bml [filename w/o extension]: load/execute the javascript file.
      • +
      • cert : allow invalid certificates w/o arguments, otherwise restore to default.
      • +
      • clear : the arguments could be +
          +
        • cache : clear cache
        • +
        • dns : clear dns cache
        • +
        • storage: clear site storage data.
        • +
        +
      • +
      • ext [extension path]: load unpacked Chrome extension.
      • +
      • nh/uh for No/Use url history.
      • +
      • nj/uj for No/Use external Javascript files.
      • +
      • nr/ur for No/Use "redirect.json" for domain redirection.
      • +
      • np : no proxy
      • +
      • up [proxyName] : use proxy. privous proxy or the first proxy in proxy.json w/o [proxyName].
      • +
      • ua [useragentName] : set user agent for future tabs. default user agent w/o arguments.
      • +
      • pdf [filename w/o extension] {options} : print to PDF file. All arguments are optional; empty option "{}" to capture long screenshot as vector graphics.
      • +
      +
    • +
    • ":!" address bar commands
    • +
    +

    Commands in no-focus mode (this mode is similar to vi Normal mode)

    +

    Pressing "ESC" to enter no-focus mode if not sure.
    +The commands are defined in "mapkeys.json", which will map keys to address bar commands.

    +

    Configuration files

    +
      +
    • "config": lines of address bar commands.
    • +
    • "search.json": search engines as shortcut-queryUrl pairs.
    • +
    • "default.autoc": predefined strings for address bar auto completion.
    • +
    • "gredirect.json": global redirection urls as array of urls
    • +
    • "redirect.json": domain-replacementDomain pairs, default to be applied.
    • +
    • "mapkeys.json": keys-addressbarCommands pairs. The addressbar commands are multiple lines of address bar command separated by "\n".
    • +
    • "proxy.json": name-ProxyConfig pairs
    • +
    • "uas.json" : name-useragent pairs
    • +
    +

    New usages

    +
      +
    • +

      Vector designing with web tech to replace Adobe Illustrator/Inkscape.

      +
        +
      • +

        Design with web tech.

        +
      • +
      • +

        Printing to pdf with customized paper size.

        +
      • +
      • +

        Magnify the pdf paper size to the required size.

        +
      • +
      +

      OR

      +
        +
      • Adjust window width and use addressbar command line ":Pdf {}" to export vector graphics.
      • +
      • Use imageMagick to convert to any other vector graphics format.
      • +
      +
    • +
    + +
    +

    Last Modified: 11 June 2024
    +
    +

    
    +

    + + + +
    +
    + © 2018-2024 Richard H. Cao +
    +
    + + + + + diff --git a/en/index.xml b/en/index.xml index 7a4bb43..76c0d3d 100644 --- a/en/index.xml +++ b/en/index.xml @@ -6,7 +6,7 @@ Recent content on uweb browser: unlimited power Hugo en - Mon, 10 Jun 2024 17:27:55 +0800 + Tue, 11 Jun 2024 18:34:35 +0800 Text selection/processing @@ -132,7 +132,7 @@ /en/bookmarklet/ Fri, 24 Jun 2022 00:00:00 +0000 /en/bookmarklet/ - With a href=&quot;../index.html#&quot;&gt;uweb browser, long pressing any bookmarklet link, click &quot;Open in new tab&quot;, the bookmarklet will be run on the last other tab. List all script urls User agent Cookie Source code Last modified date Eruda: mobile console QR code generation Use &quot;GET&quot; method for &quot;POST&quot; Shows all form elements Enables all form elements Toggle checkboxes Check all checkboxes Uncheck all checkboxes Toggle all checkboxes in forms Enable selection + With uweb browser, long pressing any bookmarklet link, click &quot;Open in new tab&quot;, the bookmarklet will be run on the last other tab. List all script urls User agent Cookie Source code Last modified date Eruda: mobile console QR code generation Use &quot;GET&quot; method for &quot;POST&quot; Shows all form elements Enables all form elements Toggle checkboxes Check all checkboxes Uncheck all checkboxes Toggle all checkboxes in forms Enable selection Restore context menu Url services @@ -211,6 +211,13 @@ /en/gesture/ Swipe down from the top to show the address bar; swipe up to the top to hide the address bar. Swipe down to the bottom to hide the toolbar with option &quot;swipe to hide tools&quot;; swipe on the bottom corners to show the toolbar. Swipe left/right near the toolbar to switch window; fling left/right to switch to the last/first window. Swiping on the top part of content window (near the top address bar by default) triggers corresponding link in the file &quot;default. + + + /en/ebrowserreadme/ + Mon, 01 Jan 0001 00:00:00 +0000 + /en/ebrowserreadme/ + Ebrowser as alternative to uweb browser Ebrowser is the minimal browser with the philosophy of Android uweb browser. lightweight (less than 20k bytes) without bundled electron. much less memory footprint than edge/chrome browser and highly performant. keyboard (command line) friendly. 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. Install (for Windows, macOS and Linux) Install ebrowser with nodejs installed + /en/mirrors/ diff --git a/en/readme/index.html b/en/readme/index.html index 6b62f93..afeba1a 100644 --- a/en/readme/index.html +++ b/en/readme/index.html @@ -88,7 +88,7 @@

    -

    Ebrowser for Windows, MacOS and Linux

    +

    Ebrowser for Windows, MacOS and Linux

    Ebrowser is a simple verison of uweb browser on the desktop.

    • Fully open source.
    • @@ -106,8 +106,8 @@
    -

    Last Modified: 10 June 2024
    -rename eweb to ebrowser
    +

    Last Modified: 11 June 2024
    +use adaptable ebrowser links

    
     

    diff --git a/en/sitemap.xml b/en/sitemap.xml index 7e50be2..675bb0f 100644 --- a/en/sitemap.xml +++ b/en/sitemap.xml @@ -3,7 +3,7 @@ xmlns:xhtml="http://www.w3.org/1999/xhtml"> /en/_posts/ - 2024-05-24T09:50:14+08:00 + 2024-06-11T08:12:27+08:00 /en/tags/ - 2024-05-24T09:50:14+08:00 + 2024-06-11T08:12:27+08:00 /en/ - 2024-06-10T17:27:55+08:00 + 2024-06-11T18:34:35+08:00 /en/tags/javascript/ - 2024-04-02T11:45:19+08:00 + 2024-06-11T08:12:27+08:00 /en/bookmarklet/ - 2024-04-02T11:45:19+08:00 + 2024-06-11T08:12:27+08:00 + + /en/ebrowserreadme/ + 2024-06-11T18:18:13+08:00 /en/mirrors/ 2024-04-06T10:20:49+08:00 /en/readme/ - 2024-06-10T17:27:55+08:00 + 2024-06-11T18:34:35+08:00 /en/unlist/ - 2024-06-10T17:27:55+08:00 + 2024-06-11T18:34:35+08:00 Recent content in Tags on uweb browser: unlimited power Hugo en - Fri, 24 May 2024 09:50:14 +0800 + Tue, 11 Jun 2024 08:12:27 +0800 Clipboard diff --git a/en/tags/javascript/index.xml b/en/tags/javascript/index.xml index dfc850d..c9b0c01 100644 --- a/en/tags/javascript/index.xml +++ b/en/tags/javascript/index.xml @@ -6,7 +6,7 @@ Recent content in Javascript on uweb browser: unlimited power Hugo en - Tue, 02 Apr 2024 11:45:19 +0800 + Tue, 11 Jun 2024 08:12:27 +0800 JS/CSS/HTML/preprocessing for domains @@ -20,7 +20,7 @@ /en/bookmarklet/ Fri, 24 Jun 2022 00:00:00 +0000 /en/bookmarklet/ - With a href=&quot;../index.html#&quot;&gt;uweb browser, long pressing any bookmarklet link, click &quot;Open in new tab&quot;, the bookmarklet will be run on the last other tab. List all script urls User agent Cookie Source code Last modified date Eruda: mobile console QR code generation Use &quot;GET&quot; method for &quot;POST&quot; Shows all form elements Enables all form elements Toggle checkboxes Check all checkboxes Uncheck all checkboxes Toggle all checkboxes in forms Enable selection + With uweb browser, long pressing any bookmarklet link, click &quot;Open in new tab&quot;, the bookmarklet will be run on the last other tab. List all script urls User agent Cookie Source code Last modified date Eruda: mobile console QR code generation Use &quot;GET&quot; method for &quot;POST&quot; Shows all form elements Enables all form elements Toggle checkboxes Check all checkboxes Uncheck all checkboxes Toggle all checkboxes in forms Enable selection Restore context menu Long pressed link menu diff --git a/en/unlist/index.xml b/en/unlist/index.xml index e19e0ea..b1bfc38 100644 --- a/en/unlist/index.xml +++ b/en/unlist/index.xml @@ -7,6 +7,13 @@ Hugo en + + + /en/ebrowserreadme/ + Mon, 01 Jan 0001 00:00:00 +0000 + /en/ebrowserreadme/ + Ebrowser as alternative to uweb browser Ebrowser is the minimal browser with the philosophy of Android uweb browser. lightweight (less than 20k bytes) without bundled electron. much less memory footprint than edge/chrome browser and highly performant. keyboard (command line) friendly. 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. Install (for Windows, macOS and Linux) Install ebrowser with nodejs installed + /en/mirrors/ diff --git a/misc/ebrowser/index.html b/misc/ebrowser/index.html new file mode 100644 index 0000000..c5447ad --- /dev/null +++ b/misc/ebrowser/index.html @@ -0,0 +1,337 @@ + + + + + +
    + +
    +
    + +
    + + diff --git a/misc/ebrowser/webview.js b/misc/ebrowser/webview.js new file mode 100644 index 0000000..f1f8099 --- /dev/null +++ b/misc/ebrowser/webview.js @@ -0,0 +1,419 @@ +const { + app, BrowserWindow, Menu, shell, clipboard, + session, protocol, net} = require('electron') +let win; + +if(!app.requestSingleInstanceLock()) + app.quit() +else { + app.on('ready', createWindow); + app.on('second-instance', (event, args, cwd) => { + // 当已经有运行的实例时,我们激活窗口而不是创建新的窗口 + if (win) { + if (win.isMinimized()) { + win.restore() + } + win.show() + win.focus() + cmdlineProcess(args,cwd,1); + }else + createWindow(); + }) +} +topMenu(); + +const fs = require('fs'); +const readline = require('readline'); +const path = require('path') +const process = require('process') +var gredirects = []; +var gredirect; +var redirects; +var bRedirect = true; +var bJS = true; +var bHistory = false; +var proxies = {}; +var proxy; +var useragents = {}; +var defaultUA = + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + + process.versions.chrome +" Safari/537.36"; +app.userAgentFallback = defaultUA; +var historyFile = path.join(__dirname,'history.rec'); + +fs.readFile(path.join(__dirname,'redirect.json'), 'utf8', (err, jsonString) => { + if (err) return; + try { + redirects = JSON.parse(jsonString); + } catch (e){} +}); + +async function createWindow () { + let json = await fs.promises.readFile(path.join(__dirname,'uas.json'), 'utf8'); + try { + useragents = JSON.parse(json); + } catch (e){} + + await (async ()=>{ + try{ + const readInterface = readline.createInterface ({ + input: fs.createReadStream (path.join(__dirname,'config'), 'utf8'), + }); + + for await (const line of readInterface) { + addrCommand(line); + } + }catch(e){return;} + })(); + + win = new BrowserWindow( + {width: 800, height: 600,autoHideMenuBar: true, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + webviewTag: true, + }}); + win.setMenuBarVisibility(false); + win.on('closed', function () { + win = null + }) + + win.loadFile('index.html'); + fs.readFile(path.join(__dirname,'gredirect.json'), 'utf8', (err, jsonString) => { + if (err) return; + try { + gredirects = JSON.parse(jsonString); + } catch (e){} + }); + + fs.readFile(path.join(__dirname,'proxy.json'), 'utf8', (err, jsonString) => { + if (err) return; + try { + proxies = JSON.parse(jsonString, (key,val)=>{ + if(!proxy && key==="proxyRules"){ + proxy = {proxyRules:val}; + } + return val; + }); + } catch (e){} + }); + + cmdlineProcess(process.argv, process.cwd(), 0); + //app.commandLine.appendSwitch ('trace-warnings'); + + win.webContents.on('page-title-updated',(event,cmd)=>{ + addrCommand(cmd); + }); + + win.webContents.on('console-message',cbConsoleMsg); + //protocol.handle("https",cbScheme_https); +} + +app.on('window-all-closed', function () { + app.quit() +}) + +app.on('activate', function () { + if (win === null) { + createWindow() + } +}) + +app.on('will-quit', () => { +}) + +app.on ('web-contents-created', (event, contents) => { + if (contents.getType () === 'webview') { + contents.setWindowOpenHandler(cbWindowOpenHandler); + contents.on('context-menu',onContextMenu); + contents.on('page-title-updated',cbTitleUpdate); + //contents.on('console-message',cbConsoleMsg); + //contents.on('focus', ()=>{cbFocus(contents)}); + //contents.on('blur',()=>{cbBlur()}); + contents.session.webRequest.onBeforeRequest(interceptRequest); + contents.on('did-finish-load',()=>{cbFinishLoad(contents)}); + } +}); + +function addrCommand(cmd){ + if(cmd.length<3) return; + let c0 = cmd.charCodeAt(0); + switch(c0){ + case 58: //':' + args = cmd.substring(1).split(/\s+/); + switch(args[0]){ + case "cert": + if(args.length==1) + session.defaultSession.setCertificateVerifyProc((request, callback) => { + callback(0); + }); + else + session.defaultSession.setCertificateVerifyProc(null); + return; + case "clear": + if(args.length==1){ + return; + } + switch(args[1]){ + case "cache": + session.defaultSession.clearCache(); + return; + case "dns": + session.defaultSession.clearHostResolverCache(); + return; + case "storage": + session.defaultSession.clearStorageData(); + return; + } + return; + case "ext": + session.defaultSession.loadExtension(args[1]); + return; + case "nh": + bHistory = false; return; + case "uh": + bHistory = true; return; + case "nj": + bJS = false; return; + case "uj": + bJS = true; return; + case "np": + session.defaultSession.setProxy ({mode:"direct"}); + return; + case "up": + if(args.length>1) + proxy = proxies[args[1]]; //retrieve proxy + if(proxy) + session.defaultSession.setProxy(proxy); + bRedirect = false; + return; + case "nr": + bRedirect = false; return; + case "ur": + bRedirect = true; return; + case "ua": + if(args.length==2) + session.defaultSession.setUserAgent(useragents[args[1]]); + else + session.defaultSession.setUserAgent(defaultUA); + return; + } + } +} + +function cbConsoleMsg(e, level, msg, line, sourceid){ + console.log(line); + console.log(sourceid); + console.log(msg); +} + +function cbFinishLoad(webContents){ + if(!bHistory) return; + let histItem = webContents.getTitle()+" "+webContents.getURL()+"\n"; + fs.appendFile(historyFile, histItem, (err) => {}); +} + +function cbFocus(webContents){ + let js = "if(focusMesg){let m=focusMesg;focusMesg=null;m}"; + win.webContents.executeJavaScript(js,false).then((r)=>{ + //focusMesg as js code + console.log(r); + if(r) webContents.executeJavaScript(r,false); + }); +} + +function interceptRequest(details, callback){ + if(!bJS && details.url.endsWith(".js")){ + callback({ cancel: true }); + return; + } + do { + if(gredirect){ + if(!details.url.startsWith("http")) break; + if(!details.url.startsWith(gredirect)){ + if(details.resourceType === 'mainFrame'){ + let wc = details.webContents; + let url = details.url; + if(wc){ + let nUrl = gredirect+url; + fetch(nUrl).then(res=>{ + if(res.ok) return res.arrayBuffer(); + throw new Error(`Err: ${res.status} - ${res.statusText}`); + }).then(aBuf=>{ + const u8 = new Uint8Array(aBuf); + const b64 = Buffer.from (u8).toString('base64'); + const dataUrl = `data:text/html;base64,${b64}`; + wc.loadURL(dataUrl,{baseURLForDataURL:url}); + }).catch(e=>{ + console.log(nUrl+" err:",e); + }); + callback({ cancel: true }); + return; + } + } + let newUrl = gredirect + details.url; + callback({ cancel: false, redirectURL: newUrl }); + return; + } + break; + } + + if(!bRedirect ||(details.resourceType !== 'mainFrame' && + details.resourceType !== 'subFrame')) break; + let oURL = new URL(details.url); + let domain = oURL.hostname; + let newUrl; + try{ + let newDomain = redirects[domain]; + if(!newDomain) break; + newUrl = "https://"+newDomain+oURL.pathname+oURL.search+oURL.hash; + }catch(e){break;} + callback({ cancel: false, redirectURL: newUrl }); + return; + }while(false); + callback({ cancel: false }); +} + +function cbWindowOpenHandler(details){ + let url = details.url; + let js = "newTab();tabs.children[tabs.children.length-1].src='"+ + url+"';"; + switch(details.disposition){ + case "foreground-tab": + case "new-window": + js = js + "switchTab(tabs.children.length-1)"; + } + win.webContents.executeJavaScript(js,false); + return { action: "deny" }; +} +function cbTitleUpdate(event,title){ + win.setTitle(title); +} +function menuArray(labelprefix, linkUrl){ + const menuTemplate = [ + { + label: labelprefix+'Open Link', + click: () => { + shell.openExternal(linkUrl); + } + }, + { + label: labelprefix+'Copy Link', + click: () => { + clipboard.writeText(linkUrl); + } + }, + { + label: labelprefix+'Download', + click: () => { + win.contentView.children[i].webContents.downloadURL(linkUrl); + } + }, + ]; + return menuTemplate; +} + +function onContextMenu(event, params){ + let url = params.linkURL; + let mTemplate = []; + if (url) { + mTemplate.push({label:url,enabled:false}); + mTemplate.push.apply(mTemplate,menuArray("",url)); + if((url=params.srcURL)) + mTemplate.push.apply(mTemplate,menuArray("src: ",url)); + }else if((url=params.srcURL)){ + mTemplate.push({label:url,enabled:false}); + mTemplate.push.apply(mTemplate,menuArray("src: ",url)); + }else + return; + + const contextMenu = Menu.buildFromTemplate(mTemplate); + contextMenu.popup(); +} + +function topMenu(){ + const menuTemplate = [ + { + label: '', + submenu: [ + { label: '', accelerator: 'Ctrl+G', click: ()=>{ + let js="{let q=document.forms[0].q;q.focus();q.value=tabs.children[iTab].src}" + win.webContents.executeJavaScript(js,false) + }}, + { label: '', accelerator: 'Ctrl+L', click:()=>{ + win.webContents.executeJavaScript("document.forms[0].q.select()",false); + }}, + { label: '', accelerator: 'Ctrl+T', click:()=>{ + let js = "newTab();document.forms[0].q.select();switchTab(tabs.children.length-1)"; + win.webContents.executeJavaScript(js,false); + }}, + { label: '', accelerator: 'Ctrl+R', click: ()=>{ + gredirect=null; + }}, + { label: '', accelerator: 'Ctrl+Shift+R', click: ()=>{ + if(0==gredirects.length) return; + gredirect=gredirects[0]; + }}, + { label: '', accelerator: 'Ctrl+W', click: ()=>{ + win.webContents.executeJavaScript("tabClose()",false).then((r)=>{ + if(""===r) win.close(); + else win.setTitle(r); + }); + }}, + { label: '', accelerator: 'Ctrl+Tab', click: ()=>{ + let js="tabInc(1);getWinTitle()"; + win.webContents.executeJavaScript(js,false).then((r)=>{ + win.setTitle(r); + }); + }}, + { label: '', accelerator: 'Ctrl+Shift+Tab', click: ()=>{ + let js="tabDec(-1);getWinTitle()"; + win.webContents.executeJavaScript(js,false).then((r)=>{ + win.setTitle(r); + }); + }}, + { label: '', accelerator: 'Ctrl+Left', click: ()=>{ + let js="tabs.children[iTab].goBack()"; + win.webContents.executeJavaScript(js,false); + }}, + { label: '', accelerator: 'Ctrl+Right', click: ()=>{ + let js="tabs.children[iTab].goForward()"; + win.webContents.executeJavaScript(js,false); + }}, + { label: '', accelerator: 'Esc', click: ()=>{ + let js = `{let e=document.activeElement; +if(e)e.blur();try{tabs.children[iTab].stopFindInPage('clearSelection')}catch(er){}}`; + win.webContents.executeJavaScript(js,false); + }}, + { label: '', accelerator: 'F5', click: ()=>{ + win.webContents.executeJavaScript("tabs.children[iTab].reload()",false); + }}, + { label: '', accelerator: 'F12', click: ()=>{ + let js = "try{tabs.children[iTab].openDevTools()}catch(e){console.log(e)}"; + win.webContents.executeJavaScript(js,false); + }}, + + ], + }, + ]; + const menu = Menu.buildFromTemplate(menuTemplate); + Menu.setApplicationMenu(menu); +} + +function cmdlineProcess(argv,cwd,extra){ + let i1st = 2+extra; //index for the first query item + if(argv.length>i1st){ + if(i1st+1==argv.length){//local file + let fname = path.join(cwd, argv[i1st]); + if(fs.existsSync(fname)){ + let js = "tabs.children[iTab].src='file://"+fname+"'"; + win.webContents.executeJavaScript(js,false); + win.setTitle(argv[i1st]); + return; + } + } + let url=argv.slice(i1st).join(" "); + win.webContents.executeJavaScript("handleQuery(`"+url+"`)",false); + win.setTitle(url); + } +} diff --git a/sitemap.xml b/sitemap.xml index 60fa55c..525de89 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -4,14 +4,14 @@ /en/sitemap.xml - 2024-06-10T17:27:55+08:00 + 2024-06-11T18:34:35+08:00 /zh/sitemap.xml - 2024-06-10T17:28:20+08:00 + 2024-06-11T18:37:58+08:00 diff --git a/zh/index.xml b/zh/index.xml index 5ef14d0..c8f1830 100644 --- a/zh/index.xml +++ b/zh/index.xml @@ -6,7 +6,7 @@ Recent content on 超微浏览器: 威、快、高效、极致优化 Hugo zh - Mon, 10 Jun 2024 17:28:20 +0800 + Tue, 11 Jun 2024 18:37:58 +0800 操作选中(富)文本/元素 diff --git a/zh/readme/index.html b/zh/readme/index.html index 112050c..3134d30 100644 --- a/zh/readme/index.html +++ b/zh/readme/index.html @@ -90,7 +90,7 @@

    支持网址特定脚本/样式,可轻松支持百万以上不同脚本。

    支持自定义任意多个搜索引擎; 支持执行用户提供任何js文件; 支持用户定义任意多个useragent; 长按链接支持运行第三方程序; 长按链接支持运行用户js文件。

    配套安装uWeb定制Termux应用,可用地址栏作图(类似matlab功能)、超级计算器(无限精度/π的前万位或更多、无限函数、无限常量)、符号演算(解方程、分解因式、求积分导数)、离线字典查找等。譬如地址栏输入sin(x)**5就直接得到函数图形。利用好第三方代码,才能真正发挥出uWeb的潜能。

    -

    Ebrowser for Windows, MacOS and Linux

    +

    Ebrowser for Windows, MacOS and Linux

    可看作超微浏览器台式机简易版,用于弥补普通浏览器访问痛点。

    • @@ -119,8 +119,8 @@
    -

    Last Modified: 10 June 2024
    -rename eweb to ebrowser
    +

    Last Modified: 11 June 2024
    +use adaptable ebrowser links

    
     

    diff --git a/zh/sitemap.xml b/zh/sitemap.xml index bf85adf..78cabbe 100644 --- a/zh/sitemap.xml +++ b/zh/sitemap.xml @@ -81,7 +81,7 @@ />
    /zh/ - 2024-06-10T17:28:20+08:00 + 2024-06-11T18:37:58+08:00 2024-04-02T11:46:25+08:00 /zh/readme/ - 2024-06-10T17:28:20+08:00 + 2024-06-11T18:37:58+08:00 2024-04-02T11:46:25+08:00 /zh/unlist/ - 2024-06-10T17:28:20+08:00 + 2024-06-11T18:37:58+08:00