diff options
author | Andrew Dolgov <[email protected]> | 2019-02-27 15:17:56 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2019-02-27 15:17:56 +0300 |
commit | 69260ce229d3a80dfb13f751459ee9f2b32e98da (patch) | |
tree | ad066805512b7b04e5d7ec02fee99f54f49911d5 /init.js |
initial
Diffstat (limited to 'init.js')
-rw-r--r-- | init.js | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -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; + }); + }); + +}); |