2021-02-19 15:47:50 +00:00
|
|
|
/* global xhr, App, Plugins, Article, Notify */
|
|
|
|
|
2020-02-27 04:59:57 +00:00
|
|
|
Plugins.Af_Readability = {
|
2020-02-28 05:03:25 +00:00
|
|
|
orig_attr_name: 'data-readability-orig-content',
|
|
|
|
self: this,
|
2020-02-27 04:59:57 +00:00
|
|
|
embed: function(id) {
|
2021-02-19 15:47:50 +00:00
|
|
|
const content = App.find(App.isCombinedMode() ? `.cdm[data-article-id="${id}"] .content-inner` :
|
|
|
|
`.post[data-article-id="${id}"] .content`);
|
2020-02-28 05:03:25 +00:00
|
|
|
|
|
|
|
if (content.hasAttribute(self.orig_attr_name)) {
|
|
|
|
content.innerHTML = content.getAttribute(self.orig_attr_name);
|
|
|
|
content.removeAttribute(self.orig_attr_name);
|
|
|
|
|
2020-05-09 05:16:12 +00:00
|
|
|
if (App.isCombinedMode()) Article.cdmMoveToId(id);
|
2020-02-28 05:03:25 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-27 04:59:57 +00:00
|
|
|
Notify.progress("Loading, please wait...");
|
|
|
|
|
2021-02-19 07:22:00 +00:00
|
|
|
xhr.json("backend.php", App.getPhArgs("af_readability", "embed", {id: id}), (reply) => {
|
2020-02-27 04:59:57 +00:00
|
|
|
|
|
|
|
if (content && reply.content) {
|
2020-02-28 05:03:25 +00:00
|
|
|
content.setAttribute(self.orig_attr_name, content.innerHTML);
|
2020-02-27 04:59:57 +00:00
|
|
|
content.innerHTML = reply.content;
|
|
|
|
Notify.close();
|
2020-02-28 05:03:25 +00:00
|
|
|
|
2020-05-09 05:16:12 +00:00
|
|
|
if (App.isCombinedMode()) Article.cdmMoveToId(id);
|
2020-02-28 05:03:25 +00:00
|
|
|
|
2020-02-27 04:59:57 +00:00
|
|
|
} else {
|
2020-02-28 05:03:25 +00:00
|
|
|
Notify.error("Unable to fetch full text for this article");
|
2020-02-27 04:59:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|