Skip to content

Instantly share code, notes, and snippets.

View charisTheo's full-sized avatar
⚛️
Reacting

Harry Theo charisTheo

⚛️
Reacting
View GitHub Profile
@charisTheo
charisTheo / prerender-skyscanner.js
Created April 23, 2024 10:35
npm init -y && npm i puppeteer && node prerender-skyscanner.js
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
headless: false,
args: [
'--window-size=1818,1328',
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
@charisTheo
charisTheo / index.js
Last active February 15, 2024 15:53
npm init -y && npm i puppeteer && node index.js
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({
headless: false,
args: [
'--window-size=1818,1328',
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
@charisTheo
charisTheo / plp-pdp-view-transition-mpa.js
Created February 16, 2023 12:36
Example code for implementing View Transitions on MPAs for navigations between PLP and PDP pages.
const PRODUCT_ANCHOR_ELEMENT_SELECTOR = '[data-component="ProductCardLink"]';
// get all <a> elemenets in a list of product links
const links = Array.from(document.querySelectorAll(PRODUCT_ANCHOR_ELEMENT_SELECTOR));
links.map(link => {
link.addEventListener('click', async (e) => {
e.preventDefault();
const image = link.querySelector('img');
// View Transition necessary styles
@charisTheo
charisTheo / supergroup_to_group_channel.js
Created December 1, 2021 12:33
This script migrates all messages and users from a Sendbird supergroup channel to a group channel
/*
* This script migrates all messages and users
* from a Sendbird supergroup channel to a group channel
* by creating a new group channel and deleting the old supergroup channel.
*
* Note: make sure you have chat history enabled for newly joined members
* Enable it by selecting an App from the Dashboard and toggle the checkbox under
* Settings > Chat > Group Channels > Chat history
*
* To use this script, you need to change APP_ID and API_TOKEN below
export default [
'www/index.html',
'www/main.css',
'www/main.js',
'www/icons/ic-add-room.svg',
'www/icons/ic-arrow-down-right-24.svg',
'www/icons/ic-arrow-left.svg',
'www/icons/ic-call-filled-active.svg',
'www/icons/ic-call-filled-deactive.svg',
'www/icons/ic-call-filled-purple.svg',
async function copyImageToClipboard(img) {
const src = img.src
const imageMimeType = getImageMimeTypeFromUrl(src)
const blob = imageMimeType === 'image/svg'
? await getTextBlobFromUrl(src)
: await getImageBlobFromUrl(src)
await navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob
if (isSafari()) {
const imageMimeType = getImageMimeTypeFromUrl(src)
await navigator.clipboard.write([
new ClipboardItem({
[imageMimeType]: getImageBlobFromUrl(src)
})
])
}
function getImageMimeTypeFromUrl(url) {
return `image/${url.match(/([a-z]+)$/)[0]}`
}
document.querySelector('.copy-button').addEventListener('click', async () => {
const src = document.querySelector('.image-to-copy').src
try {
const blob = await getImageBlobFromUrl(src)
await navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob
})
])
alert('Image copied to clipboard!')
async function getImageBlobFromUrl(url) {
const fetchedImageData = await fetch(url)
const blob = await fetchedImageData.blob()
return blob
}