Skip to content

Commit 336d013

Browse files
committed
Add alphanumeric order
1 parent 58ffdca commit 336d013

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

BrowserImageSlideshow.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@
4545
<script src="settings.js"></script>
4646
<script>
4747

48-
// modes (defined in settings.js):
48+
// modes
4949
// 0: Random order (default)
5050
// 1: Alphabetical order
5151
// 2: Alphabetical order (start on random image)
52+
// 3: Alphanumeric
5253

5354
// common extensions from here https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
5455
const imageExtensions = ["apng", "avif", "gif", "jpg", "jpeg", "jfif", "pjpeg", "pjp", "png", "svg", "webp", "bmp", "ico", "cur"];
@@ -107,6 +108,17 @@
107108
return a;
108109
}
109110

111+
// Sort list of images alpha numerically
112+
function alphanumericSort() {
113+
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#numeric
114+
const collator = new Intl.Collator(undefined, {
115+
numeric: true
116+
});
117+
images.sort((a, b) => {
118+
return collator.compare(a, b);
119+
});
120+
}
121+
110122
function randomizeIndex(max) {
111123
index = Math.floor(Math.random() * max); // [0, max)
112124
}
@@ -213,13 +225,16 @@
213225
shuffle(indexes);
214226
} else if (mode === 2) { // choose random image to start on
215227
randomizeIndex(images.length);
228+
} else if (mode === 3) {
229+
alphanumericSort();
216230
}
217231

218-
botImage.src = images[indexes[index]];
219232
if(captionEnabled) {
220233
generateCaptions();
221234
setCaption(captions[indexes[index]]);
222235
}
236+
237+
botImage.src = images[indexes[index]];
223238
$("#botImage").animate(
224239
{ opacity: 1.0 },
225240
{ duration: fadeDuration }

README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Useful for slideshows that may exceed the 250mb uncompressed limit in older vers
4242
0: Random order (default)
4343
1: Alphabetical order
4444
2: Alphabetical order (start on random image)
45+
3: Alphanumeric order
4546
slideDuration: duration in milliseconds (default 4000)
4647
loopSlideshow: if true, the slideshow will repeat. in Random order mode, images will be reshuffled. (default true)
4748
startWithAutoplay: if true, the slideshow will start playing automatically. untick this option if you wish to control slides manually via hotkeys.

SlideshowSettings.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ maxSlideDuration = 100000
1515
loopSlideshow = true
1616
startWithAutoplay = true
1717
browserSourceName = "Browser"
18-
local mode_options = {"Random Order", "Alphabetical Order", "Alphabetical Order, start on random"}
18+
local mode_options = {"Random Order", "Alphabetical Order", "Alphabetical Order, start on random", "Alphanumeric"}
1919
captionEnabled = false
2020

2121
HK_PAUSE = obs.OBS_INVALID_HOTKEY_ID

0 commit comments

Comments
 (0)