Created
January 5, 2019 21:50
-
-
Save codycodes/28fb9153e6a8a5d2a171762137c13d3f to your computer and use it in GitHub Desktop.
Tampermonkey Script; Hacky. You can drag down all-day events into the calendar as normal events. Useful for me because I use Google Calendar all day events as a todo list and I like being able to just drag in the events. Updating secTimer will change how frequently the function that makes all day events draggable runs. Also respods to some key p…
This file contains 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 Make Google Calendar All-Day Events Draggable | |
// @namespace https://calendar.google.com/calendar/* | |
// @version 0.1 | |
// @description Hacky. You can drag down all-day events into the calendar as normal events. Useful for me because I use Google Calendar all day events as a todo list and I like being able to just drag in the events. Updating secTimer will change how frequently the function that makes all day events draggable runs. Also respods to some key presses. Still very much WIP | |
// @author Cody Antonio Gagnon | |
// @match https://calendar.google.com/calendar/* | |
// @grant none | |
// ==/UserScript== | |
let nodeList; | |
let i; | |
let cur; | |
let secTimer = 2; | |
let state; | |
let listenerCreated = false; | |
let previous = '6'; // begin with all day drag | |
let current = '3'; // change state to no all day drag | |
async function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
// let google calendar load... | |
sleep(secTimer * 1000); | |
function getDraggableSettings(){ | |
if (!listenerCreated) { | |
document.addEventListener("keypress", function(e) { | |
// alert(e.which); | |
if (e.which == 123) { | |
previous = '3'; | |
current = '6'; | |
console.log('all day drag enabled!'); | |
} else if (e.which == 125) { | |
previous = '6'; | |
current = '3'; | |
console.log('all day drag disabled!'); | |
} else if (e.which == 91) { | |
document.querySelector('.gb_sc').click(); | |
} else if (e.which == 93) { | |
document.querySelector('.gcENoe').click(); | |
} | |
}); | |
listenerCreated = true; | |
} | |
return [previous, current]; | |
} | |
(function(previous, current) { | |
state = getDraggableSettings(); | |
let nodeList = document.querySelectorAll('.eADW5d'); | |
i = 0; | |
cur = nodeList[0]; | |
'use strict'; | |
try { | |
while (cur) { | |
// check if there are any all-day events first | |
if (cur.childNodes[0].innerText.charAt(0) != '0') { | |
let j = 0; | |
let event = cur.childNodes[1].children; | |
while (event[j]) { | |
// check for the event type that we want to be able to drag | |
if (event[j].getAttribute("data-dragsource-type") == state[0]) { | |
event[j].setAttribute("data-dragsource-type", state[1]); | |
console.log('changed!' + state[0] + " to " + state[1]); | |
} | |
j++; | |
} | |
} | |
i++; | |
cur = nodeList[i]; | |
} | |
} catch (e) {} | |
// recursively call this anonymous function again | |
setTimeout(arguments.callee, secTimer * 1000, previous, current); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment