summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-08-16 09:34:31 +0300
committerAndrew Dolgov <[email protected]>2019-08-16 09:34:31 +0300
commit5d15fcc8d09ddbea71ed9142918807079f796268 (patch)
treeaea6150ae6edec6563cb7e2bb095b3f9d3a4fa0e
parent20e94f987a8415673fbe760ef2d0ae17ab047d16 (diff)
move JS part to an appropriate context
-rwxr-xr-xinit.js31
1 files changed, 16 insertions, 15 deletions
diff --git a/init.js b/init.js
index da32676..1e1332e 100755
--- a/init.js
+++ b/init.js
@@ -1,30 +1,31 @@
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
const words_per_minute = 200;
- function inject_prompt(row) {
- try {
- const words = row.querySelector(".content-inner").textContent.split(/\s+/).length;
- const ttr = Math.round(words / words_per_minute).toFixed(0);
+ Plugins.Time_To_Read = {
+ inject_prompt: function(row) {
+ try {
+ const words = row.querySelector(".content-inner").textContent.split(/\s+/).length;
+ const ttr = Math.round(words / words_per_minute).toFixed(0);
- if (ttr > 1) {
+ if (ttr > 1) {
- const pr = document.createElement("span");
- pr.className = 'time-to-read text-muted';
- pr.innerHTML = __("Time to read: ~%s minutes.").replace("%s", ttr);
+ const pr = document.createElement("span");
+ pr.className = 'time-to-read text-muted';
+ pr.innerHTML = __("Time to read: ~%s minutes.").replace("%s", ttr);
- row.querySelector(".titleWrap").appendChild(pr);
- }
+ row.querySelector(".titleWrap").appendChild(pr);
+ }
- } catch (e) {
- console.warn(e);
+ } catch (e) {
+ console.warn(e);
+ }
}
-
- }
+ };
ready(function() {
PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) {
window.setTimeout(function() {
- inject_prompt(row);
+ Plugins.Time_To_Read.inject_prompt(row);
}, 100);
return true;