Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui authored May 16, 2024
2 parents 40d1f5c + 3744b30 commit 47caf31
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 54 deletions.
49 changes: 23 additions & 26 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,13 @@ const chatgpt = { // eslint-disable-line no-redeclare
getLastPrompt: function() { return chatgpt.getChatData('active', 'msg', 'user', 'latest'); },
getLastResponse: function() { return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'); },

getNewChatLink: function() {
for (const navLink of document.querySelectorAll('nav a')) {
if (/(new|clear) chat/i.test(navLink.text)) {
return navLink;
}}},
getNewChatButton: function() {
for (const navBtnSVG of document.querySelectorAll('nav button svg'))
if (navBtnSVG.querySelector('path[d*="M15.673 3.913a3.121"]')) // new chat icon found
return navBtnSVG.parentNode;
},

getNewChatLink: function() { return document.querySelector('nav a[href="/"]'); },

getRegenerateButton: function() {
for (const mainSVG of document.querySelectorAll('main svg')) {
Expand Down Expand Up @@ -907,11 +909,10 @@ const chatgpt = { // eslint-disable-line no-redeclare
history: {
isLoaded: function() {
return new Promise(resolve => {
const checkChatHistory = () => {
(function checkChatHistory() {
if (document.querySelector('nav')) resolve(true);
else setTimeout(checkChatHistory, 100);
};
checkChatHistory();
})();
});}
},

Expand Down Expand Up @@ -1054,10 +1055,11 @@ const chatgpt = { // eslint-disable-line no-redeclare

isLoaded: function() {
return new Promise(resolve => {
const intervalId = setInterval(() => {
if (document.querySelector('nav button[id*="menu"]')) {
clearInterval(intervalId); setTimeout(() => { resolve(true); }, 500);
}}, 100);});},
(function checkIsLoaded() {
if (chatgpt.getNewChatButton()) resolve(true);
else setTimeout(checkIsLoaded, 100);
})();
});},

isLightMode: function() { return document.documentElement.classList.toString().includes('light'); },
isMobileDevice: function() { return chatgpt.browser.isMobile(); },
Expand Down Expand Up @@ -1639,10 +1641,6 @@ const chatgpt = { // eslint-disable-line no-redeclare
elements: [], observer: {},

activateObserver: function() {
const chatHistoryNav = document.querySelector('nav'),
firstButton = chatHistoryNav.querySelector('a');
if (chatgpt.history.isOff()) // Hide enable history spam div
try { firstButton.parentNode.nextElementSibling.style.display = 'none'; } catch (err) {}

// Stop the previous observer to preserve resources
if (this.observer instanceof MutationObserver)
Expand Down Expand Up @@ -1753,28 +1751,26 @@ const chatgpt = { // eslint-disable-line no-redeclare
show: function() { this.isOff() ? this.toggle() : console.info('Sidebar already shown!'); },
isOff: function() { return !this.isOn(); },
isOn: function() {
const sidebar = document.querySelector('#__next > div > div');
return chatgpt.browser.isMobile() ?
document.documentElement.style.overflow == 'hidden'
: document.querySelector('#__next > div > div').style.visibility != 'hidden';
: sidebar.style.visibility != 'hidden' && sidebar.style.width != '0px';
},

toggle: function() {
const isMobileDevice = chatgpt.browser.isMobile(),
navBtnSelector = isMobileDevice ? '#__next button' : 'main button' ,
isGPT4oUI = !!document.documentElement.className.includes(' '),
navBtnSelector = isMobileDevice ? '#__next button' : isGPT4oUI ? 'nav button' : 'main button',
isToggleBtn = isMobileDevice ? () => true // since 1st one is toggle
: btn => Array.from(btn.querySelectorAll('*'))
.some(child => child.style.transform.includes('translateY'));
: isGPT4oUI ? btn => btn.querySelectorAll('svg path[d*="M8.857 3h6.286c1.084"]').length > 0
: /* post-GPT-4o desktop */ btn => [...btn.querySelectorAll('*')]
.some(child => child.style.transform.includes('translateY'));
for (const btn of document.querySelectorAll(navBtnSelector))
if (isToggleBtn(btn)) { btn.click(); return; }
}
},

startNewChat: function() {
for (const navLink of document.querySelectorAll('nav a')) {
if (/(new|clear) chat/i.test(navLink.text)) {
navLink.click(); return;
}}},

startNewChat: function() { try { this.getNewChatButton().click(); } catch (err) { console.error(err.message); }},
stop: function() { this.response.stopGenerating(); },

suggest: async function(ideaType, details) {
Expand Down Expand Up @@ -1902,6 +1898,7 @@ const funcAliases = [
['send', 'sendChat', 'sendMsg'],
['sendInNewChat', 'sendNewChat'],
['sentiment', 'analyzeSentiment', 'sentimentAnalysis'],
['startNewChat', 'new', 'newChat'],
['stop', 'stopGenerating'],
['suggest', 'suggestion', 'recommend'],
['toggleAutoRefresh', 'toggleAutoRefresher', 'toggleRefresher', 'toggleSessionRefresher'],
Expand Down
49 changes: 23 additions & 26 deletions starters/chrome/extension/lib/chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,13 @@ const chatgpt = { // eslint-disable-line no-redeclare
getLastPrompt: function() { return chatgpt.getChatData('active', 'msg', 'user', 'latest'); },
getLastResponse: function() { return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'); },

getNewChatLink: function() {
for (const navLink of document.querySelectorAll('nav a')) {
if (/(new|clear) chat/i.test(navLink.text)) {
return navLink;
}}},
getNewChatButton: function() {
for (const navBtnSVG of document.querySelectorAll('nav button svg'))
if (navBtnSVG.querySelector('path[d*="M15.673 3.913a3.121"]')) // new chat icon found
return navBtnSVG.parentNode;
},

getNewChatLink: function() { return document.querySelector('nav a[href="/"]'); },

getRegenerateButton: function() {
for (const mainSVG of document.querySelectorAll('main svg')) {
Expand Down Expand Up @@ -903,11 +905,10 @@ const chatgpt = { // eslint-disable-line no-redeclare
history: {
isLoaded: function() {
return new Promise(resolve => {
const checkChatHistory = () => {
(function checkChatHistory() {
if (document.querySelector('nav')) resolve(true);
else setTimeout(checkChatHistory, 100);
};
checkChatHistory();
})();
});}
},

Expand Down Expand Up @@ -1050,10 +1051,11 @@ const chatgpt = { // eslint-disable-line no-redeclare

isLoaded: function() {
return new Promise(resolve => {
const intervalId = setInterval(() => {
if (document.querySelector('nav button[id*="menu"]')) {
clearInterval(intervalId); setTimeout(() => { resolve(true); }, 500);
}}, 100);});},
(function checkIsLoaded() {
if (chatgpt.getNewChatButton()) resolve(true);
else setTimeout(checkIsLoaded, 100);
})();
});},

isLightMode: function() { return document.documentElement.classList.toString().includes('light'); },
isMobileDevice: function() { return chatgpt.browser.isMobile(); },
Expand Down Expand Up @@ -1635,10 +1637,6 @@ const chatgpt = { // eslint-disable-line no-redeclare
elements: [], observer: {},

activateObserver: function() {
const chatHistoryNav = document.querySelector('nav'),
firstButton = chatHistoryNav.querySelector('a');
if (chatgpt.history.isOff()) // Hide enable history spam div
try { firstButton.parentNode.nextElementSibling.style.display = 'none'; } catch (err) {}

// Stop the previous observer to preserve resources
if (this.observer instanceof MutationObserver)
Expand Down Expand Up @@ -1749,28 +1747,26 @@ const chatgpt = { // eslint-disable-line no-redeclare
show: function() { this.isOff() ? this.toggle() : console.info('Sidebar already shown!'); },
isOff: function() { return !this.isOn(); },
isOn: function() {
const sidebar = document.querySelector('#__next > div > div');
return chatgpt.browser.isMobile() ?
document.documentElement.style.overflow == 'hidden'
: document.querySelector('#__next > div > div').style.visibility != 'hidden';
: sidebar.style.visibility != 'hidden' && sidebar.style.width != '0px';
},

toggle: function() {
const isMobileDevice = chatgpt.browser.isMobile(),
navBtnSelector = isMobileDevice ? '#__next button' : 'main button' ,
isGPT4oUI = !!document.documentElement.className.includes(' '),
navBtnSelector = isMobileDevice ? '#__next button' : isGPT4oUI ? 'nav button' : 'main button',
isToggleBtn = isMobileDevice ? () => true // since 1st one is toggle
: btn => Array.from(btn.querySelectorAll('*'))
.some(child => child.style.transform.includes('translateY'));
: isGPT4oUI ? btn => btn.querySelectorAll('svg path[d*="M8.857 3h6.286c1.084"]').length > 0
: /* post-GPT-4o desktop */ btn => [...btn.querySelectorAll('*')]
.some(child => child.style.transform.includes('translateY'));
for (const btn of document.querySelectorAll(navBtnSelector))
if (isToggleBtn(btn)) { btn.click(); return; }
}
},

startNewChat: function() {
for (const navLink of document.querySelectorAll('nav a')) {
if (/(new|clear) chat/i.test(navLink.text)) {
navLink.click(); return;
}}},

startNewChat: function() { try { this.getNewChatButton().click(); } catch (err) { console.error(err.message); }},
stop: function() { this.response.stopGenerating(); },

suggest: async function(ideaType, details) {
Expand Down Expand Up @@ -1898,6 +1894,7 @@ const funcAliases = [
['send', 'sendChat', 'sendMsg'],
['sendInNewChat', 'sendNewChat'],
['sentiment', 'analyzeSentiment', 'sentimentAnalysis'],
['startNewChat', 'new', 'newChat'],
['stop', 'stopGenerating'],
['suggest', 'suggestion', 'recommend'],
['toggleAutoRefresh', 'toggleAutoRefresher', 'toggleRefresher', 'toggleSessionRefresher'],
Expand Down
4 changes: 2 additions & 2 deletions starters/chrome/extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,

Check warning on line 2 in starters/chrome/extension/manifest.json

View workflow job for this annotation

GitHub Actions / eslint

"manifest_version" must be equal to 2
"name": "ChatGPT Extension",
"description": "A Chrome template to start using chatgpt.js like a boss!",
"version": "2024.5.15",
"version": "2024.5.16",
"author": "chatgpt.js",
"icons": {

Check warning on line 7 in starters/chrome/extension/manifest.json

View workflow job for this annotation

GitHub Actions / eslint

"icons" must be array
"16": "icons/icon16.png",
Expand All @@ -17,7 +17,7 @@
"resources": ["lib/settings-utils.js", "lib/chatgpt.js"]
}],
"content_scripts": [{
"matches": ["https://chat.openai.com/*"],
"matches": ["https://chatgpt.com/*", "https://chat.openai.com/*"],
"js": ["content.js"]
}],
"background": { "service_worker": "background.js" }
Expand Down

0 comments on commit 47caf31

Please sign in to comment.