/* global xhr, App, Plugins, Article, Notify */ Plugins.Af_Fulltext = { orig_attr_name: 'data-af-fulltext-orig-content', /** * Toggle extracted content in place for one article. * * Doubles as the rule-debugging loop: edit a rule, hit the button, see the * result immediately -- and the notification names the rule that produced it, * so a rule that quietly stopped matching is visible rather than merely * disappointing. */ embed: function(id) { const content = document.querySelector(App.isCombinedMode() ? `.cdm[data-article-id="${id}"] .content-inner` : `.post[data-article-id="${id}"] .content`); if (!content) return; if (content.hasAttribute(this.orig_attr_name)) { content.innerHTML = content.getAttribute(this.orig_attr_name); content.removeAttribute(this.orig_attr_name); if (App.isCombinedMode()) Article.cdmMoveToId(id); return; } Notify.progress("Extracting, please wait..."); xhr.json("backend.php", App.getPhArgs("af_fulltext", "embed", {id: id}), (reply) => { if (reply && reply.content) { content.setAttribute(this.orig_attr_name, content.innerHTML); content.innerHTML = reply.content; Notify.info(reply.summary || "Extracted"); if (App.isCombinedMode()) Article.cdmMoveToId(id); } else { const why = reply && reply.errors && reply.errors.length ? reply.errors[0] : "no content extracted"; Notify.error("af_fulltext: " + why); } }); } };