Skip to content

Commit fb9bf89

Browse files
committed
add skip roll animation toggle
1 parent 52940a6 commit fb9bf89

2 files changed

Lines changed: 64 additions & 3 deletions

File tree

static/js/task.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ function isSpecialRollUser() {
99
return SPECIAL_ROLL_USERNAMES.has(getCurrentUsername());
1010
}
1111

12+
function isShaduKatUser() {
13+
return getCurrentUsername() === 'shadukat';
14+
}
15+
16+
function getCookieValue(name) {
17+
const encodedName = `${encodeURIComponent(name)}=`;
18+
const cookies = document.cookie ? document.cookie.split(';') : [];
19+
for (let i = 0; i < cookies.length; i += 1) {
20+
const cookie = cookies[i].trim();
21+
if (cookie.indexOf(encodedName) === 0) {
22+
return decodeURIComponent(cookie.substring(encodedName.length));
23+
}
24+
}
25+
return null;
26+
}
27+
28+
function shouldSkipRollAnimation() {
29+
return getCookieValue('skip_roll_animation') === 'true';
30+
}
31+
1232
function shuffleArray(items) {
1333
const cloned = items.slice();
1434
for (let i = cloned.length - 1; i > 0; i -= 1) {
@@ -109,6 +129,7 @@ function rollTaskModal(options) {
109129
finalName,
110130
finalImage,
111131
instant = false,
132+
showSpecialMessage = false,
112133
candidates = []
113134
} = options;
114135

@@ -142,7 +163,7 @@ function rollTaskModal(options) {
142163
}
143164

144165
const finalImageSource = resolveTaskImageSource(finalImage);
145-
specialNode.hidden = !instant;
166+
specialNode.hidden = !showSpecialMessage;
146167

147168
if (instant) {
148169
imageNode.src = finalImageSource;
@@ -184,7 +205,8 @@ $(document).on('click', '#start', function(){
184205
await rollTaskModal({
185206
finalName: data.name,
186207
finalImage: data.image,
187-
instant: isSpecialRollUser(),
208+
instant: isSpecialRollUser() || shouldSkipRollAnimation(),
209+
showSpecialMessage: isShaduKatUser() && shouldSkipRollAnimation(),
188210
candidates: rollCandidates
189211
});
190212

@@ -242,7 +264,8 @@ $(document).on('click', '#generate_unofficial', function(){
242264
await rollTaskModal({
243265
finalName: data.name,
244266
finalImage: data.image,
245-
instant: isSpecialRollUser(),
267+
instant: isSpecialRollUser() || shouldSkipRollAnimation(),
268+
showSpecialMessage: isShaduKatUser() && shouldSkipRollAnimation(),
246269
candidates: rollCandidates.length > 0 ? rollCandidates : getOfficialRollCandidates()
247270
});
248271

templates/profile.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ <h3>{{username}} Profile</h3>
8585
{% endif %}
8686
<span class="slider round"></span>
8787
</label>
88+
<p>Skip Roll Animation</p>
89+
<label class="switch">
90+
<input type="checkbox" id="skip_roll_animation">
91+
<span class="slider round"></span>
92+
</label>
8893
</div>
8994
<div class="warning-section">
9095
<p id="warning"style="display: none;" class="incomplete">!!!YOU CANNOT RE-ENABLE OFFICIAL STATUS!!!</p>
@@ -232,7 +237,40 @@ <h3>{{username}} Profile</h3>
232237
</script>
233238

234239
<script>
240+
function getCookieValue(name) {
241+
const encodedName = `${encodeURIComponent(name)}=`;
242+
const cookies = document.cookie ? document.cookie.split(';') : [];
243+
for (let i = 0; i < cookies.length; i++) {
244+
const cookie = cookies[i].trim();
245+
if (cookie.indexOf(encodedName) === 0) {
246+
return decodeURIComponent(cookie.substring(encodedName.length));
247+
}
248+
}
249+
return null;
250+
}
251+
252+
function setCookieValue(name, value, maxAgeSeconds) {
253+
document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; path=/; max-age=${maxAgeSeconds}; SameSite=Lax`;
254+
}
255+
235256
$(document).ready(function() {
257+
const skipRollToggle = document.getElementById('skip_roll_animation');
258+
if (skipRollToggle) {
259+
const cookieValue = getCookieValue('skip_roll_animation');
260+
skipRollToggle.checked = cookieValue === 'true';
261+
262+
skipRollToggle.addEventListener('change', function(e) {
263+
const enabled = e.target.checked;
264+
setCookieValue('skip_roll_animation', enabled ? 'true' : 'false', 31536000);
265+
if (enabled) {
266+
alert('Roll animation will now be skipped when generating tasks.');
267+
}
268+
else {
269+
alert('Roll animation is now enabled when generating tasks.');
270+
}
271+
});
272+
}
273+
236274

237275
$('#lms_status').on('change', function(e) {
238276
var lms_status = e.target.checked;

0 commit comments

Comments
 (0)