Skip to content

Commit 7ba884e

Browse files
committed
Updated chatbar.<tweak|reset> to move Perplexity Search button back to left where it belongs ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/chatgpt-widescreen]
1 parent 11ca185 commit 7ba884e

File tree

4 files changed

+44
-32
lines changed

4 files changed

+44
-32
lines changed

chromium/extension/lib/chatbar.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@ window.chatbar = {
2626
if (site == 'chatgpt') { // restore chatbar inner width
2727
const inputArea = chatbarDiv.querySelector(selectors.input)
2828
if (inputArea) inputArea.style.width = inputArea.parentNode.style.width = 'initial'
29-
} else if (site == 'perplexity') { // remove left-align Attach File button
30-
const attachFileBtn = chatbarDiv.querySelector(selectors.btns.attachFile)
31-
if (attachFileBtn?.getAttribute('left-aligned')) {
29+
} else if (site == 'perplexity') { // remove left-align Attach File + Search buttons
30+
const leftAlignedBtns = chatbarDiv.querySelectorAll('[left-aligned]')
31+
if (leftAlignedBtns.length) {
3232
const sendBtn = chatbarDiv.querySelector(selectors.btns.send) ; if (!sendBtn) return
33-
sendBtn.before(attachFileBtn.parentNode) ; attachFileBtn.removeAttribute('left-aligned')
34-
if (await this.is.tall()) attachFileBtn.style.marginRight = ''
33+
leftAlignedBtns.forEach(btn => {
34+
sendBtn.parentNode.before(btn.parentNode) // restore to left of Send
35+
btn.style.margin = '' ; btn.removeAttribute('left-aligned') // reset margins/attr
36+
})
37+
chatbarDiv.querySelector('button').closest('div').style.marginRight = '' // reset gap
3538
}
3639
} else if (site == 'poe') { // restore Poe Mic button position
3740
const micBtn = chatbarDiv.querySelector(selectors.btns.mic) ; if (!micBtn) return
3841
micBtn.style.marginRight = ''
3942
}
4043
},
4144

42-
async tweak() { // update ChatGPT chatbar inner width or left-align Perplexity Attach File btn or move Poe Mic btn right
45+
async tweak() { // update ChatGPT chatbar inner width or left-align Perplexity btns or move Poe Mic btn right
4346
const site = this.imports.site
4447
const chatbarDiv = await this.get() ; if (!chatbarDiv) return
4548
const selectors = this.imports.sites[site].selectors
@@ -57,15 +60,18 @@ window.chatbar = {
5760
widths.chatbar - totalBtnWidths -43 }px`
5861
inputArea.style.width = '100%' // rid h-scrollbar
5962
}
60-
} else if (site == 'perplexity') { // left-align Attach File button
61-
const attachFileBtn = chatbarDiv.querySelector(selectors.btns.attachFile) ; if (!attachFileBtn) return
62-
let newParent = chatbarDiv
63-
if (await this.is.tall()) { // select new newParent
64-
newParent = chatbarDiv.querySelector('div:has(> span > button)') // left button cluster
65-
attachFileBtn.style.marginRight = '-10px' // bring Search button closer
66-
}
67-
newParent?.children[1]?.before(attachFileBtn.parentNode)
68-
attachFileBtn.setAttribute('left-aligned', true)
63+
} else if (site == 'perplexity') { // left-align Attach File + Search buttons
64+
const rightBtns = {} ; ['attachFile', 'search'].forEach(btnType =>
65+
rightBtns[btnType] = chatbarDiv.querySelector(selectors.btns[btnType]))
66+
const modelSelectorDiv = chatbarDiv.querySelector('button').closest('div')
67+
if (!modelSelectorDiv) return // in case of breaking DOM update
68+
Object.values(rightBtns).forEach(btn => {
69+
if (!btn) return
70+
modelSelectorDiv.after(btn.parentNode) // move to right of selector
71+
btn.style.margin = '0 -5px' // close x-gap
72+
btn.setAttribute('left-aligned', true) // for this.reset()
73+
})
74+
if (chatbarDiv.querySelector('[left-aligned]')) modelSelectorDiv.style.marginRight = '3px' // close gap
6975
} else if (site == 'poe') // move Mic btn closer to Send
7076
dom.get.loadedElem(selectors.btns.mic, { timeout: 5000 })
7177
.then(btn => { if (btn) btn.style.marginRight = '-7px' })

chromium/extension/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ chrome.runtime.onMessage.addListener(async req => {
3232
// Init APP data
3333
const app = {
3434
version: chrome.runtime.getManifest().version,
35-
latestResourceCommitHash: 'e0bb4b5', // for cached app.json + sites.json5 + icons.questionMark.src
35+
latestResourceCommitHash: '11ca185', // for cached app.json + sites.json5 + icons.questionMark.src
3636
urls: {},
3737
chatgptJSver: /v(\d+\.\d+\.\d+)/.exec(await (await fetch(chrome.runtime.getURL('lib/chatgpt.js'))).text())[1]
3838
}

firefox/extension/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ chrome.runtime.onMessage.addListener(async req => {
3232
// Init APP data
3333
const app = {
3434
version: chrome.runtime.getManifest().version,
35-
latestResourceCommitHash: 'e0bb4b5', // for cached app.json + sites.json5 + icons.questionMark.src
35+
latestResourceCommitHash: '11ca185', // for cached app.json + sites.json5 + icons.questionMark.src
3636
urls: {},
3737
chatgptJSver: /v(\d+\.\d+\.\d+)/.exec(await (await fetch(chrome.runtime.getURL('lib/chatgpt.js'))).text())[1]
3838
}

firefox/extension/lib/chatbar.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@ window.chatbar = {
2626
if (site == 'chatgpt') { // restore chatbar inner width
2727
const inputArea = chatbarDiv.querySelector(selectors.input)
2828
if (inputArea) inputArea.style.width = inputArea.parentNode.style.width = 'initial'
29-
} else if (site == 'perplexity') { // remove left-align Attach File button
30-
const attachFileBtn = chatbarDiv.querySelector(selectors.btns.attachFile)
31-
if (attachFileBtn?.getAttribute('left-aligned')) {
29+
} else if (site == 'perplexity') { // remove left-align Attach File + Search buttons
30+
const leftAlignedBtns = chatbarDiv.querySelectorAll('[left-aligned]')
31+
if (leftAlignedBtns.length) {
3232
const sendBtn = chatbarDiv.querySelector(selectors.btns.send) ; if (!sendBtn) return
33-
sendBtn.before(attachFileBtn.parentNode) ; attachFileBtn.removeAttribute('left-aligned')
34-
if (await this.is.tall()) attachFileBtn.style.marginRight = ''
33+
leftAlignedBtns.forEach(btn => {
34+
sendBtn.parentNode.before(btn.parentNode) // restore to left of Send
35+
btn.style.margin = '' ; btn.removeAttribute('left-aligned') // reset margins/attr
36+
})
37+
chatbarDiv.querySelector('button').closest('div').style.marginRight = '' // reset gap
3538
}
3639
} else if (site == 'poe') { // restore Poe Mic button position
3740
const micBtn = chatbarDiv.querySelector(selectors.btns.mic) ; if (!micBtn) return
3841
micBtn.style.marginRight = ''
3942
}
4043
},
4144

42-
async tweak() { // update ChatGPT chatbar inner width or left-align Perplexity Attach File btn or move Poe Mic btn right
45+
async tweak() { // update ChatGPT chatbar inner width or left-align Perplexity btns or move Poe Mic btn right
4346
const site = this.imports.site
4447
const chatbarDiv = await this.get() ; if (!chatbarDiv) return
4548
const selectors = this.imports.sites[site].selectors
@@ -57,15 +60,18 @@ window.chatbar = {
5760
widths.chatbar - totalBtnWidths -43 }px`
5861
inputArea.style.width = '100%' // rid h-scrollbar
5962
}
60-
} else if (site == 'perplexity') { // left-align Attach File button
61-
const attachFileBtn = chatbarDiv.querySelector(selectors.btns.attachFile) ; if (!attachFileBtn) return
62-
let newParent = chatbarDiv
63-
if (await this.is.tall()) { // select new newParent
64-
newParent = chatbarDiv.querySelector('div:has(> span > button)') // left button cluster
65-
attachFileBtn.style.marginRight = '-10px' // bring Search button closer
66-
}
67-
newParent?.children[1]?.before(attachFileBtn.parentNode)
68-
attachFileBtn.setAttribute('left-aligned', true)
63+
} else if (site == 'perplexity') { // left-align Attach File + Search buttons
64+
const rightBtns = {} ; ['attachFile', 'search'].forEach(btnType =>
65+
rightBtns[btnType] = chatbarDiv.querySelector(selectors.btns[btnType]))
66+
const modelSelectorDiv = chatbarDiv.querySelector('button').closest('div')
67+
if (!modelSelectorDiv) return // in case of breaking DOM update
68+
Object.values(rightBtns).forEach(btn => {
69+
if (!btn) return
70+
modelSelectorDiv.after(btn.parentNode) // move to right of selector
71+
btn.style.margin = '0 -5px' // close x-gap
72+
btn.setAttribute('left-aligned', true) // for this.reset()
73+
})
74+
if (chatbarDiv.querySelector('[left-aligned]')) modelSelectorDiv.style.marginRight = '3px' // close gap
6975
} else if (site == 'poe') // move Mic btn closer to Send
7076
dom.get.loadedElem(selectors.btns.mic, { timeout: 5000 })
7177
.then(btn => { if (btn) btn.style.marginRight = '-7px' })

0 commit comments

Comments
 (0)