clicking on the force completion message closes it forcing the completion. see #419

This commit is contained in:
Mic 2025-09-12 00:17:00 +02:00
parent 9e80391903
commit 78f2936d65

View file

@ -80,7 +80,8 @@ async function chatgpt_isIdle() {
const intervalId = setInterval(() => {
if (chatgpt_getRegenerateButton() || do_force_completion) {
clearInterval(intervalId); resolve(true);
}}, 100);});}
}
}, 100);});}
function chatgpt_getRegenerateButton() {
for (const mainSVG of document.querySelectorAll('main svg.icon')) {
@ -133,9 +134,9 @@ function addCustomDiv(prompt_action,tabId,mailMessageId) {
style.textContent += "#mzta-btn_close_diff{position:absolute;bottom:10px;left:50%;transform:translateX(-50%);}";
style.textContent += "#mzta-btn_change_reply_type{padding-left:4px;padding-right:10px;margin-left:0px;border-bottom-left-radius:0px;border-top-left-radius:0px;height:2.7em;}";
style.textContent += ".mzta-btn_reply{padding-right:4px;margin-right:0px;border-bottom-right-radius:0px;border-top-right-radius:0px;}";
style.textContent += "#mzta-arrow-hint{display:none;position:fixed;bottom:30px;right:90px;width:20em;background: #c3cefeff;color: #111827;padding:10px 14px;border-radius:12px;box-shadow:0 4px 10px rgba(0,0,0,.2);font-size:14px;font-weight:bold;z-index:2000;pointer-events:none;}";
style.textContent += "#mzta-arrow-hint .label{display:block;line-height:1.3;}";
style.textContent += "#mzta-arrow-hint svg{position:absolute;bottom:-10px;right:-20px;width:40px;height:40px;}";
style.textContent += "#mzta-forcecomp-hint{display:none;position:fixed;bottom:30px;right:90px;width:20em;background: #c3cefeff;color: #111827;padding:10px 14px;border-radius:12px;box-shadow:0 4px 10px rgba(0,0,0,.2);font-size:14px;font-weight:bold;z-index:2000;pointer:default;}";
style.textContent += "#mzta-forcecomp-hint .label{display:block;line-height:1.3;}";
style.textContent += "#mzta-forcecomp-hint svg{position:absolute;bottom:-10px;right:-20px;width:40px;height:40px;}";
// Add <style> to the page's <head>
document.head.appendChild(style);
@ -376,27 +377,37 @@ function addCustomDiv(prompt_action,tabId,mailMessageId) {
fixedDiv.appendChild(customDiv);
// light background hint with diagonal thick arrow
let arrowHint = document.createElement('div');
arrowHint.id = 'mzta-arrow-hint';
let forcecompletionHint_div = document.createElement('div');
forcecompletionHint_div.id = 'mzta-forcecomp-hint';
forcecompletionHint_div.addEventListener("click", () => {
do_force_completion = true;
});
let arrowLabel = document.createElement('span');
arrowLabel.className = 'label';
forcecompletionHint_div.style.cursor = 'default';
arrowLabel.textContent = browser.i18n.getMessage("chatgpt_click_force_completion");
arrowHint.appendChild(arrowLabel);
forcecompletionHint_div.appendChild(arrowLabel);
arrowLabel.addEventListener("click", () => {
do_force_completion = true;
});
// SVG solid arrow (triangle)
const svgNS = 'http://www.w3.org/2000/svg';
let hintArrow = document.createElementNS(svgNS, 'svg');
hintArrow.setAttribute('viewBox', '0 0 40 40');
hintArrow.addEventListener("click", () => {
do_force_completion = true;
});
let arrowPolygon = document.createElementNS(svgNS, 'polygon');
arrowPolygon.setAttribute('points', '0,0 40,40 0,28');
arrowPolygon.setAttribute('fill', '#c3cefeff');
hintArrow.appendChild(arrowPolygon);
arrowHint.appendChild(hintArrow);
forcecompletionHint_div.appendChild(hintArrow);
fixedDiv.appendChild(arrowHint);
fixedDiv.appendChild(forcecompletionHint_div);
document.body.insertBefore(fixedDiv, document.body.firstChild);
}
@ -511,7 +522,7 @@ function operation_done(){
}
document.getElementById('mzta-loading').style.display = 'none';
document.getElementById('mzta-force-completion').style.display = 'none';
document.getElementById('mzta-arrow-hint').style.display = 'none';
document.getElementById('mzta-forcecomp-hint').style.display = 'none';
chatpgt_scrollToBottom();
}
@ -571,11 +582,11 @@ async function doProceed(message, customText = ''){
curr_model_warn.insertAdjacentElement('afterend', btn_retry);
break;
}
const arrowHintTimeout = setTimeout(() => {
document.getElementById('mzta-arrow-hint').style.display = 'block';
const forcecompletionHintTimeout = setTimeout(() => {
document.getElementById('mzta-forcecomp-hint').style.display = 'block';
}, delay_wait_completion);
await chatgpt_isIdle();
clearTimeout(arrowHintTimeout);
clearTimeout(forcecompletionHintTimeout);
operation_done();
}