-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
home.js
69 lines (59 loc) · 2.16 KB
/
home.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
const { ipcRenderer } = require('electron')
const webview = document.querySelector('#webview')
document.querySelector('#back-btn').addEventListener('click' , () => {
webview.goBack()
})
document.querySelector('#forward-btn').addEventListener('click' , () => {
webview.goForward()
})
document.querySelector('#reload-btn').addEventListener('click' , () => {
webview.reloadIgnoringCache()
})
const urlBar = document.querySelector('#url-bar')
urlBar.addEventListener('focus', () => {
document.execCommand('selectAll', false, null)
})
const urlBarProtocol = document.querySelector('#url-bar-protocol')
const urlBarHost = document.querySelector('#url-bar-host')
const urlBarPath = document.querySelector('#url-bar-path')
webview.addEventListener('page-title-updated', event => {
const url = webview.getURL()
const [ protocol, hostAndPath ] = url.split('://')
urlBarProtocol.textContent = `${protocol}://`
const [ host, ...path ] = hostAndPath.split('/')
urlBarHost.textContent = host
urlBarPath.textContent = `/${path.join('/')}`
document.title = `Race TV Multiplayer | ${webview.getTitle()}`
})
// let lastIconUrl = ''
// webview.addEventListener('page-favicon-updated', event => {
// const iconUrl = event.favicons[0]
// if(lastIconUrl === iconUrl) return
// lastIconUrl = iconUrl
// ipcRenderer.invoke('icon-ipc', iconUrl)
// })
let currentUrl = 'https://f1tv.formula1.com'
webview.addEventListener('did-navigate-in-page', event => {
if(event.url.startsWith('https://f1tv.formula1.com/detail/')) {
const referrer = currentUrl
webview.goBack()
ipcRenderer.invoke('video-ipc', event.url, referrer)
}
currentUrl = event.url
})
let webviewReady = false
const loadWebview = () => {
if(!webviewReady || !history.state || !history.state.useragent) return
webview.setUserAgent(history.state.useragent)
webview.loadURL('https://f1tv.formula1.com')
}
ipcRenderer.on('useragent', (event, useragent) => {
history.replaceState({ ...history.state, useragent }, '')
loadWebview()
})
const onDomReady = () => {
webview.removeEventListener('dom-ready', onDomReady)
webviewReady = true
loadWebview()
}
webview.addEventListener('dom-ready', onDomReady)