From 921e576e994b2cf7dfc52db3a90e08cd1c10589e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Mar 2021 18:15:47 +0300 Subject: shorten everything --- init.js | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'init.js') 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; }); }); -- cgit v1.2.3