Skip to content

Commit

Permalink
Added chatgpt.sidebar.isLoaded()
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed May 17, 2024
1 parent a54bd4a commit 5cd54ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,15 @@ const chatgpt = { // eslint-disable-line no-redeclare
.some(child => child.style.transform.includes('translateY'));
for (const btn of document.querySelectorAll(navBtnSelector))
if (isToggleBtn(btn)) { btn.click(); return; }
}
},

isloaded: function() {
return new Promise(resolve => {
(function checkIsLoaded() {
if (document.querySelector('nav a[href="/"]')) resolve(true);
else setTimeout(checkIsLoaded, 100);
})();
});}
},

startNewChat: function() { try { this.getNewChatButton().click(); } catch (err) { console.error(err.message); }},
Expand Down
14 changes: 14 additions & 0 deletions docs/USERGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
- [hide](#hide)
- [show](#show)
- [toggle](#toggle-2)
- [isloaded](#isloaded-async-2)

# Importing the library

Expand Down Expand Up @@ -1838,6 +1839,19 @@ Example code:
chatgpt.sidebar.toggle();
```

### isLoaded `async`

Resolves a promise when the ChatGPT sidebar has finished loading.

Example code:

```js
(async () => {
await chatgpt.sidebar.isLoaded();
console.log('ChatGPT sidebar has finished loading.');
})();
```

<br>
<br>

Expand Down

0 comments on commit 5cd54ee

Please sign in to comment.