|
1 | 1 | /* eslint-enable no-undef */
|
2 | 2 | /* eslint-enable no-unused-vars */
|
3 | 3 | const { ElectronBlocker } = require('@cliqz/adblocker-electron');
|
4 |
| -const { app, BrowserWindow, Menu, session, ipcMain } = require('electron'); |
| 4 | +const { app, BrowserWindow, Menu, session, ipcMain, dialog } = require('electron'); |
5 | 5 | const path = require('path');
|
6 | 6 | const fs = require('fs');
|
7 | 7 | const https = require('https');
|
8 | 8 | const contextMenu = require('electron-context-menu');
|
| 9 | +const parse = require('bookmarks-parser') |
9 | 10 |
|
10 | 11 | if (require('electron-squirrel-startup')) app.quit();
|
11 | 12 |
|
@@ -144,7 +145,41 @@ const template = [{
|
144 | 145 | click: function () {
|
145 | 146 | mainWindow.webContents.toggleDevTools();
|
146 | 147 | },
|
| 148 | +}, |
| 149 | +{ |
| 150 | + label: 'htmlmarks', |
| 151 | + accelerator: 'CmdOrCtrl+H', |
| 152 | + click: function() { |
147 | 153 |
|
| 154 | + dialog.showOpenDialog({ |
| 155 | + properties: ['openFile', 'multiSelections'] |
| 156 | + }).then(result => { |
| 157 | + if (!result.canceled) { |
| 158 | + const filePaths = result.filePaths; |
| 159 | + const file = filePaths[0] |
| 160 | + try { |
| 161 | + const buf = fs.readFileSync(file, { encoding: 'utf8', flag: 'r' }); |
| 162 | + parse(buf, function(e,r) { |
| 163 | + console.log(e) |
| 164 | + console.log(r['bookmarks'][0].children) |
| 165 | + marks = r['bookmarks'][0].children |
| 166 | + for (var i = 0; i < marks.length; i++) |
| 167 | + { |
| 168 | + url = marks[i]['url']; |
| 169 | + title = marks[i]['title'] |
| 170 | + js = `progBookmarkTab("${url}", "${title}")` |
| 171 | + console.log(url) |
| 172 | + mainWindow.webContents.executeJavaScript(js) |
| 173 | + } |
| 174 | + }) |
| 175 | + } catch { |
| 176 | + return; |
| 177 | + } |
| 178 | + } |
| 179 | + }).catch(err => { |
| 180 | + console.error('Error opening file dialog:', err); |
| 181 | + }); |
| 182 | + } |
148 | 183 | }];
|
149 | 184 |
|
150 | 185 | app.on('web-contents-created', (e, contents) => {
|
|
0 commit comments