From 69260ce229d3a80dfb13f751459ee9f2b32e98da Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 27 Feb 2019 15:17:56 +0300 Subject: initial --- init.css | 3 +++ init.js | 36 ++++++++++++++++++++++++++++++++++++ init.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 init.css create mode 100644 init.js create mode 100644 init.php diff --git a/init.css b/init.css new file mode 100644 index 0000000..628756b --- /dev/null +++ b/init.css @@ -0,0 +1,3 @@ +.time-to-read { + color : black; +} 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; + }); + }); + +}); diff --git a/init.php b/init.php new file mode 100644 index 0000000..8103739 --- /dev/null +++ b/init.php @@ -0,0 +1,28 @@ +host = $host; + + } + + function get_js() { + return file_get_contents(__DIR__ . "/init.js"); + } + + function get_css() { + return file_get_contents(__DIR__ . "/init.css"); + } + + function api_version() { + return 2; + } + +} -- cgit v1.2.3