summaryrefslogtreecommitdiff
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
initial
-rw-r--r--init.css3
-rw-r--r--init.js36
-rw-r--r--init.php28
3 files changed, 67 insertions, 0 deletions
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 @@
+<?php
+class Time_to_Read extends Plugin {
+ private $host;
+
+ function about() {
+ return array(1.0,
+ "Shows (approximate) time it takes to read an article, combined mode only",
+ "fox");
+ }
+
+ function init($host) {
+ $this->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;
+ }
+
+}