This commit is contained in:
Rudis Muiznieks 2023-09-25 14:30:00 -05:00
parent 1e6734567d
commit 0ffb8ba3a0
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
2 changed files with 23 additions and 5 deletions

View File

@ -25,7 +25,7 @@ class KagiSummarizerExtension extends Minz_Extension {
public function addSummarizeButton(FreshRSS_Entry $entry): FreshRSS_Entry {
$this->registerTranslates();
$entry->_content('<p class="kagi-summary"><a class="kagi-summary btn" data-url="' . urlencode($entry->link()) .' href="#">' . _t('ext.kagiSummarizer.ui.summarize_button') . '</a></p>' . $entry->content());
$entry->_content('<p class="kagi-summary"><a class="btn" data-url="' . urlencode($entry->link()) .' href="#">' . _t('ext.kagiSummarizer.ui.summarize_button') . '</a></p>' . $entry->content());
return $entry;
}
}

View File

@ -1,9 +1,27 @@
if (document.readyState && document.readyState !== 'loading') {
configureKagiButtons();
kagiSummarizeOnLoad();
} else {
document.addEventListener('DOMNodeInserted', configureKagiButtons, false);
document.addEventListener('DOMContentLoaded', kagiSummarizeOnLoad, false);
}
function configureKagiButtons() {
console.log('configuring kagi buttons');
function kagiSummarizeOnLoad() {
console.log('configuring kagi observer');
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
var hasClass = [].some.call(mutation.addedNodes, function(el) {
return el.classList.contains('kagi-summary');
});
if (hasClass) {
console.log('kagi observer triggered');
}
}
});
});
observer.observe(document.body, {
attributes: true,
childList: true,
characterData: true
});
}