Skip to content

Instantly share code, notes, and snippets.

@li-yiyang
Created January 11, 2023 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li-yiyang/d189ba209c20a30968238655b3bafc72 to your computer and use it in GitHub Desktop.
Save li-yiyang/d189ba209c20a30968238655b3bafc72 to your computer and use it in GitHub Desktop.
Add a download selected button for UCAS SEP files.
// ==UserScript==
// @name UCAS SEP Download Selected Files
// @namespace http://li-yiyang.github.io/
// @version 0.1
// @description Add a download selected button for UCAS SEP files.
// @author 凉凉
// @match http*://course.ucas.ac.cn/portal/site/*/tool/*
// @grant none
// ==/UserScript==
// run after window is loaded
window.onload = (function () {
// base url of the content
let base_url = "https://course.ucas.ac.cn/access/content";
// Add a button to page.
// Get the bar.
let bar = document.getElementsByClassName("col-lg-6 col-md-8 col-sm-8 col-xs-12 btn-group btn-group-sm")[0];
// or at the bottom
// let bar = document.getElementById("bottompadding");
// make a button
let btm = document.createElement("button");
btm.innerHTML = "Download Selected";
btm.onclick = function () {
let table = document.getElementsByTagName("tr");
let length = table.length;
// the first two element of the web table is a total check
// and the second one is a directory path, which are useless
for (var i = 2; i < length; i++) {
let item = table[i].querySelector("[name=selectedMembers]");
if (item.checked) {
let url = base_url + item.value;
let fname = item.value.split("/").slice(-1)[0];
(function (url) {
// you can change the download method
window.open(url, "_blank");
})(url);
console.log(url)
}
}
}
// use the same style as copy button
btm.style = "margin:0";
btm.setAttribute("class", "btn btn-default");
btm.setAttribute("id", "download-button");
// add the item to the bar
bar.appendChild(btm);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment