diff options
author | Andrew Dolgov <[email protected]> | 2021-03-10 18:15:47 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-03-10 18:15:47 +0300 |
commit | 921e576e994b2cf7dfc52db3a90e08cd1c10589e (patch) | |
tree | bc407feaadc7eeff4d410735a7598838642130d8 | |
parent | a0b020cdc7c14c7eb41130d51f11036c1cac6fde (diff) |
shorten everything
-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; }); }); |