summaryrefslogtreecommitdiff
path: root/qutebrowser/html/back.html
blob: 6128c41f74a2d24cf895e29f6eb2ce76529a27b8 (plain)
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
{% extends "base.html" %}

{% block script %}
const STATE_BACK = "back";
const STATE_FORWARD = "forward";

function switch_state(new_state) {
	history.replaceState(
		new_state,
		document.title,
		location.pathname + location.hash);
}

function go_back() {
	switch_state(STATE_FORWARD);
	history.back();
}

function go_forward() {
	switch_state(STATE_BACK);
	history.forward();
}

function prepare_restore() {
	if (!document.hidden) {
		go_back();
		return;
	}

	document.addEventListener("visibilitychange", go_back, {once: true});
}

// there are three states
// default: register focus listener,
//	    on focus: go back and switch to the state forward
// back: user came from a later history entry
//	 -> switch to the state forward,
//	    forward him to the previous history entry
// forward: user came from a previous history entry
//	 -> switch to the state back,
//	    forward him to the next history entry
switch (history.state) {
	case STATE_BACK:
		go_back();
		break;
	case STATE_FORWARD:
		go_forward();
		break;
	default:
		setTimeout(prepare_restore, 1000);
		break;
}
{% endblock %}

{% block content %}
<noscript><p>Javascript isn't enabled. So you need to manually go back in history to restore this tab.</p></noscript>
<p>Loading suspended page...<br>
<br>
If nothing happens, something went wrong or you disabled JavaScript.</p>
{% endblock %}