-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
170 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>HackMD</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style> | ||
html, body { | ||
margin: 0; | ||
height: 100%; | ||
background-color: #f8f8f8; | ||
overflow: hidden; | ||
font-family: Arial, Helvetica, sans-serif; | ||
} | ||
|
||
body { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
webview { | ||
display: flex; | ||
flex: 1; | ||
} | ||
|
||
navbar { | ||
height: 23px; | ||
align-items: center; | ||
width: 100%; | ||
display: flex; | ||
-webkit-app-region: drag; | ||
padding-left: 75px; | ||
background-color: #f8f8f8; | ||
color: #484848; | ||
} | ||
|
||
#navbar-container { | ||
font-size: 0.9em; | ||
font-family: "Courier New", Courier, monospace; | ||
display: flex; | ||
flex: 1; | ||
justify-content: space-between; | ||
-webkit-user-select: none; | ||
user-select: none; | ||
} | ||
|
||
navbar.dark { | ||
background-color: #333333; | ||
color: white; | ||
} | ||
|
||
navbar.dark .control-buttons > *:hover { | ||
color: white; | ||
} | ||
|
||
#navbar-container .control-buttons { | ||
flex: 1; | ||
display: flex; | ||
} | ||
|
||
#navbar-container .control-buttons > * { | ||
margin: 0 .3em; | ||
cursor: pointer; | ||
-webkit-user-select: none; | ||
height: 23px; | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
#navbar-container .control-buttons > *:hover { | ||
color: #c1c1c1; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<navbar> | ||
<div id="navbar-container"> | ||
<div class="control-buttons"> | ||
<div class="home">HOME</div> | ||
<div class="refresh">REFRESH</div> | ||
<div class="navigate-back" style="margin: 0 1em;"><</div> | ||
<div class="navigate-foward">></div> | ||
</div> | ||
<div class="control-buttons" style="flex: 2"> | ||
<div class="title"></div> | ||
</div> | ||
</div> | ||
</navbar> | ||
<script src="renderer.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const fs = require('electron').remote.require('fs'); | ||
const os = require('electron').remote.require('os'); | ||
const path = require('electron').remote.require('path'); | ||
const {BrowserWindow} = require('electron').remote; | ||
const {clipboard} = require('electron'); | ||
|
||
const SERVER_URL = 'https://hackmd.io'; | ||
|
||
const isDarwin = os.platform() === 'darwin'; | ||
|
||
const winOption = { | ||
width: 1024, | ||
height: 768 | ||
} | ||
|
||
onload = () => { | ||
if (window.location.search !== '') { | ||
targetURL = window.location.search.match(/\?target=([^?]+)/)[1]; | ||
} else { | ||
targetURL = SERVER_URL; | ||
} | ||
|
||
document.body.innerHTML += `<webview src="${targetURL}" id="main-window" disablewebsecurity autosize="on" allowpopups allowfileaccessfromfiles></webview>`; | ||
|
||
const webview = document.getElementById("main-window"); | ||
|
||
webview.addEventListener('dom-ready', function(){ | ||
// set webview title | ||
document.querySelector('#navbar-container .title').innerHTML = webview.getTitle(); | ||
|
||
// set dark theme if in home page | ||
if (webview.getURL().split('?')[0].split('#')[0].match(/https:\/\/hackmd.io\/$/)) { | ||
document.querySelector('navbar').className = 'dark'; | ||
} else { | ||
document.querySelector('navbar').className = ''; | ||
} | ||
|
||
/* bind control buttons event */ | ||
document.querySelector('#navbar-container .navigate-back').onclick = () => { | ||
if (webview.canGoBack()) { | ||
webview.goBack(); | ||
} | ||
}; | ||
|
||
document.querySelector('#navbar-container .navigate-foward').onclick = () => { | ||
if (webview.canGoForward()) { | ||
webview.goForward(); | ||
} | ||
}; | ||
|
||
document.querySelector('#navbar-container .home').onclick = () => { | ||
webview.loadURL(SERVER_URL); | ||
} | ||
|
||
document.querySelector('#navbar-container .refresh').onclick = () => { | ||
webview.loadURL(webview.getURL()); | ||
} | ||
|
||
document.querySelector('#navbar-container .title').onclick = () => { | ||
clipboard.writeText(webview.getURL()); | ||
new Notification('URL copied', { title: 'URL copied', body: webview.getURL() }); | ||
} | ||
|
||
// webview.openDevTools(); | ||
}); | ||
|
||
/* handle _target=blank pages */ | ||
webview.addEventListener('new-window', (event) => { | ||
new BrowserWindow( | ||
(isDarwin | ||
? Object.assign({}, winOption, {titleBarStyle: 'hidden'}) | ||
: winOption) | ||
).loadURL(`file://${path.join(__dirname, `index.html?target=${event.url}`)}`); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.