Skip to content

Commit 67121a7

Browse files
committed
added Caption based on fileName
1 parent 3b23a3d commit 67121a7

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

BrowserImageSlideshow.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
margin: auto;
2525
overflow: hidden;
2626
}
27+
#caption {
28+
height: 30%;
29+
width: 100%;
30+
position: fixed;
31+
bottom: 0;
32+
color: white;
33+
font-size: 7em;
34+
display: flex;
35+
align-items: center;
36+
justify-content: center;
37+
text-align: center;
38+
text-shadow: -2px 2px black, -2px -2px black, 2px -2px black, 2px 2px black, 5px 5px 2px black;
39+
}
2740
</style>
2841

2942
<script src="jquery-3.4.1.min.js"></script>
@@ -64,6 +77,11 @@
6477
let imageContainer = document.getElementById("imageContainer");
6578
imageContainer.appendChild(botImage);
6679
imageContainer.appendChild(topImage);
80+
if(captionEnabled) {
81+
const caption = document.createElement("div");
82+
caption.id = "caption";
83+
imageContainer.appendChild(caption);
84+
}
6785
topImage.id = "topImage";
6886
botImage.id = "botImage";
6987

@@ -137,6 +155,9 @@
137155
}
138156
}
139157
);
158+
if(captionEnabled) {
159+
setImageCaption(imageSrc);
160+
}
140161

141162
fadeInTop = !fadeInTop;
142163
}
@@ -161,6 +182,12 @@
161182
start();
162183
}
163184

185+
function setImageCaption(imageSrc) {
186+
let filename = imageSrc.replace(/^.*[\\/]/, '');
187+
filename = filename.substr(0, filename.lastIndexOf('.')) || filename;
188+
caption.innerText = filename;
189+
}
190+
164191
// called once when the browser source loads or restarts
165192
function start() {
166193
topImage.style.opacity = "0.0";
@@ -175,6 +202,9 @@
175202
}
176203

177204
botImage.src = images[indexes[index]];
205+
if(captionEnabled) {
206+
setImageCaption(images[indexes[index]]);
207+
}
178208
$("#botImage").animate(
179209
{ opacity: 1.0 },
180210
{ duration: fadeDuration }

SlideshowSettings.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ loopSlideshow = true
1616
startWithAutoplay = true
1717
browserSourceName = "Browser"
1818
local mode_options = {"Random Order", "Alphabetical Order", "Alphabetical order, start on random"}
19+
captionEnabled = false
1920

2021
HK_PAUSE = obs.OBS_INVALID_HOTKEY_ID
2122
HK_RESUME = obs.OBS_INVALID_HOTKEY_ID
@@ -57,6 +58,7 @@ function script_properties()
5758
obs.obs_properties_add_int(props, "slideDuration", "Slide duration (ms):", minSlideDuration, maxSlideDuration, 500)
5859
obs.obs_properties_add_bool(props, "startWithAutoplay", "Autoplay")
5960
obs.obs_properties_add_bool(props, "loopSlideshow", "Loop slideshow")
61+
obs.obs_properties_add_bool(props, "captionEnabled", "Add Captaions based on filename")
6062
obs.obs_properties_add_text(props, "browserSourceName", "Browser source name:\n(for use with hotkeys)", obs.OBS_TEXT_DEFAULT)
6163
obs.obs_properties_add_button(props, "refreshButton", "Refresh", refresh_source)
6264
return props
@@ -130,6 +132,7 @@ function script_load(settings)
130132
obs.obs_data_set_default_int(settings, "slideDuration", defaultSlideDuration)
131133
obs.obs_data_set_default_bool(settings, "startWithAutoplay", true)
132134
obs.obs_data_set_default_bool(settings, "loopSlideshow", true)
135+
obs.obs_data_set_default_bool(settings, "captionEnabled", false)
133136
obs.obs_data_set_default_string(settings, "browserSourceName", "Browser")
134137
update_image_list()
135138

@@ -181,6 +184,7 @@ function script_update(settings)
181184
mode = obs.obs_data_get_int(settings, "mode")
182185
slideDuration = obs.obs_data_get_int(settings, "slideDuration")
183186
loopSlideshow = obs.obs_data_get_bool(settings, "loopSlideshow")
187+
captionEnabled = obs.obs_data_get_bool(settings, "captionEnabled")
184188
startWithAutoplay = obs.obs_data_get_bool(settings, "startWithAutoplay")
185189
browserSourceName = obs.obs_data_get_string(settings, "browserSourceName")
186190

@@ -198,6 +202,12 @@ function script_update(settings)
198202
else
199203
output:write('let startWithAutoplay = false;\n')
200204
end
205+
206+
if captionEnabled == true then
207+
output:write('let captionEnabled = true;\n')
208+
else
209+
output:write('let captionEnabled = false;\n')
210+
end
201211

202212
output:close()
203213
-- log_slideshow_info()
@@ -281,5 +291,6 @@ function log_slideshow_info()
281291
"\" | mode: ".. mode_options[mode+1] ..
282292
" | slide duration: ".. slideDuration ..
283293
"ms | loop: " .. tostring(loopSlideshow) ..
284-
" | autoplay: " .. tostring(startWithAutoplay))
294+
" | autoplay: " .. tostring(startWithAutoplay) ..
295+
" | captionEnabled: " .. tostring(captionEnabled))
285296
end

settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
let mode = 0;
22
let slideDuration = 4000;
33
let loopSlideshow = true;
4+
let captionEnabled = false;
45
let startWithAutoplay = true;

0 commit comments

Comments
 (0)