Skip to content

Commit 08e72f4

Browse files
committed
Moved custom buttons to left in Perplexity chatbar to avoid constant pointless breaking UI changes ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/chatgpt-widescreen]
1 parent 50c7504 commit 08e72f4

File tree

10 files changed

+44
-72
lines changed

10 files changed

+44
-72
lines changed

chromium/extension/components/buttons.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ window.buttons = {
7070
`@media (max-width: 768px) {
7171
#fullWindow-btn { display: none }
7272
#widescreen-btn { margin-right: ${ site == 'perplexity' ? 9 : 19 }px }}`
73-
: '' }`
73+
: '' }
74+
${ site == 'perplexity' ? // hide native tooltip that persists for being in same parent
75+
`body:not(:has(button[role=radio]:hover)) ${selectors.tooltip} { display: none !important }` : '' }`
7476
))
7577
},
7678

@@ -152,23 +154,31 @@ window.buttons = {
152154

153155
async insert() {
154156
if (!config.btnsVisible || this.state.status == 'inserting' || this.fullscreen?.isConnected) return
157+
const { site } = this.imports.env
155158
this.state.status = 'inserting' ; if (!this.fullscreen) await this.create()
156159

157160
// Init elems
158161
const chatbarDiv = await chatbar.get() ; if (!chatbarDiv) return this.state.status = 'missing'
159162
const btnTypesToInsert = this.get.types.valid()
160-
const parentToInsertInto = (
161-
this.imports.env.site == 'chatgpt' ? (await this.get.rightBtn()).closest('[class*=bottom]') // right btn div
162-
: chatbarDiv.lastChild ) // parent of [Perplexity right btns or Poe Mic/Send btns]
163+
let parentToInsertInto = (
164+
site == 'chatgpt' ? (await this.get.rightBtn()).closest('[class*=bottom]') // right btn div
165+
: site == 'perplexity' ? chatbarDiv.querySelector('div[role=radiogroup]') // left mode btns div
166+
: /* poe */ chatbarDiv.lastChild ) // parent of Mic/Send btns
167+
if (site == 'perplexity') { // wrap in div to tweak side-gaps
168+
parentToInsertInto.append(this.btnsDiv = dom.create.elem('div', {
169+
style: 'display: flex ; margin-left: -36px ; margin-right: 9px ; align-items: center' }))
170+
parentToInsertInto = this.btnsDiv
171+
}
163172
const elemToInsertBefore = parentToInsertInto[
164-
this.imports.env.site == 'chatgpt' ? 'lastChild' // right btn
165-
: 'firstChild'] // Perplexity Pro spam toggle or Poe Mic btn
173+
site == 'poe' ? 'firstChild' // Mic btn
174+
: 'lastChild'] // right btn
166175

167176
// Insert buttons
177+
168178
btnTypesToInsert.slice().reverse().forEach((btnType, idx) => {
169179
const btn = this[btnType]
170180
this.update.svg(btnType) // update icon
171-
elemToInsertBefore.before(btn) // insert button
181+
parentToInsertInto.insertBefore(btn, elemToInsertBefore) // insert button
172182
if (!this.state.hasFadedIn) { // fade-in
173183
btn.style.opacity = 0 ; setTimeout(() => btn.style.opacity = 1, (idx +1) *30)
174184
if (idx == btnTypesToInsert.length -1) // final button scheduled for fade-in
@@ -181,7 +191,7 @@ window.buttons = {
181191

182192
async remove() {
183193
if (!await chatbar.get() || !this.fullscreen?.isConnected) return
184-
this.types.forEach(type => this[type]?.remove()) ; tooltip.div?.remove()
194+
['btnsDiv', ...this.types].filter(Boolean).forEach(type => this[type]?.remove()) ; tooltip.div?.remove()
185195
this.state.status = 'missing' // ensure next .insert() doesn't return early
186196
this.state.hasFadedIn = false // ensure next .insert() fades in buttons
187197
},

chromium/extension/components/tooltip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ window.tooltip = {
2626
toggle(event) {
2727
if (tooltip.imports.env.browser.isMobile) return
2828
tooltip.div = tooltip.div || dom.create.elem('div', { class: `${tooltip.imports.app.slug}-tooltip` })
29-
if (!tooltip.div.isConnected) event.currentTarget?.before(tooltip.div)
29+
if (!tooltip.div.isConnected) event.currentTarget?.after(tooltip.div)
3030
if (!tooltip.styles) tooltip.stylize()
3131
tooltip.update(event.currentTarget)
3232
tooltip.div.style.opacity = +(event.type == 'mouseenter')

chromium/extension/content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
}
167167
styles.tweaks.update() // sync TCB/NCB/HH/HF/BA
168168
styles.chatbar.update() // sync WCB
169-
chatbar.tweak() // update ChatGPT chatbar inner width or hack other sites' button positions
169+
if (env.site != 'perplexity') chatbar.tweak() // update ChatGPT chatbar inner width or hack Poe btn pos
170170
buttons[config.btnsVisible ? 'insert' : 'remove']() // update button visibility
171171
if (options?.updatedKey == 'btnAnimationsDisabled' && !config.btnAnimationsDisabled) // apply/remove fx
172172
// ...to visually signal location + preview fx applied by Button Animations toggle-on

chromium/extension/lib/chatbar.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ window.chatbar = {
2525
if (site == 'chatgpt') { // restore chatbar inner width
2626
const inputArea = chatbarDiv.querySelector(selectors.input)
2727
if (inputArea) inputArea.style.width = inputArea.parentNode.style.width = 'initial'
28-
} else if (site == 'perplexity') { // restore left-align right buttons
29-
const leftAlignedBtns = chatbarDiv.querySelectorAll('[data-left-aligned]')
30-
if (leftAlignedBtns.length) {
31-
const ogBtnParents = [...chatbarDiv.querySelectorAll('[data-btn-moved]')].reverse()
32-
leftAlignedBtns.forEach((btn, idx) => {
33-
ogBtnParents[idx].append(btn) ; ogBtnParents[idx].removeAttribute('data-btn-moved')
34-
btn.style.margin = '' ; btn.removeAttribute('data-left-aligned') // reset margins/attr
35-
})
36-
const modeDiv = chatbarDiv.querySelector('button').closest('div')
37-
modeDiv.style.marginRight = modeDiv.parentNode.style.paddingRight = '' // reset gap x-hacks
38-
}
3928
} else if (site == 'poe') // restore Attach File button icon + Poe Mic button position
4029
['attachFile', 'mic'].forEach(btnType => {
4130
const btn = chatbarDiv.querySelector(selectors.btns[btnType]) ; if (!btn) return
@@ -45,7 +34,7 @@ window.chatbar = {
4534
})
4635
},
4736

48-
async tweak() { // update ChatGPT chatbar inner width or hack Perplexity/Poe buttons
37+
async tweak() { // update ChatGPT chatbar inner width or hack Poe buttons
4938
const chatbarDiv = await this.get() ; if (!chatbarDiv) return
5039
const { site, sites: { [site]: { selectors }}} = this.imports
5140
if (site == 'chatgpt') { // update chatbar inner width
@@ -62,19 +51,6 @@ window.chatbar = {
6251
widths.chatbar - totalBtnWidths -43 }px`
6352
inputArea.style.width = '100%' // rid h-scrollbar
6453
}
65-
} else if (site == 'perplexity') { // left-align Attach File + Search src buttons
66-
const modeDiv = chatbarDiv.querySelector('button').closest('div') ; if (!modeDiv) return
67-
const rightBtns = {} ; ['attachFile', 'searchSrcs'].forEach(btnType =>
68-
rightBtns[btnType] = chatbarDiv.querySelector(selectors.btns[btnType]))
69-
Object.values(rightBtns).forEach(btn => { if (!btn) return
70-
btn.style.marginTop = '2px' // lower it
71-
btn.dataset.leftAligned = true ; btn.parentNode.dataset.btnMoved = true // for this.reset()
72-
modeDiv.after(btn) // move to right of selector
73-
})
74-
if (chatbarDiv.querySelector('[data-left-aligned]')) {
75-
modeDiv.style.marginRight = '-2px' // close gap vs. right buttons
76-
modeDiv.parentNode.style.paddingRight = '5px' // extend bg rightward
77-
}
7854
} else if (site == 'poe') { // replace Attach File btn icon + move Mic btn closer to Send
7955
const btnLoadTimeout = 5000
8056
dom.get.loadedElem(selectors.btns.attachFile, { timeout: btnLoadTimeout }).then(btn => {

chromium/extension/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const appReady = (async () => {
66
// Init APP data
77
const app = {
88
version: chrome.runtime.getManifest().version,
9-
latestResourceCommitHash: '196be4d', // for cached app.json + sites.json5 + icons.questionMark.src
9+
latestResourceCommitHash: '50c7504', // for cached app.json + sites.json5 + icons.questionMark.src
1010
urls: {},
1111
chatgptJSver: /v(\d+\.\d+\.\d+)/.exec(await (await fetch(chrome.runtime.getURL('lib/chatgpt.js'))).text())[1]
1212
}

firefox/extension/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Init APP data
55
const app = {
66
version: chrome.runtime.getManifest().version,
7-
latestResourceCommitHash: '196be4d', // for cached app.json + sites.json5 + icons.questionMark.src
7+
latestResourceCommitHash: '50c7504', // for cached app.json + sites.json5 + icons.questionMark.src
88
urls: {},
99
chatgptJSver: /v(\d+\.\d+\.\d+)/.exec(await (await fetch(chrome.runtime.getURL('lib/chatgpt.js'))).text())[1]
1010
}

firefox/extension/components/buttons.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ window.buttons = {
7070
`@media (max-width: 768px) {
7171
#fullWindow-btn { display: none }
7272
#widescreen-btn { margin-right: ${ site == 'perplexity' ? 9 : 19 }px }}`
73-
: '' }`
73+
: '' }
74+
${ site == 'perplexity' ? // hide native tooltip that persists for being in same parent
75+
`body:not(:has(button[role=radio]:hover)) ${selectors.tooltip} { display: none !important }` : '' }`
7476
))
7577
},
7678

@@ -152,23 +154,31 @@ window.buttons = {
152154

153155
async insert() {
154156
if (!config.btnsVisible || this.state.status == 'inserting' || this.fullscreen?.isConnected) return
157+
const { site } = this.imports.env
155158
this.state.status = 'inserting' ; if (!this.fullscreen) await this.create()
156159

157160
// Init elems
158161
const chatbarDiv = await chatbar.get() ; if (!chatbarDiv) return this.state.status = 'missing'
159162
const btnTypesToInsert = this.get.types.valid()
160-
const parentToInsertInto = (
161-
this.imports.env.site == 'chatgpt' ? (await this.get.rightBtn()).closest('[class*=bottom]') // right btn div
162-
: chatbarDiv.lastChild ) // parent of [Perplexity right btns or Poe Mic/Send btns]
163+
let parentToInsertInto = (
164+
site == 'chatgpt' ? (await this.get.rightBtn()).closest('[class*=bottom]') // right btn div
165+
: site == 'perplexity' ? chatbarDiv.querySelector('div[role=radiogroup]') // left mode btns div
166+
: /* poe */ chatbarDiv.lastChild ) // parent of Mic/Send btns
167+
if (site == 'perplexity') { // wrap in div to tweak side-gaps
168+
parentToInsertInto.append(this.btnsDiv = dom.create.elem('div', {
169+
style: 'display: flex ; margin-left: -36px ; margin-right: 9px ; align-items: center' }))
170+
parentToInsertInto = this.btnsDiv
171+
}
163172
const elemToInsertBefore = parentToInsertInto[
164-
this.imports.env.site == 'chatgpt' ? 'lastChild' // right btn
165-
: 'firstChild'] // Perplexity Pro spam toggle or Poe Mic btn
173+
site == 'poe' ? 'firstChild' // Mic btn
174+
: 'lastChild'] // right btn
166175

167176
// Insert buttons
177+
168178
btnTypesToInsert.slice().reverse().forEach((btnType, idx) => {
169179
const btn = this[btnType]
170180
this.update.svg(btnType) // update icon
171-
elemToInsertBefore.before(btn) // insert button
181+
parentToInsertInto.insertBefore(btn, elemToInsertBefore) // insert button
172182
if (!this.state.hasFadedIn) { // fade-in
173183
btn.style.opacity = 0 ; setTimeout(() => btn.style.opacity = 1, (idx +1) *30)
174184
if (idx == btnTypesToInsert.length -1) // final button scheduled for fade-in
@@ -181,7 +191,7 @@ window.buttons = {
181191

182192
async remove() {
183193
if (!await chatbar.get() || !this.fullscreen?.isConnected) return
184-
this.types.forEach(type => this[type]?.remove()) ; tooltip.div?.remove()
194+
['btnsDiv', ...this.types].filter(Boolean).forEach(type => this[type]?.remove()) ; tooltip.div?.remove()
185195
this.state.status = 'missing' // ensure next .insert() doesn't return early
186196
this.state.hasFadedIn = false // ensure next .insert() fades in buttons
187197
},

firefox/extension/components/tooltip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ window.tooltip = {
2626
toggle(event) {
2727
if (tooltip.imports.env.browser.isMobile) return
2828
tooltip.div = tooltip.div || dom.create.elem('div', { class: `${tooltip.imports.app.slug}-tooltip` })
29-
if (!tooltip.div.isConnected) event.currentTarget?.before(tooltip.div)
29+
if (!tooltip.div.isConnected) event.currentTarget?.after(tooltip.div)
3030
if (!tooltip.styles) tooltip.stylize()
3131
tooltip.update(event.currentTarget)
3232
tooltip.div.style.opacity = +(event.type == 'mouseenter')

firefox/extension/content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
}
167167
styles.tweaks.update() // sync TCB/NCB/HH/HF/BA
168168
styles.chatbar.update() // sync WCB
169-
chatbar.tweak() // update ChatGPT chatbar inner width or hack other sites' button positions
169+
if (env.site != 'perplexity') chatbar.tweak() // update ChatGPT chatbar inner width or hack Poe btn pos
170170
buttons[config.btnsVisible ? 'insert' : 'remove']() // update button visibility
171171
if (options?.updatedKey == 'btnAnimationsDisabled' && !config.btnAnimationsDisabled) // apply/remove fx
172172
// ...to visually signal location + preview fx applied by Button Animations toggle-on

firefox/extension/lib/chatbar.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ window.chatbar = {
2525
if (site == 'chatgpt') { // restore chatbar inner width
2626
const inputArea = chatbarDiv.querySelector(selectors.input)
2727
if (inputArea) inputArea.style.width = inputArea.parentNode.style.width = 'initial'
28-
} else if (site == 'perplexity') { // restore left-align right buttons
29-
const leftAlignedBtns = chatbarDiv.querySelectorAll('[data-left-aligned]')
30-
if (leftAlignedBtns.length) {
31-
const ogBtnParents = [...chatbarDiv.querySelectorAll('[data-btn-moved]')].reverse()
32-
leftAlignedBtns.forEach((btn, idx) => {
33-
ogBtnParents[idx].append(btn) ; ogBtnParents[idx].removeAttribute('data-btn-moved')
34-
btn.style.margin = '' ; btn.removeAttribute('data-left-aligned') // reset margins/attr
35-
})
36-
const modeDiv = chatbarDiv.querySelector('button').closest('div')
37-
modeDiv.style.marginRight = modeDiv.parentNode.style.paddingRight = '' // reset gap x-hacks
38-
}
3928
} else if (site == 'poe') // restore Attach File button icon + Poe Mic button position
4029
['attachFile', 'mic'].forEach(btnType => {
4130
const btn = chatbarDiv.querySelector(selectors.btns[btnType]) ; if (!btn) return
@@ -45,7 +34,7 @@ window.chatbar = {
4534
})
4635
},
4736

48-
async tweak() { // update ChatGPT chatbar inner width or hack Perplexity/Poe buttons
37+
async tweak() { // update ChatGPT chatbar inner width or hack Poe buttons
4938
const chatbarDiv = await this.get() ; if (!chatbarDiv) return
5039
const { site, sites: { [site]: { selectors }}} = this.imports
5140
if (site == 'chatgpt') { // update chatbar inner width
@@ -62,19 +51,6 @@ window.chatbar = {
6251
widths.chatbar - totalBtnWidths -43 }px`
6352
inputArea.style.width = '100%' // rid h-scrollbar
6453
}
65-
} else if (site == 'perplexity') { // left-align Attach File + Search src buttons
66-
const modeDiv = chatbarDiv.querySelector('button').closest('div') ; if (!modeDiv) return
67-
const rightBtns = {} ; ['attachFile', 'searchSrcs'].forEach(btnType =>
68-
rightBtns[btnType] = chatbarDiv.querySelector(selectors.btns[btnType]))
69-
Object.values(rightBtns).forEach(btn => { if (!btn) return
70-
btn.style.marginTop = '2px' // lower it
71-
btn.dataset.leftAligned = true ; btn.parentNode.dataset.btnMoved = true // for this.reset()
72-
modeDiv.after(btn) // move to right of selector
73-
})
74-
if (chatbarDiv.querySelector('[data-left-aligned]')) {
75-
modeDiv.style.marginRight = '-2px' // close gap vs. right buttons
76-
modeDiv.parentNode.style.paddingRight = '5px' // extend bg rightward
77-
}
7854
} else if (site == 'poe') { // replace Attach File btn icon + move Mic btn closer to Send
7955
const btnLoadTimeout = 5000
8056
dom.get.loadedElem(selectors.btns.attachFile, { timeout: btnLoadTimeout }).then(btn => {

0 commit comments

Comments
 (0)