diff options
Diffstat (limited to 'plugins/af_readability')
-rw-r--r-- | plugins/af_readability/init.js | 33 | ||||
-rwxr-xr-x | plugins/af_readability/init.php | 25 |
2 files changed, 58 insertions, 0 deletions
diff --git a/plugins/af_readability/init.js b/plugins/af_readability/init.js new file mode 100644 index 000000000..644dff9fe --- /dev/null +++ b/plugins/af_readability/init.js @@ -0,0 +1,33 @@ +Plugins.Af_Readability = { + orig_attr_name: 'data-readability-orig-content', + self: this, + embed: function(id) { + const content = $$(App.isCombinedMode() ? ".cdm[data-article-id=" + id + "] .content-inner" : + ".post[data-article-id=" + id + "] .content")[0]; + + if (content.hasAttribute(self.orig_attr_name)) { + content.innerHTML = content.getAttribute(self.orig_attr_name); + content.removeAttribute(self.orig_attr_name); + + if (App.isCombinedMode()) Article.cdmScrollToId(id); + + return; + } + + Notify.progress("Loading, please wait..."); + + xhrJson("backend.php",{ op: "pluginhandler", plugin: "af_readability", method: "embed", param: id }, (reply) => { + + if (content && reply.content) { + content.setAttribute(self.orig_attr_name, content.innerHTML); + content.innerHTML = reply.content; + Notify.close(); + + if (App.isCombinedMode()) Article.cdmScrollToId(id); + + } else { + Notify.error("Unable to fetch full text for this article"); + } + }); + } +}; diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index a487707c8..9c62a4772 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -38,6 +38,7 @@ class Af_Readability extends Plugin { $host->add_hook($host::HOOK_PREFS_TAB, $this); $host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this); $host->add_hook($host::HOOK_PREFS_SAVE_FEED, $this); + $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); // Note: we have to install the hook even if disabled because init() is being run before plugin data has loaded // so we can't check for our storage-set options here @@ -46,6 +47,15 @@ class Af_Readability extends Plugin { $host->add_filter_action($this, "action_inline", __("Inline content")); } + function get_js() { + return file_get_contents(__DIR__ . "/init.js"); + } + + function hook_article_button($line) { + return "<i class='material-icons' onclick=\"Plugins.Af_Readability.embed(".$line["id"].")\" + style='cursor : pointer' title='".__('Toggle full article text')."'>description</i>"; + } + function hook_prefs_tab($args) { if ($args != "prefFeeds") return; @@ -284,4 +294,19 @@ class Af_Readability extends Plugin { return $tmp; } + function embed() { + $article_id = (int) $_REQUEST["param"]; + + $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries WHERE id = ?"); + $sth->execute([$article_id]); + + $ret = []; + + if ($row = $sth->fetch()) { + $ret["content"] = sanitize($this->extract_content($row["link"])); + } + + print json_encode($ret); + } + } |