aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2024-07-17 00:00:00 +0000
committertdro <tdro@noreply.example.com>2024-07-17 00:00:00 +0000
commitb8b1c93608bb8c2ed5c262bb71a35ccf948f773c (patch)
tree4ef5a917e3fc82ad7c82a4c1c7b1edd128d6150d
parentc0707719c84652ab37130cf6eb107fb5e5b83979 (diff)
downloadcanory-b8b1c93608bb8c2ed5c262bb71a35ccf948f773c.tar.gz
canory-b8b1c93608bb8c2ed5c262bb71a35ccf948f773c.tar.bz2
canory-b8b1c93608bb8c2ed5c262bb71a35ccf948f773c.zip
static/js/autoplay: Add default state
-rw-r--r--assets/js/index.js5
-rw-r--r--static/js/autoplay.ts8
2 files changed, 11 insertions, 2 deletions
diff --git a/assets/js/index.js b/assets/js/index.js
index d698127..c230a42 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -520,6 +520,9 @@
const view = element.getBoundingClientRect();
return view.top >= -options.offset.top && view.left >= -options.offset.left && view.bottom <= (self.innerHeight || document.documentElement.clientHeight) + options.offset.bottom && view.right <= (self.innerWidth || document.documentElement.clientWidth) + options.offset.right;
}
+ const state = "on";
+ const key = "config.video.autoplay";
+ if (!localStorage[key]) localStorage[key] = state;
[
"scroll",
"DOMContentLoaded"
@@ -539,7 +542,7 @@
videos[i].setAttribute("muted", true);
videos[i].setAttribute("playsinline", true);
const onscreen = viewport(videos[i]);
- if (first && onscreen) {
+ if (first && onscreen && localStorage[key] === state) {
videos[i].play();
first = false;
} else {
diff --git a/static/js/autoplay.ts b/static/js/autoplay.ts
index 5987576..9a47c2e 100644
--- a/static/js/autoplay.ts
+++ b/static/js/autoplay.ts
@@ -10,8 +10,14 @@
&& view.right <= (self.innerWidth || document.documentElement.clientWidth) + options.offset.right;
};
+ const state = "on";
+ const key = "config.video.autoplay";
+
+ if (!localStorage[key]) localStorage[key] = state;
+
["scroll", "DOMContentLoaded"].forEach(function (event) {
self.addEventListener(event, function () {
+
let first = true;
let videos = document.querySelectorAll("video");
@@ -30,7 +36,7 @@
const onscreen = viewport(videos[i]);
- if (first && onscreen) {
+ if (first && onscreen && localStorage[key] === state) {
videos[i].play();
first = false;
} else {