summaryrefslogtreecommitdiff
path: root/init.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-02-27 15:17:56 +0300
committerAndrew Dolgov <[email protected]>2019-02-27 15:17:56 +0300
commit69260ce229d3a80dfb13f751459ee9f2b32e98da (patch)
treead066805512b7b04e5d7ec02fee99f54f49911d5 /init.js
initial
Diffstat (limited to 'init.js')
-rw-r--r--init.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/init.js b/init.js
new file mode 100644
index 0000000..8188a19
--- /dev/null
+++ b/init.js
@@ -0,0 +1,36 @@
+require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
+ const words_per_minute = 200;
+
+ function inject_prompt(row) {
+ try {
+ console.log('ip', row);
+
+ const words = row.querySelector(".content-inner").textContent.split(/\s+/).length;
+ const ttr = Math.round(words / words_per_minute).toFixed(0);
+
+ if (ttr > 1) {
+
+ const pr = document.createElement("span");
+ pr.className = 'time-to-read label';
+ pr.innerHTML = "Time to read: ~" + ttr + " minutes.";
+
+ row.querySelector(".titleWrap").appendChild(pr);
+ }
+
+ } catch (e) {
+ console.warn(e);
+ }
+
+ }
+
+ ready(function() {
+ PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) {
+ window.setTimeout(function() {
+ inject_prompt(row);
+ }, 100);
+
+ return true;
+ });
+ });
+
+});