Last active
May 21, 2021 13:23
-
-
Save jrr6/2cfb984396d0e0d556ed2b117d5fe678 to your computer and use it in GitHub Desktop.
A userscript that adds a button to the assignment page on Google Classroom allowing you go back to your Work list. You'll need to install this script from Tampermonkey's "Utilities" page (copy the download URL, then paste it into TamperMonkey's URL import field), as Google Chrome doesn't like Gist.
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 Classroom Back to Work | |
| // @description Adds a button on the assignment page to go back to your work list, rather than the corresponding Class. | |
| // @include https://classroom.google.com/* | |
| // @downloadURL https://gist.github.com/jrr6/2cfb984396d0e0d556ed2b117d5fe678/raw/GCBackToWork.user.js | |
| // @updateURL https://gist.github.com/jrr6/2cfb984396d0e0d556ed2b117d5fe678/raw/GCBackToWork.user.js | |
| // @version 1.1.4 | |
| // @author aaplmath | |
| // ==/UserScript== | |
| function addButton () { | |
| let button = document.querySelector('#b2w-button') | |
| let buttonExists = button !== null | |
| let isInAssignment = window.location.pathname.indexOf('/c') > -1 && window.location.pathname.indexOf('/a') > -1 | |
| if (isInAssignment && !buttonExists) { | |
| let topBar = document.querySelector('.XIpEib.QRiHXd') | |
| if (topBar !== null) { | |
| let a = document.createElement('a') | |
| let div = document.createElement('div') | |
| let h1 = document.createElement('h1') | |
| div.setAttribute('id', 'b2w-button') | |
| a.setAttribute('href', '#') | |
| a.style.marginLeft = '1em' | |
| div.style.border = '1px solid rgba(0,0,0,0.87)' | |
| div.style.padding = '0.5em' | |
| div.style.position = 'absolute' | |
| div.style.top = '1em' | |
| h1.style.color = 'rgba(0,0,0,0.87)' | |
| h1.textContent = 'Back to Work' | |
| div.appendChild(h1) | |
| a.appendChild(div) | |
| topBar.appendChild(a) | |
| a.addEventListener('click', goBackToWork, false) | |
| } else { | |
| window.setTimeout(addButton, 500) | |
| } | |
| } else if (buttonExists && !isInAssignment) { | |
| button.parentNode.removeChild(button) | |
| } | |
| } | |
| function goBackToWork (e) { | |
| e.preventDefault() | |
| document.querySelector('a[href="/a/not-turned-in/all"]').click() | |
| } | |
| addButton() | |
| const obs = new MutationObserver(function (mutations, observer) { | |
| if (mutations[0].addedNodes.length || mutations[0].removedNodes.length) | |
| addButton() | |
| }) | |
| obs.observe(document.body, { | |
| childList: true, | |
| subtree: true | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment