Skip to content

Instantly share code, notes, and snippets.

@maciejkos
Last active October 8, 2023 22:20
Show Gist options
  • Save maciejkos/35fde432c0939a0c77059372dd35a501 to your computer and use it in GitHub Desktop.
Save maciejkos/35fde432c0939a0c77059372dd35a501 to your computer and use it in GitHub Desktop.
Copy code from Gradescope to clipboard (bookmarklet for Chrome)
// Running this bookmarklet on a Gradescope grading page adds a copy icon next to the contents of each attached file.
// Clicking the icon copies the file contents to the clipboard.
// Use case: I grade many coding assignments submitted by students to Gradescope. This bookmarklet saves me a few seconds per submission.
javascript:(function(){function copyToClipboard(text){const textarea=document.createElement('textarea');textarea.value=text;document.body.appendChild(textarea);textarea.select();document.execCommand('copy');document.body.removeChild(textarea);}const fileViewers=document.querySelectorAll('.fileViewer');fileViewers.forEach((fileViewer)=>{const copyIcon=document.createElement('i');copyIcon.className='fa fa-copy';copyIcon.style.cursor='pointer';copyIcon.style.marginLeft='10px';const fileViewerHeader=fileViewer.querySelector('.fileViewerHeader');fileViewerHeader.appendChild(copyIcon);const fileContents=fileViewer.querySelector('.hljs').textContent;copyIcon.addEventListener('click',()=>{copyToClipboard(fileContents);});});})();
// How to use:
// 1. In Chrome, right-click on the bookmarks bar and select "Add page."
// 2. Name your bookmarklet, e.g., "Copy File Contents."
// 3. In the URL field, paste the above code (line 6) as a single line of code, including javascript:
// 4. Save the bookmark.
// When grading an individual assignment, click on all file names to show their contents on the page.
// Click the bookmarklet and copy icons will appear next to "Download."
// Click the icon to copy the file contents to the clipboard.
// Tested on:
// - Windows 10
// - Chrome Version 117.0.5938.134 (Official Build) (64-bit)
// - 10/8/2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment