From 0ffb8ba3a0f1c005e6b1be76ce1f46414145ac2f Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Mon, 25 Sep 2023 14:30:00 -0500 Subject: [PATCH] wip --- extension.php | 2 +- static/script.js | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/extension.php b/extension.php index d703d97..22be9a3 100644 --- a/extension.php +++ b/extension.php @@ -25,7 +25,7 @@ class KagiSummarizerExtension extends Minz_Extension { public function addSummarizeButton(FreshRSS_Entry $entry): FreshRSS_Entry { $this->registerTranslates(); - $entry->_content('

' . _t('ext.kagiSummarizer.ui.summarize_button') . '

' . $entry->content()); + $entry->_content('

' . _t('ext.kagiSummarizer.ui.summarize_button') . '

' . $entry->content()); return $entry; } } diff --git a/static/script.js b/static/script.js index bb7b350..2a2431f 100644 --- a/static/script.js +++ b/static/script.js @@ -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 + }); }