-
Notifications
You must be signed in to change notification settings - Fork 2
/
z0ruck.js
170 lines (149 loc) · 4.35 KB
/
z0ruck.js
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
var FLASH_WIDTH = 600;
var FLASH_HEIGHT = 450;
// special value that indicates initialization state and shouldn't be put on
// the stack
var curflashloop = -1;
// array that serves as size-limited stack to allow skipping back and to
// prevent showing the same flash loops too frequent
var MAX_ARRAY_SIZE = 100;
var shownflashloops = new Array();
function setVisibility(id, visible, block) {
if (visible)
if (block)
document.getElementById(id).style.display = "block";
else
document.getElementById(id).style.display = "inline";
else
document.getElementById(id).style.display = "none";
}
function validateNumber(n) {
if (typeof n == "string") {
var nu = parseInt(n);
if (!isNaN(nu) && nu >= 0 && nu < TOTAL_FLASH_COUNT)
return nu;
else
return -1;
}
else
return -1;
}
function addOldFlash() {
if (curflashloop != -1) {
if (shownflashloops.length >= MAX_ARRAY_SIZE)
shownflashloops = shownflashloops.slice(1, MAX_ARRAY_SIZE);
shownflashloops.push(curflashloop);
} else return false;
}
function replaceFlash() {
document.title = "ZOMG ZUFALL! #" + curflashloop;
document.location.hash = curflashloop;
document.getElementById("onlinelink").innerHTML =
"Online link: <a href=\"http://z0r.de/" + curflashloop +
"\">http://z0r.de/" + curflashloop + "</a>";
// works a lot faster and easier than recursively emptying the DOM tree
document.getElementById("content").innerHTML = "";
if (curflashloop <= 0)
setVisibility("prev", false, false);
else
setVisibility("prev", true, false);
if (curflashloop >= TOTAL_FLASH_COUNT - 1)
setVisibility("next", false, false);
else
setVisibility("next", true, false);
if (shownflashloops.length == 0)
setVisibility("back", false, false);
else
setVisibility("back", true, false);
// ADAPT FILE NAME SCHEMA HERE
var flashpath = "z0r-" + curflashloop + ".swf";
// for leeching directly off z0r.de (don't do it)
//var flashpath = "http://raz.z0r.de/L/z0r-de_" + curflashloop + ".swf";
/* HTML code produced by this DOM thingy:
<object type="application/x-shockwave-flash" data="$FLASHPATH"
width="$FLASH_WIDTH" height="$FLASH_HEIGHT">
<param name="movie" value="$FLASHPATH">
</object> */
var flashobj = document.createElement("object");
flashobj.setAttribute("type", "application/x-shockwave-flash");
flashobj.setAttribute("data", flashpath);
flashobj.setAttribute("width", FLASH_WIDTH);
flashobj.setAttribute("height", FLASH_HEIGHT);
var theParam = document.createElement("param");
theParam.setAttribute("name", "movie");
theParam.setAttribute("value", flashpath);
flashobj.appendChild(theParam);
document.getElementById("content").appendChild(flashobj);
}
function prevFlash() {
if (curflashloop <= 0)
return false;
else {
addOldFlash();
curflashloop--;
replaceFlash();
}
}
function nextFlash() {
if (curflashloop >= TOTAL_FLASH_COUNT - 1)
return false;
else {
addOldFlash();
curflashloop++;
replaceFlash();
}
}
function randomFlash() {
var alreadyshown = true;
var rndflashloop;
while (alreadyshown) {
rndflashloop = Math.floor(Math.random() * TOTAL_FLASH_COUNT);
alreadyshown = false;
for (var i = 0; i++; i < shownflashloops.length) {
if (shownflashloops[i] == rndflashloop) {
alreadyshown = true;
break;
}
}
}
addOldFlash();
curflashloop = rndflashloop;
replaceFlash();
}
function lastFlash() {
if (shownflashloops.length == 0)
return false;
else {
curflashloop = shownflashloops.pop();
replaceFlash();
}
}
function flashByNumber() {
var input = validateNumber(prompt("Jump to which flash loop (0 through " +
(TOTAL_FLASH_COUNT - 1) + ")?", ""));
if (input != -1) {
addOldFlash();
curflashloop = input;
replaceFlash();
}
}
window.onload = window.onpopstate = function() {
document.getElementById("prev").onclick = prevFlash;
document.getElementById("rand").onclick = randomFlash;
document.getElementById("next").onclick = nextFlash;
document.getElementById("back").onclick = lastFlash;
document.getElementById("bynum").onclick = flashByNumber;
document.getElementById("main").style.width = FLASH_WIDTH + "px";
document.getElementById("content").style.minHeight = FLASH_HEIGHT + "px";
setVisibility("onlinelink", true, true);
if (location.hash.length > 1) {
var input = validateNumber(location.hash.substring(1));
if (input != -1) {
curflashloop = input;
replaceFlash();
}
else
randomFlash();
}
else
randomFlash();
}