diff options
Diffstat (limited to 'init.js')
-rw-r--r-- | init.js | 46 |
1 files changed, 16 insertions, 30 deletions
@@ -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; }); }); |