Last active
May 4, 2025 14:36
-
-
Save lomnom/a0c51d25a65198eba13333d6395e9bb1 to your computer and use it in GitHub Desktop.
Tapermonkey script that adds the download button to lectures on NYJCPortal/NYPortal
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 NYJC download | |
// @namespace https://tampermonkey.net/ | |
// @version 2025-03-02 | |
// @description Adds the download button to lectures on the NYJCportal. https://gist.github.com/lomnom/a0c51d25a65198eba13333d6395e9bb1 | |
// @author lomnom on github | |
// @match portal.nyjc.edu.sg/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
// Template to put id into to make download button. | |
// In form before + id + after = button HTML | |
// Copied from source of the other buttons | |
const buttonTemplate = { | |
before: '<a class="btn btn-xs btn-success" href="javascript:void(0)" onclick="$Page.variables().download(\'', | |
after: '\')"><i class="fa fa-download"></i> Download</a> ' | |
} | |
/* | |
The .download() call makes the same API request as the .video_view call, which supposedly | |
registers who has watched the lecture. | |
*/ | |
// Padding | |
const padding = "<a style='visibility: hidden'>I</a>"; | |
function main(){ | |
const buttons = document.querySelectorAll("a.btn"); | |
for (var index = 0; index<buttons.length; index++){ | |
var button = buttons[index]; | |
// Ensure button is a "Watch online button." | |
if (!button.innerHTML.endsWith("Watch Online")){ | |
continue; | |
} | |
// Ensure button has not already been processed | |
if (button.classList.contains("download-added")){ | |
continue; | |
} | |
// Flag the button as processed | |
button.classList.add("download-added"); | |
var id = button.onclick.toString().split("'")[1]; // The id of the video | |
var addedButton = padding + buttonTemplate.before + id + buttonTemplate.after; | |
// console.log(addedButton); | |
console.log("Download button added for " + id) | |
button.insertAdjacentHTML('afterend', addedButton); | |
} | |
} | |
const pollTime = 750; // How often a check is done for new buttons | |
setInterval(main, pollTime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment