summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-10 18:15:47 +0300
committerAndrew Dolgov <[email protected]>2021-03-10 18:15:47 +0300
commit921e576e994b2cf7dfc52db3a90e08cd1c10589e (patch)
treebc407feaadc7eeff4d410735a7598838642130d8
parenta0b020cdc7c14c7eb41130d51f11036c1cac6fde (diff)
shorten everything
-rw-r--r--init.js46
1 files changed, 16 insertions, 30 deletions
diff --git a/init.js b/init.js
index 28e7ec7..6c17de5 100644
--- a/init.js
+++ b/init.js
@@ -1,40 +1,26 @@
+/* global require, PluginHost */
+
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
+ function pause(vid) {
+ vid.removeAttribute("autoplay");
+ vid.pause();
+ vid.onclick = () => {
+ this.paused ? this.play() : this.pause();
+ }
+ }
+
+ function pause_all(row) {
+ [...row.querySelectorAll("video")].forEach((vid) => pause(vid));
+ }
+
ready(function () {
PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function (row) {
- if (row) {
- console.log("af_zz_noautoplay!");
- console.log(row);
-
- const videos = row.getElementsByTagName("video");
- console.log(row.innerHTML);
-
- for (i = 0; i < videos.length; i++) {
-
- videos[i].removeAttribute("autoplay");
- videos[i].pause();
- videos[i].onclick = function () {
- this.paused ? this.play() : this.pause();
- }
- }
- }
-
+ pause_all(row);
return true;
});
PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED, function (row) {
- if (row) {
- const videos = row.getElementsByTagName("video");
-
- for (i = 0; i < videos.length; i++) {
- videos[i].removeAttribute("autoplay");
- videos[i].pause();
- videos[i].onclick = function () {
- this.paused ? this.play() : this.pause();
- }
- }
-
- }
-
+ pause_all(row);
return true;
});
});