Skip to content

Instantly share code, notes, and snippets.

View taylormitchell's full-sized avatar

Taylor Mitchell taylormitchell

View GitHub Profile
@taylormitchell
taylormitchell / notifyMe
Last active September 16, 2022 19:55
Helper to create to create a notification and cancel the last one if it exists
window.extensions = {
...(window.extensions || {}),
notifyMe: {
create: function (message, timeString) {
const [hours, minutes] = timeString.split(":");
const now = new Date();
const time = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
if (now > time) {
throw new Error("Time must be in the future");
}
function helloWorld() {
console.log("hello world!");
}
@taylormitchell
taylormitchell / dates.js
Last active May 24, 2022 15:51
Javascript date helpers
// Move day of week starting index from Sunday to Monday
let f = idx => (idx + 6)%7
for(const [i, dow] of Object.entries(["S", "M", "T", "W", "Th", "F", "S"])) {
console.log(`${dow} ${i} → ${f(parseInt(i))}`)
}
// Get month
function getMonthString(d = new Date()) {
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
function createWorkSessionReminder() {
let Reminders = Application('Reminders');
let app = Application.currentApplication()
app.includeStandardAdditions = true
let now = new Date()
// Set start time to now
let startTime = `${now.getHours()}:${now.getMinutes()}`
@taylormitchell
taylormitchell / roamDate.js
Last active August 31, 2021 19:52
Javascript function to create a date string in Roam format
/**
* Returns the corresponding date suffix
* @param {number} d Day of the month
* @returns Date suffix
*/
function getDateSuffix(d) {
lastDigit = d % 10
if (d >= 11 && d <= 13) {
return "th"
} else if (lastDigit === 1) {
@taylormitchell
taylormitchell / clozify.js
Last active October 5, 2020 13:07
Roam script which wraps selected text in cloze brackets
function clozifySelectedText() {
var txtArea = document.activeElement;
if (txtArea.selectionStart != undefined) {
var startPos = txtArea.selectionStart;
var endPos = txtArea.selectionEnd;
selectedText = txtArea.value.substring(startPos, endPos);
clozifiedText = txtArea.value.slice(0, startPos) + '[[{]]' + selectedText + '[[}]]' + txtArea.value.slice(endPos);
var valueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
valueSetter.call(txtArea, clozifiedText);
@taylormitchell
taylormitchell / wiki2roam.js
Created August 20, 2020 13:07
Copy selection from a wikipedia page and convert the hyperlinks to Roam aliases
var url = document.URL;
var title = url.split("/").pop().replace(/#.*/,"").replace("_"," ");
var range = window.getSelection().getRangeAt(0);
var selectionContents = range.cloneContents();
var selectionNodes = selectionContents.childNodes;
// Convert hyperlinks to Roam references
var selection = "";
selectionNodes.forEach((node) => {
if (node.nodeName=="B") {
@taylormitchell
taylormitchell / my_roam.css
Last active June 2, 2020 13:04
My Roam CSS
/* Hide query title and page titles in query*/
.rm-query-title, .rm-title-arrow-wrapper{
display:none!important;
}
/* Hide page mentions in an article (can still get in sidebar) */
.roam-article .rm-reference-main{
display:none;
}