Skip to content

js-based view-source #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,19 @@ def get(self, out_format='json'):


def security_headers(response, secure=False):
csp = "default-src 'none'; " \
"style-src https://fonts.googleapis.com 'self'; " \
"font-src https://fonts.gstatic.com; " \
"img-src data:; script-src 'self'; " \
"sandbox allow-same-origin allow-scripts; " \
csp = "default-src 'none'; " \
"style-src https://fonts.googleapis.com 'self'; " \
"font-src https://fonts.gstatic.com; " \
"img-src data:; script-src 'self'; connect-src 'self'; " \
"sandbox allow-same-origin allow-scripts; " \
"frame-ancestors 'none'"

response.headers['Content-Security-Policy'] = csp
response.headers['Referrer-Policy'] = 'no-referrer'
response.headers['X-Content-Type-Options'] = 'nosniff'
response.headers['X-Frame-Options'] = 'DENY'
response.headers['X-XSS-Protection'] = '1; mode=block'
response.headers['Content-Security-Policy'] = csp
response.headers['Referrer-Policy'] = 'no-referrer'
response.headers['X-Content-Type-Options'] = 'nosniff'
response.headers['X-Frame-Options'] = 'DENY'
response.headers['X-XSS-Protection'] = '1; mode=block'
response.headers['Access-Control-Allow-Origin'] = 'https://hashbang.sh/'

if secure:
response.headers['Strict-Transport-Security'] = 'max-age=31536000'
Expand Down
5 changes: 3 additions & 2 deletions src/hashbang.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@
<meta name="MobileOptimized" content="320"/>
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
<link href="/assets/local.css" rel="stylesheet" type="text/css">
<link type="image/png" rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQAAAAA3iMLMAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAAYSURBVAjXY2CAAck+EKp/B0II9gMoGwYA4+MJkeae/NUAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTQtMDUtMTdUMTM6MzI6MTMtMDQ6MDB7pieOAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE0LTA1LTE3VDEzOjMxOjQ4LTA0OjAwqyt+rwAAAABJRU5ErkJggg==">
</head>
<body>
<script src="/assets/icon.js"></script>
<script src="/assets/scripts.js"></script>
<h1>#!</h1>
<a href="view-source:https://hashbang.sh">
<a id="view-source" href="view-source:https://hashbang.sh">
<code>sh <(curl hashbang.sh | gpg)</code>
</a>
</body>
Expand Down
6 changes: 0 additions & 6 deletions src/icon.js

This file was deleted.

16 changes: 15 additions & 1 deletion src/local.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* {
body {
text-indent:-9999px;
-webkit-touch-callout: none;
-webkit-user-select: none;
Expand Down Expand Up @@ -48,3 +48,17 @@ code {
text-align:center;
font-size:20px;
}

#source {
display:block;
background:black;
position:absolute
top:0px;
left:0px;
right:0px;
bottom:0px;
color:white;
font-family: monospace;
white-space: pre;
overflow:scroll;
}
20 changes: 20 additions & 0 deletions src/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
window.onload = function(){
console.log("loaded")
window.location="#!"

var sourceEl = document.getElementById("view-source")
sourceEl.removeAttribute("href");
sourceEl.onclick = function(){
var client = new XMLHttpRequest();
client.open('GET', 'https://hashbang.sh/');
client.onreadystatechange = function() {
console.log(client.responseText)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug log left over?

var div = document.createElement("div");
var sourceText = document.createTextNode(client.responseText)
div.appendChild(sourceText)
div.id = "source"
document.getElementsByTagName("html")[0].appendChild(div);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of document.getElementsByTagName("html")[0] why not use document.firstElementChild?
But also, shouldn't you be appending to document.body anyway?

}
client.send();
}
}