-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefresh_every_n_seconds.html
More file actions
148 lines (128 loc) · 5.55 KB
/
Copy pathrefresh_every_n_seconds.html
File metadata and controls
148 lines (128 loc) · 5.55 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<!--
Author: Michael Stocker mic.sto@hotmail.com, crumbleworks.org
Date: 24.01.2016 - 12:54
What: HTML page to reload a specific website every n seconds
Copyright 2016 Michael Stocker, crumbleworks.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Webseite alle [token-refresh_zeit] Sekunden neu laden</title>
<meta charset="UTF-8">
<meta name="description" content="HTML Seite um eine beliebige Seite alle n Sekunden neu zu laden">
<meta name="author" content="Michael Stocker">
<style>
#body-content {
height: 98vh;
}
fieldset {
display: table;
}
fieldset p {
display: table-row;
padding: 10px;
}
fieldset p label {
width: 5.5em;
float: left;
text-align: right;
margin-right: 0.5em;
display: table-cell;
}
fieldset p span {
width: 100%;
display: table-cell;
}
fieldset p span input.text {
width: 100%;
}
object.embedded-web {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="body-content">
</div>
<script type="text/javascript">
//process URL query into a two dimensional array
var queryParams = {};
var tmp = [];
location.search.substr(1).split("&").forEach(
function(queryElement) {
tmp = queryElement.split("=");
queryParams[tmp[0]] = tmp[1] !== null ? tmp[1] : "true";
});
//returns the value of the param if one is assigned
//returns true if the param is set and no value is assigned (or true is assigned obviously)
//returns null if no param exists
//returns all params if no argument is given
function getParam(param) {
if(param) {
return queryParams[param] ? queryParams[param] : null;
}
return queryParams;
}
//function to encode unsafe elements according to RFC2396 + RFC2732
// '|' > %7C
function replaceUnsafeCharactersInURL(websiteURL) {
return websiteURL
.replace(/[|]/g, "%2C")
.replace(/[,]/g, "%7C");
}
//scriptlet to process
// refresh_zeit > time between refreshes
// refresh_seite > website to be reloaded each refresh
//function to embed a webpage
function replaceElementInnerHTMLWithWebsite(elementId, websiteURL) {
document.getElementById(elementId).innerHTML =
"<object class=\"embedded-web\" type=\"text/html\" data=\"" + websiteURL + "\">"
+ " <p>Fehler - Webseite konnte nicht gefunden/geladen werden.</p>"
+ "</object>";
}
if(/^(?:[A-Za-z][A-Za-z0-9+.-]*:\/{2})?(?:(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})+(?::(?:[A-Za-z0-9-._~]|[%][A-Fa-f0-9]{2})+)?@)?(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.){1,126}[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?::[0-9]+)?(?:\/(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})*)*(?:\?(?:[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)(?:[&|;][A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)*)?$/.test(replaceUnsafeCharactersInURL(decodeURIComponent(getParam("refresh_seite"))))
&& /^[0-9]+$/.test(getParam("refresh_zeit"))) {
//rewrite website title with data from url query
document.title = document.title.replace('[token-refresh_zeit]', getParam("refresh_zeit"));
//replace 'body-content' with iframe
replaceElementInnerHTMLWithWebsite("body-content", replaceUnsafeCharactersInURL(decodeURIComponent(getParam("refresh_seite")))); //run once in the beginning as setInterval waits for the interval to happen before first execution
window.setInterval(
function() {
replaceElementInnerHTMLWithWebsite("body-content", replaceUnsafeCharactersInURL(decodeURIComponent(getParam("refresh_seite"))))
},
getParam("refresh_zeit") * 1000
);
} else {
//print help text
document.getElementById("body-content").innerHTML =
"<p>Parameter 'refresh_zeit' benötigt eine Zahl in Sekunden als Wert. Bsp.:<BR/> > 4</p>"
+ "<p>Parameter 'refresh_seite' benötigt eine Webseite als Wert. Bsp.:<BR/> > http://crumbleworks.com</p>"
+ "<form>"
+ " <fieldset>"
+ " <legend>URL-Generator</legend>"
+ " <p>"
+ " <label>refresh_zeit:</label>"
+ " <span><input class=\"text\" type=\"text\" name=\"refresh_zeit\" value=\"20\" /></span>"
+ " </p>"
+ " <p>"
+ " <label>refresh_seite:</label>"
+ " <span><input class=\"text\" type=\"text\" name=\"refresh_seite\" value=\"http://crumbleworks.org\" /></span>"
+ " </p>"
+ " <input id=\"url-generator-submit\" type=\"submit\" />"
+ " </fieldset>"
+ "</form>";
}
</script>
</body>
</html>