Skip to content

Instantly share code, notes, and snippets.

@brett-schneider
Created March 16, 2022 17:36
Show Gist options
  • Save brett-schneider/453dc886869184e382bd9158583b9587 to your computer and use it in GitHub Desktop.
Save brett-schneider/453dc886869184e382bd9158583b9587 to your computer and use it in GitHub Desktop.
tampermonkey user script that saves and autofills DOB and USC details in dr plano booking
// ==UserScript==
// @name Dr Plano DOB USC
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Autofill DOB and USC in Dr Plano Booking
// @author https://github.com/brett-schneider
// @include /^https?://.*drpCourseId=\d*
// @match *?drpCourseId=*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
(function() {
'use strict';
const targetNode = document.getElementsByTagName('body')[0];
const observer = new MutationObserver(callback);
const config = { attributes: false, childList: true, subtree: true };
// const config = { attributes: true, childList: true, subtree: true };
observer.observe(targetNode, config);
})();
function cc(a) {
// console.log(a);
}
function updateData(e) {
cc("fired: updateData");
let dob = GM_getValue(e.target.value);
let usc = GM_getValue("usc_"+e.target.value);
cc("values: "+dob+" / "+usc);
if (dob && document.getElementsByName("date-of-birth")[0]) document.getElementsByName("date-of-birth")[0].setAttribute("value",dob);
if (usc && document.getElementsByName("participant-tariff-id")[0] && document.getElementsByName("participant-additional-field-value")[0]) {
document.getElementsByName("participant-tariff-id")[0].setAttribute("value","155589630");
document.getElementsByName("participant-additional-field-value")[0].setAttribute("value",usc);
}
};
function saveData(e) {
if (document.getElementsByName("email")[0]) {
cc("saving for: "+document.getElementsByName("email")[0].value);
if (document.getElementsByName("date-of-birth")[0]) {
GM_setValue(document.getElementsByName("email")[0].value, document.getElementsByName("date-of-birth")[0].value);
cc("dob: "+document.getElementsByName("date-of-birth")[0].value);
}
if (document.getElementsByName("participant-additional-field-value")[0]) {
GM_setValue("usc_"+document.getElementsByName("email")[0].value, document.getElementsByName("participant-additional-field-value")[0].value);
cc("usc: "+document.getElementsByName("participant-additional-field-value")[0].value);
}
}
};
function findLMNTs(ruth) {
cc("finding elements in: "+ruth+" ("+(typeof ruth)+")");
cc("querySelector: "+(typeof ruth.querySelector));
if (typeof ruth.querySelector !== 'undefined') {
let email = ruth.querySelector('input[name="email"]');
let form = ruth.querySelector('form');
if (email) {
email.addEventListener('input', updateData);
cc("mail found");
}
if (form) {
form.addEventListener('submit', saveData);
cc("form found");
}
}
}
function callback(mutationList, observer) {
mutationList.forEach( (mutation) => {
switch(mutation.type) {
case 'childList':
cc("nodes added");
cc(mutation.addedNodes);
mutation.addedNodes.forEach(x => cc(x));
mutation.addedNodes.forEach(x => findLMNTs(x));
break;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment