forked from I2P_Developers/i2p.i2p
Merge branch 'graphs-js' into 'master'
Console: js refresh of graphs See merge request i2p-hackers/i2p.i2p!199
This commit is contained in:
@ -70,7 +70,15 @@ public class GraphHelper extends FormHandler {
|
||||
ConfigRestartBean.getRestartTimeRemaining() < (1000 * (_refreshDelaySeconds + 30)))
|
||||
return "";
|
||||
// shorten the refresh by 3 seconds so we beat the iframe
|
||||
return "<meta http-equiv=\"refresh\" content=\"" + (_refreshDelaySeconds - 3) + "\">";
|
||||
return "<noscript><meta http-equiv=\"refresh\" content=\"" + (_refreshDelaySeconds - 3) + ";url=/graphs\" /></noscript>";
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.63
|
||||
*/
|
||||
public int getRefresh() {
|
||||
// shorten the refresh by 3 seconds so we beat the iframe
|
||||
return _refreshDelaySeconds - 3;
|
||||
}
|
||||
|
||||
public void setPeriodCount(String str) {
|
||||
|
@ -16,6 +16,12 @@
|
||||
boolean allowRefresh = intl.allowIFrame(request.getHeader("User-Agent"));
|
||||
if (allowRefresh) {
|
||||
out.print(graphHelper.getRefreshMeta());
|
||||
%>
|
||||
<script nonce="<%=cspNonce%>" type="text/javascript">
|
||||
var graphRefreshInterval = "<%=graphHelper.getRefresh()%>";
|
||||
</script>
|
||||
<script src="/js/graphs.js?<%=net.i2p.CoreVersion.VERSION%>" type="text/javascript"></script>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<%@include file="summaryajax.jsi" %>
|
||||
|
31
apps/routerconsole/jsp/js/graphs.js
Normal file
31
apps/routerconsole/jsp/js/graphs.js
Normal file
@ -0,0 +1,31 @@
|
||||
/* I2P+ graphs.js by dr|z3d */
|
||||
/* Ajax graph refresh and configuration toggle */
|
||||
/* Adapted from I2P+, licensed to I2P under our license */
|
||||
|
||||
var __graphs_counter = 0;
|
||||
|
||||
function initGraphs() {
|
||||
if (graphRefreshInterval > 0) {
|
||||
setTimeout(updateGraphs, graphRefreshInterval * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function updateGraphs() {
|
||||
const param = '&g=' + (++__graphs_counter);
|
||||
var images = document.getElementsByClassName("statimage");
|
||||
for (var i = 0; i < images.length; i++) {
|
||||
let image = images[i];
|
||||
// https://stackoverflow.com/questions/1077041/refresh-image-with-a-new-one-at-the-same-url
|
||||
let idx = image.src.indexOf('&g=');
|
||||
if (idx > 0) {
|
||||
image.src = image.src.substring(0, idx) + param;
|
||||
} else {
|
||||
image.src = image.src + param;
|
||||
}
|
||||
}
|
||||
setTimeout(updateGraphs, graphRefreshInterval * 1000);
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
initGraphs();
|
||||
});
|
Reference in New Issue
Block a user