diff --git a/canvasBetter.js b/canvasBetter.js index 8c4899e..03ba80c 100644 --- a/canvasBetter.js +++ b/canvasBetter.js @@ -1,7 +1,7 @@ // ==UserScript== -// @name Canvas betterments 2.1 - LTI Install! [PROD] +// @name Canvas betterments 2.2 - Abort pending SIS Imports [PROD] // @namespace https://siteadmin.instructure.com/ -// @version 2019.03.21 +// @version 2021.03.18 // @description try to take over the world! // @author Daniel Gilogley // @match https://*.test.instructure.com/* @@ -319,7 +319,16 @@ function myJQueryCode() { }); } else if(document.location.pathname.toLowerCase() === "/dgtools2") { document.title = "DG Tools"; - $('#main').html('

DG Tools

DG Tools are the best!

Links

Tools




'); + $('#main').html('

DG Tools

DG Tools are the best!

Links

Tools




'); + + //Abort all pending SIS Imports + $('li.dg_action_abortsisimports').click(function(e){ + e.preventDefault(); + console.log('Aborting all pending SIS Imports'); + //Disable the button + $("button", this).attr("disabled","disabled"); + abortPendingSISImports(); + }); //LTI Buttons Function $('li.dg_action_lti').click(function(e){ @@ -875,6 +884,27 @@ function myJQueryCode() { xhr.send(data); } + //Abort all pending SIS Imports function + function abortPendingSISImports(){ + var data = null; + + var xhr = new XMLHttpRequest(); + xhr.withCredentials = true; + + xhr.addEventListener("readystatechange", function () { + if (this.readyState === 4) { + console.log(this.responseText); + alert("Aborted all pending SIS Imports.\n" + this.responseText); + } + }); + + xhr.open("PUT", "/api/v1/accounts/1/sis_imports/abort_all_pending"); + xhr.setRequestHeader("Authorization", "Bearer " + userToken); + xhr.setRequestHeader("Cache-Control", "no-cache"); + + xhr.send(data); + } + //======== Begin Google / Office LTI Auto Install ======== //read the ? part and add to action form for URL