Skip to content

Instantly share code, notes, and snippets.

@mpfaff
Last active September 8, 2023 17:13
Show Gist options
  • Save mpfaff/78ca5212f67fa2f13b18676316c09b0a to your computer and use it in GitHub Desktop.
Save mpfaff/78ca5212f67fa2f13b18676316c09b0a to your computer and use it in GitHub Desktop.
Speedrun your "Worker Health and Safety Awareness in 4 Steps"
function getCertificate(firstName, lastName, course, forceDownload, language, email) {
function base64Encode(data) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
ac = 0,
enc = "",
tmp_arr = [];
if (!data) {
return data;
}
do { // pack three octets into four hexets
o1 = data.charCodeAt(i++);
o2 = data.charCodeAt(i++);
o3 = data.charCodeAt(i++);
bits = o1 << 16 | o2 << 8 | o3;
h1 = bits >> 18 & 0x3f;
h2 = bits >> 12 & 0x3f;
h3 = bits >> 6 & 0x3f;
h4 = bits & 0x3f;
// use hexets to index into b64, and append result to encoded string
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
} while (i < data.length);
enc = tmp_arr.join('');
var r = data.length % 3;
return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
}
/* Change the buttonURL to your own URL */
var buttonURL = 'https://www.labour.gov.on.ca/scripts/mpdf/certificatev2021.php?id=';
/*Use JSON string to pass in variables to the id URL Parameter*/
var strJSON = JSON.stringify({
"firstName": firstName,
"lastName": lastName,
"course": course,
"forcedownload": forceDownload,
"language": language,
"usermail": email,
});
/*Base 64 Encode JSON*/
buttonURL = buttonURL + base64Encode(strJSON);
/*Open the URL with the specified target*/
return buttonURL;
}
const COURSE_NAME = "Worker Health and Safety Awareness in 4 Steps";
console.log(getCertificate(process.argv[2], process.argv[3], process.argv[4] ?? COURSE_NAME, 1, "en", ""));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment