Created
July 14, 2023 16:19
-
-
Save 01010111/f8b32308c80af308990b75987eeabd63 to your computer and use it in GitHub Desktop.
Itch.io Jam Page - Add to Google Calendar Userscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Itch Jam Page - Add to Google Calendar | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Scrapes date data from jam site and adds a google calendar link | |
// @author 01010111 | |
// @match https://itch.io/jam/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=itch.io | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const jam_url = window.location.href; | |
const jam_title = document.querySelector('.jam_title_header').innerText; | |
const date_data = document.querySelector('.date_data'); | |
if (!jam_title || !date_data) return; | |
const date_format_divs = date_data.querySelectorAll('.date_format'); | |
const from = new Date(date_format_divs[0].getAttribute('title')); | |
const to = new Date(date_format_divs[1].getAttribute('title')); | |
function remove_punctuation(input) { | |
for (let char of '.-:'.split('')) input = input.replaceAll(char, ''); | |
return input; | |
} | |
let base_url = 'https://calendar.google.com/calendar/r/eventedit?action=TEMPLATE'; | |
let text = `text=${encodeURIComponent(jam_title.trim())}`; | |
let dates = `dates=${remove_punctuation(from.toISOString())}/${remove_punctuation(to.toISOString())}`; | |
let sprop = `sprop=${encodeURIComponent(jam_url)}`; | |
let calendar_url = `${base_url}&${text}&${dates}&${sprop}`; | |
if (!text || !dates || !sprop) return; | |
date_data.onclick = () => window.open(calendar_url,'_blank'); | |
date_data.style.cursor = 'pointer'; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment