-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframe.html
More file actions
77 lines (76 loc) · 2.22 KB
/
frame.html
File metadata and controls
77 lines (76 loc) · 2.22 KB
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
<!DOCTYPE html>
<style>
html, body {
height: 100%;
margin: 0;
}
iframe {
width: 100%;
height: 100%;
border: 0;
margin: 0;
padding: 0;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
</style>
<iframe id="frame" allowfullscreen></iframe>
<script>
(function(){
var frame = document.getElementById('frame');
var conn = new WebSocket("ws://localhost:8000/__ws");
if (window.location.hash == "") {
window.location = '#/index.html';
}
frame.src = window.location.hash.substring(1);
function stripPrefix(str) {
var parser = document.createElement('a');
parser.href = str;
return parser.pathname.substring(1);
}
function checkCollection(collection, attr, value) {
if (!collection) return false;
for (var i=0; i<collection.length; i++) {
console.log(collection[i], stripPrefix(collection[i][attr]));
if (collection[i][attr] && decodeURI(stripPrefix(collection[i][attr])) == value) {
return true;
}
}
return false;
}
function checkDocument(doc, filename) {
var currentPath = doc.location.pathname.substring(1);
if (currentPath[currentPath.length-1] == '/') currentPath = currentPath + 'index.html';
if (currentPath == filename) {
console.log('reloading ' + filename);
doc.location.reload();
return;
}
if(checkCollection(doc.images, 'src', filename) ||
checkCollection(doc.scripts, 'src', filename) ||
checkCollection(doc.embed, 'src', filename) ||
checkCollection(doc.styleSheets, 'href', filename)){
doc.location.reload();
return;
}
var frames = doc.getElementsByTagName('iframe');
for (var i=0; i<frames.length; i++) checkDocument(frames[i].contentDocument, filename);
}
conn.onmessage = function(message) {
var filename = message.data;
console.log(filename);
var doc = frame.contentDocument;
checkDocument(doc,filename);
};
frame.onload = function onframeload(e) {
window.location = '#' + frame.contentDocument.location.pathname;
};
window.onhashchange = function onhashchange(e) {
var path = location.hash.substring(1);
if (path != frame.contentDocument.location.pathname) frame.src = path;
};
})();
</script>