Skip to content

Commit

Permalink
Replaced all top-level this refs w/ chatgpt for consistent method…
Browse files Browse the repository at this point in the history
… invocation context + readability ↞ [auto-sync from `KudoAI/chatgpt.js`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed May 17, 2024
1 parent b4405ac commit e110b11
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions starters/chrome/extension/lib/chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const chatgpt = { // eslint-disable-line no-redeclare

// Insert text into elements
modalTitle.innerText = title || '';
modalMessage.innerText = msg || ''; this.renderHTML(modalMessage);
modalMessage.innerText = msg || ''; chatgpt.renderHTML(modalMessage);

// Create/append buttons (if provided) to buttons div
const modalButtons = document.createElement('div');
Expand Down Expand Up @@ -400,7 +400,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
} catch (err) {
console.error(err.message);
if (arguments.length == 0) {
console.info('Using backend API method instead.'); this.clearChats('api'); }
console.info('Using backend API method instead.'); chatgpt.clearChats('api'); }
}

} else { // API method
Expand Down Expand Up @@ -497,7 +497,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
}
},

continue: function() { this.response.continue(); },
continue: function() { chatgpt.response.continue(); },

detectLanguage: async function(text) {
if (!text) return console.error('Text argument not supplied. Pass some text!');
Expand Down Expand Up @@ -1367,9 +1367,9 @@ const chatgpt = { // eslint-disable-line no-redeclare
nodeContent = node.childNodes;

// Preserve consecutive spaces + line breaks
if (!this.renderHTML.preWrapSet) {
node.style.whiteSpace = 'pre-wrap'; this.renderHTML.preWrapSet = true;
setTimeout(() => { this.renderHTML.preWrapSet = false; }, 100);
if (!chatgpt.renderHTML.preWrapSet) {
node.style.whiteSpace = 'pre-wrap'; chatgpt.renderHTML.preWrapSet = true;
setTimeout(() => { chatgpt.renderHTML.preWrapSet = false; }, 100);
}

// Process child nodes
Expand All @@ -1393,7 +1393,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
tagNode.setAttribute(name, value);
});

const renderedNode = this.renderHTML(tagNode); // render child elements of newly created node
const renderedNode = chatgpt.renderHTML(tagNode); // render child elements of newly created node

// Insert newly rendered node
const beforeTextNode = document.createTextNode(text.substring(0, elem.index)),
Expand All @@ -1406,7 +1406,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
}

// Process element nodes recursively
} else if (childNode.nodeType == Node.ELEMENT_NODE) this.renderHTML(childNode);
} else if (childNode.nodeType == Node.ELEMENT_NODE) chatgpt.renderHTML(childNode);
}

return node; // if assignment used
Expand Down Expand Up @@ -1485,7 +1485,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
return console.error(`Argument ${ i + 1 } must be a string!`);
const textArea = document.querySelector('form textarea'),
sendBtn = this.getSendButton();
sendBtn = chatgpt.getSendButton();
textArea.value = msg;
textArea.dispatchEvent(new Event('input', { bubbles: true })); // enable send button

Expand Down Expand Up @@ -1770,8 +1770,8 @@ const chatgpt = { // eslint-disable-line no-redeclare
});}
},

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

suggest: async function(ideaType, details) {
if (!ideaType) return console.error('ideaType (1st argument) not supplied'
Expand Down

0 comments on commit e110b11

Please sign in to comment.