Skip to content

Commit

Permalink
Stripped trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Nov 21, 2024
1 parent 0ca9d2c commit 556c737
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 74 deletions.
44 changes: 22 additions & 22 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const chatgpt = {
modalMessage = document.createElement('p');

// Create/append/update modal style (if missing or outdated)
const thisUpdated = 20231203; // datestamp of last edit for this file's `modalStyle`
const thisUpdated = 20231203; // datestamp of last edit for this file's `modalStyle`
let modalStyle = document.querySelector('#chatgpt-modal-style'); // try to select existing style
if (!modalStyle || parseInt(modalStyle.getAttribute('last-updated'), 10) < thisUpdated) { // if missing or outdated
if (!modalStyle) { // outright missing, create/id/attr/append it first
Expand All @@ -88,7 +88,7 @@ const chatgpt = {
'.no-mobile-tap-outline { outline: none ; -webkit-tap-highlight-color: transparent }'

// Background styles
+ '.chatgpt-modal {'
+ '.chatgpt-modal {'
+ 'position: fixed ; top: 0 ; left: 0 ; width: 100% ; height: 100% ;' // expand to full view-port
+ 'background-color: rgba(67, 70, 72, 0) ;' // init dim bg but no opacity
+ 'transition: background-color 0.05s ease ;' // speed to transition in show alert routine
Expand Down Expand Up @@ -140,7 +140,7 @@ const chatgpt = {
+ `border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' } ;`
+ 'background-color: black ; position: inherit }'
+ '.chatgpt-modal input[type="checkbox"]:focus { outline: none ; box-shadow: none }'
);
);
}

// Insert text into elements
Expand Down Expand Up @@ -210,7 +210,7 @@ const chatgpt = {
const modalElems = [closeBtn, modalTitle, modalMessage, modalButtons, checkboxDiv];
modalElems.forEach((elem) => { modal.append(elem); });
modal.style.width = `${ width || 458 }px`;
modalContainer.append(modal); document.body.append(modalContainer);
modalContainer.append(modal); document.body.append(modalContainer);

// Enqueue alert
let alertQueue = JSON.parse(localStorage.alertQueue);
Expand All @@ -222,7 +222,7 @@ const chatgpt = {
if (alertQueue.length === 1) {
modalContainer.style.display = '';
setTimeout(() => { // delay non-0 opacity's for transition fx
modalContainer.style.backgroundColor = (
modalContainer.style.backgroundColor = (
`rgba(67, 70, 72, ${ scheme === 'dark' ? 0.62 : 0.1 })`);
modalContainer.classList.add('animated'); }, 100);
}
Expand Down Expand Up @@ -557,7 +557,7 @@ const chatgpt = {
.replace('Copy code', '');
msgs.push(sender + ': ' + msg);
});
transcript = msgs.join('\n\n');
transcript = msgs.join('\n\n');

// ...or from getChatData(chatToGet)
} else {
Expand Down Expand Up @@ -623,7 +623,7 @@ const chatgpt = {
footer: {
get() { return document.querySelector('main form')?.parentNode.parentNode.nextElementSibling; },

hide() {
hide() {
const footer = chatgpt.footer.get();
if (!footer) return console.error('Footer element not found!');
if (footer.style.visibility == 'hidden') return console.info('Footer already hidden!');
Expand All @@ -634,7 +634,7 @@ const chatgpt = {
const footer = chatgpt.footer.get();
if (!footer) return console.error('Footer element not found!');
if (footer.style.visibility != 'hidden') return console.info('Footer already shown!');
footer.style.visibility = footer.style.height = 'inherit';
footer.style.visibility = footer.style.height = 'inherit';
}
},

Expand Down Expand Up @@ -893,7 +893,7 @@ const chatgpt = {
getRegenerateButton() { return document.querySelector('button:has([d^="M3.06957"])'); },

getResponse() {
// * Returns response via DOM by index arg if OpenAI chat page is active, otherwise uses API w/ following args:
// * Returns response via DOM by index arg if OpenAI chat page is active, otherwise uses API w/ following args:
// chatToGet = index|title|id of chat to get (defaults to latest if '' unpassed)
// responseToGet = index of response to get (defaults to latest if '' unpassed)
// regenResponseToGet = index of regenerated response to get (defaults to latest if '' unpassed)
Expand Down Expand Up @@ -1147,7 +1147,7 @@ const chatgpt = {
}

else if (element == 'dropdown') {
if (!attrs?.items || // there no are options to add
if (!attrs?.items || // there no are options to add
!Array.isArray(attrs.items) || // it's not an array
!attrs.items.length) // the array is empty
attrs.items = [{ text: '🤖 chatgpt.js option', value: 'chatgpt.js option value' }]; // set default dropdown entry
Expand All @@ -1168,7 +1168,7 @@ const chatgpt = {
const addElementsToMenu = () => {
const optionButtons = document.querySelectorAll('a[role="menuitem"]');
let cssClasses;

for (const navLink of optionButtons)
if (navLink.textContent == 'Settings') {
cssClasses = navLink.classList;
Expand Down Expand Up @@ -1240,7 +1240,7 @@ const chatgpt = {
+ (notificationDiv.isRight ? 'Right' : 'Left');

// Create/append/update notification style (if missing or outdated)
const thisUpdated = 20231110; // datestamp of last edit for this file's `notifStyle`
const thisUpdated = 20231110; // datestamp of last edit for this file's `notifStyle`
let notifStyle = document.querySelector('#chatgpt-notif-style'); // try to select existing style
if (!notifStyle || parseInt(notifStyle.getAttribute('last-updated'), 10) < thisUpdated) { // if missing or outdated
if (!notifStyle) { // outright missing, create/id/attr/append it first
Expand All @@ -1263,7 +1263,7 @@ const chatgpt = {
+ '45% { opacity: 0.05 ; transform: rotateX(-81deg) }'
+ '100% { opacity: 0 ; transform: rotateX(-180deg) scale(1.15) }}'
);
}
}

// Enqueue notification
let notifyProps = JSON.parse(localStorage.notifyProps);
Expand Down Expand Up @@ -1296,7 +1296,7 @@ const chatgpt = {
notificationDiv.style.transition = 'transform 0.15s ease, opacity 0.15s ease';
}, 10);

// Init delay before hiding
// Init delay before hiding
const hideDelay = fadeDuration > notifDuration ? 0 // don't delay if fade exceeds notification duration
: notifDuration - fadeDuration; // otherwise delay for difference

Expand All @@ -1305,7 +1305,7 @@ const chatgpt = {
notificationDiv.style.animation = `notif-zoom-fade-out ${ fadeDuration }s ease-out`;
clearTimeout(dismissFuncTID);
};
const dismissFuncTID = setTimeout(dismissNotif, hideDelay * 1000); // maintain visibility for `hideDelay` secs, then dismiss
const dismissFuncTID = setTimeout(dismissNotif, hideDelay * 1000); // maintain visibility for `hideDelay` secs, then dismiss
closeSVG.onclick = dismissNotif; // add to close button clicks

// Destroy notification
Expand Down Expand Up @@ -1453,7 +1453,7 @@ const chatgpt = {
continue() { try { chatgpt.getContinueBtn().click(); } catch (err) { console.error(err.message); }},

get() {
// * Returns response via DOM by index arg if OpenAI chat page is active, otherwise uses API w/ following args:
// * Returns response via DOM by index arg if OpenAI chat page is active, otherwise uses API w/ following args:
// chatToGet = index|title|id of chat to get (defaults to latest if '' unpassed)
// responseToGet = index of response to get (defaults to latest if '' unpassed)
// regenResponseToGet = index of regenerated response to get (defaults to latest if '' unpassed)
Expand Down Expand Up @@ -1682,14 +1682,14 @@ const chatgpt = {
break;
}
}

// Apply CSS to make the added elements look like they belong to the website
this.elements.forEach(element => {
element.setAttribute('class', cssClasses);
element.style.maxHeight = element.style.minHeight = '44px'; // Fix the height of the element
element.style.margin = '2px 0';
});

// Create MutationObserver instance
const navBar = document.querySelector('nav');
if (!navBar) return console.error('Sidebar element not found!');
Expand Down Expand Up @@ -1746,7 +1746,7 @@ const chatgpt = {
}

else if (element == 'dropdown') {
if (!attrs?.items || // There no are options to add
if (!attrs?.items || // There no are options to add
!Array.isArray(attrs.items) || // It's not an array
!attrs.items.length) // The array is empty
attrs.items = [{ text: '🤖 chatgpt.js option', value: 'chatgpt.js option value' }]; // Set default dropdown entry
Expand All @@ -1761,7 +1761,7 @@ const chatgpt = {
newElement.add(optionElement);
});
}


// Fix for blank background on dropdown elements
if (element == 'dropdown') newElement.style.backgroundColor = 'var(--gray-900, rgb(32, 33, 35))';
Expand Down Expand Up @@ -1862,7 +1862,7 @@ const chatgpt = {
if (!outputLang) return console.error('outputLang (2nd) argument not supplied. Pass a language!');
for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
return console.error(`Argument ${ i + 1 } must be a string!`);
chatgpt.send('Translate the following text to ' + outputLang
chatgpt.send('Translate the following text to ' + outputLang
+ '. Only reply with the translation.\n\n' + text);
console.info('Translating text...');
await chatgpt.isIdle();
Expand Down Expand Up @@ -2016,7 +2016,7 @@ for (const prop in chatgpt) {
// Prefix console logs w/ '🤖 chatgpt.js >> '
const consolePrefix = '🤖 chatgpt.js >> ', ogError = console.error, ogInfo = console.info;
console.error = (...args) => {
if (!args[0].startsWith(consolePrefix)) ogError(consolePrefix + args[0], ...args.slice(1));
if (!args[0].startsWith(consolePrefix)) ogError(consolePrefix + args[0], ...args.slice(1));
else ogError(...args);
};
console.info = (msg) => {
Expand Down
6 changes: 3 additions & 3 deletions docs/assets/js/src/back-to-top-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function fadeIn(el, duration) {
let last = +new Date();
const tick = () => {
el.style.opacity = +el.style.opacity + (new Date() - last) / duration;
last = +new Date();
if (+el.style.opacity < 1)
last = +new Date();
if (+el.style.opacity < 1)
(window.requestAnimationFrame && requestAnimationFrame(tick)) ||
setTimeout(tick, 16);
else el.style.display = 'block';
Expand Down Expand Up @@ -56,7 +56,7 @@ function scrollToTop() {
}
}
button.addEventListener('click', scrollToTop);

window.addEventListener('scroll', () => {
const scrollTop = window.scrollY || document.documentElement.scrollTop;
if (scrollTop > 0) fadeIn(button, 500);
Expand Down
36 changes: 18 additions & 18 deletions docs/assets/js/src/onload-hacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const iObserver = new IntersectionObserver(entries => { entries.forEach(entry =>
const key = entry.target.id || entry.target.className;
visibilityMap[key] = entry.isIntersecting;

// Handle COVER
// Handle COVER
if (entry.target.className === 'cover-main') {
if (entry.isIntersecting) {

Expand Down Expand Up @@ -108,7 +108,7 @@ const onLoadObserver = new MutationObserver(() => {
function updateTGvisibility() {
topGradient.style.display = ( // hide/show when fold is 85% at top
window.scrollY > 0.85 * cover.offsetHeight ? '' : 'none' ); }

mdLoaded.then(() => {

// Scroll slightly to overcome Chromium bug preventing parallax
Expand Down Expand Up @@ -155,7 +155,7 @@ const onLoadObserver = new MutationObserver(() => {
ghDemo.parentNode.replaceChild(ytDemo, ghDemo);
ytDemo.parentNode.style.textAlign = 'center';

// Strip blockquote wrappers from showcase app descriptions
// Strip blockquote wrappers from showcase app descriptions
document.querySelectorAll('blockquote').forEach(blockquote => {
const parent = blockquote.parentNode, content = blockquote.innerHTML;
parent.replaceChild(document.createRange().createContextualFragment(content), blockquote);
Expand Down Expand Up @@ -196,7 +196,7 @@ const onLoadObserver = new MutationObserver(() => {
activeNavItem = (document.querySelector(
`a[title="${ headingText }"]`) || {}).parentElement;

// Add `nav-active` class to matched nav item
// Add `nav-active` class to matched nav item
if (activeNavItem) {
sideNavItems.forEach(item => item.classList.remove('nav-active'));
activeNavItem.classList.add('nav-active');
Expand Down Expand Up @@ -233,12 +233,12 @@ const onLoadObserver = new MutationObserver(() => {

// Exit if still in 1st two sections
if (visibilityMap['cover-main'] || visibilityMap['feature-list']) return;

// Determine current section
let currentSection = 0;
while (window.scrollY > triggerPoints[currentSection] &&
while (window.scrollY > triggerPoints[currentSection] &&
currentSection < triggerPoints.length)
currentSection++;
currentSection++;

// Color/animate logo/stars + color scrollbar if section changed
const sectionColor = sectionColors[currentSection - 2];
Expand Down Expand Up @@ -349,7 +349,7 @@ const onLoadObserver = new MutationObserver(() => {
scaleDelay = 285, // px from trigger.y to delay scaling
scaleFactor = topGap > -scaleDelay ? 1
: 1 - Math.abs(topGap + scaleDelay) / 5 / window.innerHeight;

try { elem.classList.remove('content-fadeup'); } catch (err) {}
elem.style.opacity = newOpacity;
elem.style.transform = `translateY(${parallaxOffset}px) scale(${scaleFactor})`;
Expand Down Expand Up @@ -390,22 +390,22 @@ function validateIntArg(arg, name, defaultVal) {
if (arg === undefined) return defaultVal; // no validation required
if (!Number.isInteger(arg) && !/^\d+$/.test(arg))
throw new Error(name + ' must be an integer.');
return parseInt(arg, 10);
return parseInt(arg, 10);
}

function smoothScroll(target, speed, smooth) {

// Init target
if (target === document)
target = (document.scrollingElement
|| document.documentElement
|| document.body.parentNode
target = (document.scrollingElement
|| document.documentElement
|| document.body.parentNode
|| document.body); // cross browser support for document scrolling

// Init variables
let moving = false, pos = target.scrollTop;
const frame = target === document.body && document.documentElement
? document.documentElement
const frame = target === document.body && document.documentElement
? document.documentElement
: target; // safari
// Add listeners
target.addEventListener('mousewheel', scrolled, { passive: false });
Expand All @@ -429,8 +429,8 @@ function smoothScroll(target, speed, smooth) {
}

function update() {
moving = true;
const delta = (pos - target.scrollTop) / smooth;
moving = true;
const delta = (pos - target.scrollTop) / smooth;
target.scrollTop += delta;
if (Math.abs(delta) > 0.5) requestFrame(update);
else moving = false;
Expand Down Expand Up @@ -512,7 +512,7 @@ function typeText(txtToType, destination, typeDelay, iniTxtToType, iniTxtPos, li
iniTxtPos, 'Initial text string position', 3);
linesToScrollAt = validateIntArg( // lines reached before scrolling up
linesToScrollAt, 'Lines to scroll at', 5);

// Init variables
let typeContent = ' ',
iniRow = Math.max(0, iniTxtToType - linesToScrollAt);
Expand Down Expand Up @@ -588,7 +588,7 @@ langSelector.onmouseover = langSelector.onmouseout = langMenu.onmouseover = lang
clearTimeout(hideTimeout);
if (event.type == 'mouseover') langMenu.style.display = 'block';
else if (event.type == 'mouseout')
hideTimeout = setTimeout(() => langMenu.style.display = 'none', 55);
hideTimeout = setTimeout(() => langMenu.style.display = 'none', 55);
};
document.querySelectorAll('#language-selector a').forEach(link => { // add listener to hide tooltips
link.addEventListener('mouseenter', () => { link.removeAttribute('title'); });});
Expand Down
10 changes: 5 additions & 5 deletions docs/assets/js/src/starry-background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* * . * . * * .
. * Add starry background to <canvas>
/* * . * . * * .
. * Add starry background to <canvas>
* . . . * . . * */

// Init variables
Expand Down Expand Up @@ -56,10 +56,10 @@ function animateStars() {
star.x += (star.x - width/2) * window.starVelocity.z * star.z;
star.y += (star.y - height/2) * window.starVelocity.z * star.z;
star.z += window.starVelocity.z;

// Recycle star when out-of-bounds
if (star.x < -overflowThreshold || star.x > width + overflowThreshold ||
star.y < -overflowThreshold || star.y > height + overflowThreshold) {
star.y < -overflowThreshold || star.y > height + overflowThreshold) {
let direction = 'z', vx = Math.abs(window.starVelocity.x), vy = Math.abs(window.starVelocity.y);
if (vx > 1 || vy > 1) {
let axis;
Expand All @@ -76,7 +76,7 @@ function animateStars() {
else if (direction === 'b') { star.x = width * Math.random(); star.y = height + overflowThreshold; }
}
});

// Render stars
stars.forEach((star) => {
context.beginPath();
Expand Down
2 changes: 1 addition & 1 deletion starters/chrome/extension/components/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const icons = {
if (iconData.type == 'svg') {
const svg = dom.create.svgElem('svg', { viewBox: iconData.viewBox, ...iconAttrs })
iconData.elems.forEach(([tag, attrs]) => svg.append(dom.create.svgElem(tag, attrs)))
return svg
return svg
} else // img w/ src
return dom.create.elem('img', { src: iconData.src, ...iconAttrs })
},
Expand Down
2 changes: 1 addition & 1 deletion starters/chrome/extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// Define FEEDBACK functions

function notify(msg, pos = '', notifDuration = '', shadow = '') {

// Strip state word to append colored one later
const foundState = ['ON', 'OFF'].find(word => msg.includes(word))
if (foundState) msg = msg.replace(foundState, '')
Expand Down
Loading

0 comments on commit 556c737

Please sign in to comment.