Skip to content

Instantly share code, notes, and snippets.

@Kenny2github
Last active March 5, 2024 06:46
Show Gist options
  • Save Kenny2github/c614b71dd67a5e80abcadfab3e54b4f0 to your computer and use it in GitHub Desktop.
Save Kenny2github/c614b71dd67a5e80abcadfab3e54b4f0 to your computer and use it in GitHub Desktop.
Copy your when2meet responses from one when2meet to another.
// ==UserScript==
// @name When2meet Copy-Paste
// @match https://www.when2meet.com/?*
// @version 2024-03-06
// @description Copy your when2meet responses from one when2meet to the other.
// @author AbyxDev
// @icon https://www.google.com/s2/favicons?sz=64&domain=when2meet.com
// @grant none
// @updateURL https://gist.github.com/Kenny2github/c614b71dd67a5e80abcadfab3e54b4f0/raw/when2meet-copier.user.js
// @downloadURL https://gist.github.com/Kenny2github/c614b71dd67a5e80abcadfab3e54b4f0/raw/when2meet-copier.user.js
// ==/UserScript==
/**
* Usage:
* 1. Open the source when2meet, SIGN IN, and click "Copy".
* 2. Your responses will be put in your clipboard.
* 3. Open the destination when2meet, SIGN IN, and click "Paste".
* 4. Your responses will OVERWRITE the destination when2meet.
*/
// declare const TimeOfSlot: number[]
// declare const AvailableAtSlot: number[][]
// declare const UserID: number
// declare const SelectFromHere: (x: {target: HTMLElement | null}) => void
// declare const SelectToHere: (x: {target: HTMLElement | null}) => void
// declare const SelectStop: () => void
(() => {
if (!navigator.clipboard) return;
async function doCopy() {
const times = [];
for (let slot = 0; slot < TimeOfSlot.length; ++slot) {
if (AvailableAtSlot[slot].includes(UserID)) times.push(TimeOfSlot[slot]);
}
await navigator.clipboard.writeText('' + times);
alert(`Copied ${times.length} available timeslots`);
}
async function doPaste() {
const timesText = await navigator.clipboard.readText();
if (!timesText.match(/^\d+(?:,\d+)*$/)) {
alert('No timeslots in clipboard');
return;
}
const times = new Set(timesText.split(',').map(x => +x));
let elem = null;
let filled = false;
for (let slot = 0; slot < TimeOfSlot.length; ++slot) {
const us = times.has(TimeOfSlot[slot]);
const them = AvailableAtSlot[slot].includes(UserID);
const slotElem = document.getElementById('YouTime' + TimeOfSlot[slot]);
let updated = false;
if (us === them && elem !== null) {
// already desired state and dragging something
if (filled === us) {
// already dragging desired state, continue
elem = slotElem;
} else {
// currently dragging undesired state, stop
SelectToHere({target: elem});
SelectStop();
elem = null;
updated = true;
}
} else if (elem !== null) {
// state needs changing and dragging something
if (filled === us) {
// already dragging desired state, continue
elem = slotElem;
} else {
// currently dragging undesired state, switch
SelectToHere({target: elem});
SelectStop();
elem = slotElem;
filled = us;
SelectFromHere({target: elem});
updated = true;
}
} else if (us !== them) {
// state needs changing and not dragging, start
elem = slotElem;
filled = us;
SelectFromHere({target: elem});
updated = true;
} // else, already desired state and not dragging
if (slotElem.parentElement.matches(':last-child') && !updated) {
// end of column, must stop
SelectToHere({target: slotElem});
SelectStop();
elem = null;
}
}
if (elem !== null) {
SelectToHere({target: elem});
SelectStop();
elem = null;
}
}
const copy = document.createElement('button');
copy.innerText = 'Copy';
copy.addEventListener('click', doCopy);
const paste = document.createElement('button');
paste.innerText = 'Paste';
paste.addEventListener('click', doPaste);
document.getElementById('UserName').parentElement.appendChild(copy);
document.getElementById('UserName').parentElement.appendChild(paste);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment