-
Notifications
You must be signed in to change notification settings - Fork 0
/
0xHexBrowser.js
98 lines (82 loc) · 2.88 KB
/
0xHexBrowser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const ipc = require('electron').ipcRenderer
let configOptions = require('./configOptions.js')
let settings = configOptions.settings();
let tabs = configOptions.tabs();
// Manually create the webviews if we're not using browserViews
if (!settings.useBrowserViews) {
window.onresize = repositionWebView;
// create webviews
let tabContainer = document.querySelector("#tabBrowserViewContainer")
tabs.forEach(tab => {
let webviewHTML = `
<webview
id="webview-${tab.id}">
</webview>`
tabContainer.appendChild(createElementFromHTML(webviewHTML))
})
}
// Position the active webviews
function repositionWebView() {
var webview = document.querySelector('webview.active');
var controls = document.querySelector('#controls');
var controlsHeight = controls.offsetHeight;
var tabControls = document.querySelector('#tabs');
var tabControlsHeight = tabControls.offsetHeight + 1;
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var webviewWidth = windowWidth;
var webviewHeight = windowHeight - controlsHeight - tabControlsHeight;
webview.style.width = webviewWidth + 'px';
webview.style.height = webviewHeight + 'px';
webview.style.top = '60px';
}
// Utility function to create elements from an HTML string
function createElementFromHTML(htmlString) {
var div = document.createElement('div');
div.innerHTML = htmlString.trim();
return div.firstChild;
}
// Let `main.js` know we're ready to be bootstrapped
ipc.send('initialize', ' ')
// Create the tab headings in the UI and set click handlers
// if we're using webviews: manually
ipc.on('setTabs', (event, args) => {
var tabsNode = document.querySelector('#tabs')
tabsNode.innerHTML = '';
args.forEach(tab => {
var tabHTML = `
<div class="tab">
<div class="tabTitle">${tab.title}</div>
<div class="tabClose">×</div>
</div>`
var tabNode = createElementFromHTML(tabHTML)
if (tab.active) {
// Add the "active" class
tabNode.classList.add("active")
// Set the URL location bar
document.querySelector('#location').value = tab.url
}
// WebViews
if (!settings.useBrowserViews) {
var webviewNode = document.querySelector(`#webview-${tab.id}`)
if (tab.active) {
webviewNode.classList.add("active")
repositionWebView()
if (!webviewNode.getAttribute("src")) {
webviewNode.setAttribute("src", tab.url);
}
} else {
webviewNode.classList.remove("active")
}
}
// Setup click handlers
tabNode.onclick = function(){
ipc.send('nagivateToTab', tab)
}
// And finally, add the tab headings to the screen
tabsNode.appendChild(tabNode)
})
// Add button (not working yet)
let tabAddNode = createElementFromHTML(`<button id="addTab">+</button>`)
tabsNode.appendChild(tabAddNode)
});