|
148 | 148 | // @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!) |
149 | 149 | // @author KudoAI |
150 | 150 | // @namespace https://kudoai.com |
151 | | -// @version 2025.3.31.6 |
| 151 | +// @version 2025.3.31.7 |
152 | 152 | // @license MIT |
153 | 153 | // @icon https://cdn.jsdelivr.net/gh/KudoAI/bravegpt@df624b0/assets/images/icons/bravegpt/icon48.png |
154 | 154 | // @icon64 https://cdn.jsdelivr.net/gh/KudoAI/bravegpt@df624b0/assets/images/icons/bravegpt/icon64.png |
|
2957 | 2957 | // * stateOrEvent: 'on'|'off' or button `event` |
2958 | 2958 |
|
2959 | 2959 | if (env.browser.isMobile) return |
| 2960 | + if (!tooltip.div) tooltip.div = dom.create.elem('div', { class: `${app.slug}-tooltip no-user-select` }) |
| 2961 | + if (!tooltip.div.isConnected) appDiv.append(tooltip.div) |
| 2962 | + if (!tooltip.styles) tooltip.stylize() |
| 2963 | + |
2960 | 2964 | if (stateOrEvent?.type == 'mouseleave' || stateOrEvent == 'off') |
2961 | | - return tooltipDiv.style.opacity = 0 |
| 2965 | + return tooltip.div.style.opacity = 0 |
2962 | 2966 |
|
2963 | 2967 | const btn = stateOrEvent.currentTarget, btnType = /[^-]+-([\w-]+)-btn/.exec(btn.id)[1] |
2964 | 2968 | const baseText = ( |
|
2993 | 2997 | : btnType == 'shuffle' ? app.msgs.tooltip_askRandQuestion |
2994 | 2998 | : btnType == 'summarize' ? app.msgs.tooltip_summarizeResults : '' ) |
2995 | 2999 |
|
2996 | | - // Update text |
2997 | | - tooltipDiv.innerText = baseText |
2998 | | - tooltip.nativeRpadding = tooltip.nativeRpadding |
2999 | | - || parseFloat(window.getComputedStyle(tooltipDiv).paddingRight) |
3000 | | - clearInterval(tooltip.dotCycler) |
3001 | | - if (baseText.endsWith('...')) { // animate the dots |
3002 | | - const noDotText = baseText.slice(0, -3), dotWidth = 2.75 ; let dotCnt = 3 |
3003 | | - tooltip.dotCycler = setInterval(() => { |
3004 | | - dotCnt = (dotCnt % 3) + 1 // cycle thru 1 → 2 → 3 |
3005 | | - tooltipDiv.innerText = noDotText + '.'.repeat(dotCnt) |
3006 | | - tooltipDiv.style.paddingRight = `${ // adjust based on dotCnt |
3007 | | - tooltip.nativeRpadding + (3 - dotCnt) * dotWidth }px` |
3008 | | - }, 350) |
3009 | | - } else // restore native right-padding |
3010 | | - tooltipDiv.style.paddingRight = tooltip.nativeRpadding |
| 3000 | + // Update text |
| 3001 | + tooltip.div.innerText = baseText |
| 3002 | + tooltip.nativeRpadding = tooltip.nativeRpadding |
| 3003 | + || parseFloat(window.getComputedStyle(tooltip.div).paddingRight) |
| 3004 | + clearInterval(tooltip.dotCycler) |
| 3005 | + if (baseText.endsWith('...')) { // animate the dots |
| 3006 | + const noDotText = baseText.slice(0, -3), dotWidth = 2.75 ; let dotCnt = 3 |
| 3007 | + tooltip.dotCycler = setInterval(() => { |
| 3008 | + dotCnt = (dotCnt % 3) + 1 // cycle thru 1 → 2 → 3 |
| 3009 | + tooltip.div.innerText = noDotText + '.'.repeat(dotCnt) |
| 3010 | + tooltip.div.style.paddingRight = `${ // adjust based on dotCnt |
| 3011 | + tooltip.nativeRpadding + (3 - dotCnt) * dotWidth }px` |
| 3012 | + }, 350) |
| 3013 | + } else // restore native right-padding |
| 3014 | + tooltip.div.style.paddingRight = tooltip.nativeRpadding |
3011 | 3015 |
|
3012 | 3016 | // Update position |
3013 | | - const elems = { appDiv, btn, btnsDiv: btn.closest('[id*=btns], [class*=btns]'), tooltipDiv } |
| 3017 | + const elems = { appDiv, btn, btnsDiv: btn.closest('[id*=btns], [class*=btns]'), tooltipDiv: tooltip.div } |
3014 | 3018 | const rects = {} ; Object.keys(elems).forEach(key => rects[key] = elems[key]?.getBoundingClientRect()) |
3015 | | - tooltipDiv.style.top = `${ rects[rects.btnsDiv ? 'btnsDiv' : 'btn'].top - rects.appDiv.top -37 }px` |
3016 | | - tooltipDiv.style.right = `${ |
| 3019 | + tooltip.div.style.top = `${ rects[rects.btnsDiv ? 'btnsDiv' : 'btn'].top - rects.appDiv.top -37 }px` |
| 3020 | + tooltip.div.style.right = `${ |
3017 | 3021 | rects.appDiv.right -( rects.btn.left + rects.btn.right )/2 - rects.tooltipDiv.width/2 }px` |
3018 | 3022 |
|
3019 | 3023 | // Show tooltip |
3020 | | - tooltipDiv.style.opacity = 1 |
| 3024 | + tooltip.div.style.opacity = 1 |
3021 | 3025 | } |
3022 | 3026 | } |
3023 | 3027 |
|
|
3984 | 3988 | arrowsBtn.append(icons.arrowsDiagonal.create()) ; headerBtnsDiv.append(arrowsBtn) |
3985 | 3989 | } |
3986 | 3990 |
|
3987 | | - // Add tooltips |
3988 | | - if (!env.browser.isMobile) appDiv.append(tooltipDiv) |
3989 | | - |
3990 | 3991 | // Add app header button listeners |
3991 | 3992 | addListeners.appHeaderBtns() |
3992 | 3993 |
|
|
4081 | 4082 | show.reply.updatedAPIinHeader = true |
4082 | 4083 | const preHeaderLabel = appDiv.querySelector('.reply-header-text') |
4083 | 4084 | preHeaderLabel.replaceChildren(`⦿ API ${app.msgs.componentLabel_used}: `, dom.create.elem('b')) |
4084 | | - console.log(apiUsed) |
4085 | 4085 | setTimeout(() => type(apiUsed, preHeaderLabel.lastChild, { speed: 1.5 }), 150) |
4086 | 4086 | function type(text, targetElem, { speed = 1 } = {}) { |
4087 | 4087 | targetElem.textContent = '' ; let i = 0; |
|
4393 | 4393 | ['rpg', 'rpw'].forEach(cssType => // rising particles |
4394 | 4394 | document.head.append(dom.create.style(GM_getResourceText(`${cssType}CSS`)))) |
4395 | 4395 |
|
4396 | | - // Create/stylize TOOLTIPs |
4397 | | - const tooltipDiv = dom.create.elem('div', { class: `${app.slug}-tooltip no-user-select` }) ; tooltip.stylize() |
4398 | | - |
4399 | 4396 | // APPEND to Brave |
4400 | 4397 | const appDivParentSelector = env.browser.isMobile ? '#results' : '.sidebar' |
4401 | 4398 | const appDivParent = await new Promise(resolve => { |
|
4464 | 4461 | ['anchored', 'expanded', 'sticky', 'wider'].forEach(mode => |
4465 | 4462 | (config[mode] || config[`${mode}Sidebar`]) && appDiv.classList.add(mode)) |
4466 | 4463 | appDiv.innerHTML = saveAppDiv.html |
4467 | | - if (!env.browser.isMobile) { tooltipDiv.style.opacity = 0 ; appDiv.append(tooltipDiv) } |
4468 | 4464 | if (appDiv.querySelector(`.${app.slug}-header-btn`)) addListeners.appHeaderBtns() |
4469 | 4465 | appDiv.querySelectorAll(`.${app.slug}-standby-btn`).forEach((btn, idx) => |
4470 | 4466 | btn.onclick = show.reply[`${['query', 'summarize'][idx]}BtnClickHandler`]) |
|
0 commit comments