From 6db5e4b23a164995f578cc95fedbe088c54e4115 Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Mon, 25 Sep 2023 15:57:46 -0500 Subject: [PATCH] wip --- extension.php | 2 +- i18n/en/ext.php | 4 +++- static/script.js | 25 +++++++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/extension.php b/extension.php index aaae3e1..adfd5da 100644 --- a/extension.php +++ b/extension.php @@ -30,7 +30,7 @@ class KagiSummarizerExtension extends Minz_Extension { 'params' => array( 'id' => $entry->id() ))); - $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/i18n/en/ext.php b/i18n/en/ext.php index 08aac11..9860ca1 100644 --- a/i18n/en/ext.php +++ b/i18n/en/ext.php @@ -7,7 +7,9 @@ return array( 'kagi_token_help' => 'Copy and paste the "Session Link" from your Kagi Account settings.' ), 'ui' => array( - 'summarize_button' => 'Summarize' + 'summarize_button' => 'Summarize', + 'loading_summary' => 'Loading summary...', + 'error' => 'Error retrieving summary.' ) ) ); diff --git a/static/script.js b/static/script.js index eb54d03..cdbc9eb 100644 --- a/static/script.js +++ b/static/script.js @@ -5,14 +5,14 @@ if (document.readyState && document.readyState !== 'loading') { } function configureSummarizeButtons() { + console.log(window.context); document.getElementById('global').addEventListener('click', function(e) { - console.log('kagi handler triggered'); for (var target = e.target; target && target != this; target = target.parentNode) { if (target.matches('.kagi-summary a.btn')) { e.preventDefault(); e.stopPropagation(); if (target.href) { - summarizeButtonClick(target.href, target.parentNode); + summarizeButtonClick(target.href, target); } break; } @@ -20,8 +20,21 @@ function configureSummarizeButtons() { }, false); } -function summarizeButtonClick(url, container) { - container.innerHTML = url; - container.classList.add('alert'); - container.classList.add('alert-success'); +function summarizeButtonClick(url, button) { + var container = button.parentNode; + + var request = new XMLHttpRequest(); + request.open('POST', url, true); + request.responseType = 'json'; + + request.onload = function(e) { + if (this.status != 200) { + } + } + + request.onerror = function(e) { + badAjax(this.status == 403); + container.classList.add('alert'); + container.classList.add('alert-error'); + } }