wip
This commit is contained in:
parent
ba8c2a8a9b
commit
6db5e4b23a
|
@ -30,7 +30,7 @@ class KagiSummarizerExtension extends Minz_Extension {
|
|||
'params' => array(
|
||||
'id' => $entry->id()
|
||||
)));
|
||||
$entry->_content('<p class="kagi-summary"><a class="btn" href="' . $url .'">' . _t('ext.kagiSummarizer.ui.summarize_button') . '</a></p>' . $entry->content());
|
||||
$entry->_content('<p class="kagi-summary"><a data-loading="' . htmlspecialchars(_t('ext.kagiSummarizer.ui.loading_summary')) . '" data-error="' . htmlspecialchars(_t('ext.kagiSummarizer.ui.error')) . '" class="btn" href="' . $url .'">' . _t('ext.kagiSummarizer.ui.summarize_button') . '</a></p>' . $entry->content());
|
||||
return $entry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ return array(
|
|||
'kagi_token_help' => 'Copy and paste the "Session Link" from your <a href="https://kagi.com/settings?p=user_details" target="_blank">Kagi Account</a> settings.'
|
||||
),
|
||||
'ui' => array(
|
||||
'summarize_button' => 'Summarize'
|
||||
'summarize_button' => 'Summarize',
|
||||
'loading_summary' => 'Loading summary...',
|
||||
'error' => 'Error retrieving summary.'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue