Skip to content

Commit

Permalink
Improved sidebar toggle/visibility methods w/ early return if not fou…
Browse files Browse the repository at this point in the history
…nd + logging ↞ [auto-sync from `KudoAI/chatgpt.js`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed Sep 12, 2024
1 parent 5f0075d commit 8a3b3fa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions starters/chrome/extension/lib/chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1765,9 +1765,10 @@ const chatgpt = { // eslint-disable-line no-redeclare
show() { this.isOff() ? this.toggle() : console.info('Sidebar already shown!'); },
isOff() { return !this.isOn(); },
isOn() {
const sidebar = document.querySelector('body script + div > div');
if (!sidebar) return console.error('Sidebar element not found!');
return chatgpt.browser.isMobile() ?
const sidebar = (() => {
return chatgpt.sidebar.exists() ? document.querySelector('body script + div > div') : null; })();
if (!sidebar) { console.error('Sidebar element not found!'); return false; }
else return chatgpt.browser.isMobile() ?
document.documentElement.style.overflow == 'hidden'
: sidebar.style.visibility != 'hidden' && sidebar.style.width != '0px';
},
Expand All @@ -1779,6 +1780,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
: btn => btn.querySelector('svg path[d^="M8.857"]');
for (const btn of document.querySelectorAll(navBtnSelector))
if (isToggleBtn(btn)) { btn.click(); return; }
console.error('Sidebar toggle not found!');
},

async isLoaded() {
Expand Down

0 comments on commit 8a3b3fa

Please sign in to comment.