Created
June 7, 2021 20:31
-
-
Save edykim/f550a7a8aa8779e68647ed12f0f27686 to your computer and use it in GitHub Desktop.
Status highlights for assignments on Canvas
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 Add status highlights for assignments on Canvas | |
| // @version 0.1 | |
| // @include https://canvas.instructure.com/courses/*/assignments | |
| // @author edykim | |
| // @grant none | |
| // ==/UserScript== | |
| (function () { | |
| function install_status_marker(window, $) { | |
| "use strict"; | |
| const styles = ` | |
| .not-available-until:after, | |
| .already-submitted:after, | |
| .already-closed:after { | |
| display: inline-block; | |
| font-size: 12px; | |
| padding: 5px 10px; | |
| border-radius: 10px; | |
| font-weight: bold; | |
| } | |
| .not-available-until:after { | |
| content: "Not available"; | |
| color: red; | |
| } | |
| .already-submitted:after { | |
| content: "Submitted"; | |
| color: blue; | |
| } | |
| .already-closed:after { | |
| content: "Closed"; | |
| color: black; | |
| } | |
| .ig-row:not(.marked) { | |
| border-left: 4px solid green; | |
| } | |
| `; | |
| // if there is an ajax call | |
| $.ajaxSetup({ | |
| complete: function (event, xhr, settings) { | |
| setTimeout(() => { | |
| set_state_as_class(); | |
| }, 60); | |
| }, | |
| }); | |
| function install() { | |
| setTimeout(() => { | |
| if ($(".assignment-list li").length === 0) { | |
| install(); | |
| } else { | |
| update(); | |
| } | |
| }, 200); | |
| } | |
| function update() { | |
| $("<style>").text(styles).appendTo($("body")); | |
| set_state_as_class(); | |
| } | |
| function set_state_as_class() { | |
| $(".status-description:contains('Not available until')").each( | |
| function () { | |
| $(this) | |
| .parents(".ig-row:first") | |
| .addClass("not-available-until") | |
| .addClass("marked"); | |
| } | |
| ); | |
| $(".status-description:contains('Closed')").each(function () { | |
| $(this) | |
| .parents(".ig-row:first") | |
| .addClass("already-closed") | |
| .addClass("marked"); | |
| }); | |
| $(".grade-display, .score-display b").each(function () { | |
| $(this) | |
| .parents(".ig-row:first") | |
| .addClass("already-submitted") | |
| .addClass("marked"); | |
| }); | |
| } | |
| install(); | |
| } | |
| function load_after_jq() { | |
| if (window.jQuery) { | |
| install_status_marker(window, window.jQuery); | |
| } else { | |
| setTimeout(() => load_after_jq(), 100); | |
| } | |
| } | |
| load_after_jq(); | |
| })(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment