-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_background_js.php
More file actions
164 lines (156 loc) · 6.85 KB
/
random_background_js.php
File metadata and controls
164 lines (156 loc) · 6.85 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
require_once 'site_global.php';
require_once 'random_background.php';
require_once 'log_navigation.php';
header("Content-Type: application/json; charset=UTF-8");
?>
// This depends on <script src="<?php echo $JSRANDOM;?>"></script>
// This also depends on <script src="<?php echo $JSCOOKIE;?>"></script>
var BackgroundImageList = <?php echo json_encode($background_image_list); ?>;
var SpecialImageList = <?php echo json_encode($special_image_list); ?>;
var SafeSpecialImageList = <?php echo json_encode($safe_special_image_list); ?>;
var BoringImageList = <?php echo json_encode($boring_image_list); ?>;
var TodayDirExists = <?php echo $today_dir_exists ? "1" : "0"; ?>;
var VisitorIP = "<?php echo $VISITOR_IP; ?>";
var OnePixelBG = "<?php echo $ONE_PIXEL_ICON; ?>";
var BG_CUTE = "<?php echo $BG_CUTE_ICON; ?>";
var BG_ON = "<?php echo $BG_ON_ICON; ?>";
var BG_OFF = "<?php echo $BG_OFF_ICON; ?>";
var Random = new MersenneTwister();
var NoBackground = Cookies.get('nobackground') || false;
var BoringBackground = Cookies.get('boringbackground') || false;
//var NSFW = Cookies.get('nsfw') || false;
var NSFW = true;
function toggleBackground() {
NoBackground = Cookies.get('nobackground') || false;
Cookies.remove("boringbackground");
if(NoBackground) {
// Turn it on now.
Cookies.remove("nobackground");
NoBackground = false;
if(NSFW) {
$("#navbar-button-background").attr("src", BG_CUTE);
} else {
$("#navbar-button-background").attr("src", BG_ON);
}
$("#navbar-button-background").attr("title", "Make boring.");
} else {
Cookies.set("nobackground", true);
NoBackground = true;
$("#navbar-button-background").attr("src", BG_OFF);
$("#navbar-button-background").attr("title", "Make kawaii!");
}
randomizeBackground();
}
function syncBackgroundToggleIcon() {
NoBackground = Cookies.get('nobackground') || false;
Cookies.remove("boringbackground");
if(NoBackground) {
$("#navbar-button-background").attr("src", BG_OFF);
$("#navbar-button-background").attr("title", "Make kawaii!");
} else {
if(NSFW) {
$("#navbar-button-background").attr("src", BG_CUTE);
} else {
$("#navbar-button-background").attr("src", BG_ON);
}
$("#navbar-button-background").attr("title", "Make boring.");
}
}
function new_syncBackgroundToggleIcon() {
NoBackground = Cookies.get('nobackground') || false;
BoringBackground = Cookies.get('boringbackground') || false;
if(NoBackground) {
$("#navbar-button-background").attr("src", BG_OFF);
$("#navbar-button-background").attr("title", "Make colorful.");
} else if(BoringBackground) {
$("#navbar-button-background").attr("src", BG_ON);
$("#navbar-button-background").attr("title", "Make kawaii!");
} else {
$("#navbar-button-background").attr("src", BG_CUTE);
$("#navbar-button-background").attr("title", "Make boring.");
}
}
function new_toggleBackground() {
NoBackground = Cookies.get('nobackground') || false;
BoringBackground = Cookies.get('boringbackground') || false;
if(NoBackground) {
// We have no background, but want generic, safe, boring backgrounds.
Cookies.remove("nobackground");
NoBackground = false;
Cookies.set("boringbackground", true);
BoringBackground = true;
$("#navbar-button-background").attr("src", BG_ON);
$("#navbar-button-background").attr("title", "Make kawaii!");
} else if(BoringBackground) {
// We have backgrounds, but want super cute backgrounds!
Cookies.remove("nobackground");
NoBackground = false;
Cookies.remove("boringbackground");
BoringBackground = false;
$("#navbar-button-background").attr("src", BG_CUTE);
$("#navbar-button-background").attr("title", "Make boring.");
} else {
// We are cute, but we want no backgrounds at all.
Cookies.set("nobackground", true);
NoBackground = true;
Cookies.set("boringbackground", true);
BoringBackground = true;
$("#navbar-button-background").attr("src", BG_OFF);
$("#navbar-button-background").attr("title", "Make colorful.");
}
randomizeBackground();
}
function orig_randomizeBackground() {
if(NoBackground) {
$("#background-img").attr("src", OnePixelBG);
} else {
if(BoringBackground) {
// We do NOT want to do special day overrides if you are in boring mode.
var bg_choice = Math.floor(BoringImageList.length * Random.random());
var new_bg = "<?php echo "$BORING_DIR_URL/"; ?>" + BoringImageList[bg_choice];
$("#background-img").attr("src", new_bg);
} else if(TodayDirExists) {
var bg_choice = Math.floor(SpecialImageList.length * Random.random());
var new_bg = "<?php echo "$SPECIAL_DIR_URL/"; ?>" + SpecialImageList[bg_choice];
$("#background-img").attr("src", new_bg);
} else {
var bg_choice = Math.floor(BackgroundImageList.length * Random.random());
var new_bg = "<?php echo "$BACKGROUND_DIR_URL/"; ?>" + BackgroundImageList[bg_choice];
$("#background-img").attr("src", new_bg);
}
}
}
function randomizeBackground() {
if(NoBackground) {
$("#background-img").attr("src", OnePixelBG);
} else {
if(TodayDirExists) {
if(NSFW) {
var bg_choice = Math.floor(SpecialImageList.length * Random.random());
var new_bg = "<?php echo "$SPECIAL_DIR_URL/"; ?>" + SpecialImageList[bg_choice];
$("#background-img").attr("src", new_bg);
console.log("Today NSFW Picked " + new_bg);
} else {
var bg_choice = Math.floor(SafeSpecialImageList.length * Random.random());
var new_bg = "<?php echo "$SPECIAL_DIR_URL/"; ?>" + SafeSpecialImageList[bg_choice];
$("#background-img").attr("src", new_bg);
console.log("Today Picked " + new_bg);
}
} else {
if(NSFW) {
// We said we're OK with overly cute anime images.
var bg_choice = Math.floor(BackgroundImageList.length * Random.random());
var new_bg = "<?php echo "$BACKGROUND_DIR_URL/"; ?>" + BackgroundImageList[bg_choice];
$("#background-img").attr("src", new_bg);
console.log("NSFW Picked " + new_bg);
} else {
// This lets us be SFW, unless Today overrides it.
var bg_choice = Math.floor(BoringImageList.length * Random.random());
var new_bg = "<?php echo "$BORING_DIR_URL/"; ?>" + BoringImageList[bg_choice];
$("#background-img").attr("src", new_bg);
console.log("Picked " + new_bg);
}
}
}
}