Last active
June 3, 2019 16:40
-
-
Save SonicZentropy/8b132c736352fa570f850e52ce832233 to your computer and use it in GitHub Desktop.
Blackboard JS Hack to force rewrite copied URLs that link to shell-specific locations
This file contains 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
<!-- This snippet binds a function to the "dom:loaded" event. | |
You can put your own javascript into the function, or replace | |
the entire snippet. --> | |
<script type="text/javascript"> | |
Event.observe(document,"dom:loaded", function() { | |
//Just filter by span since BB uses random hashes for class names | |
let elements = document.getElementsByTagName('span'); | |
let matching = "None"; | |
for (let i = 0; i < elements.length; i++) { | |
//iterate EVERY span looking for Course Content, because Blackboard. | |
if (elements[i].title === 'Course Content' ) { | |
//found the correct content | |
matching = elements[i]; | |
} | |
} | |
//Should check that `matching` is filled here for safety, but in our case it ALWAYS will be found | |
//isolate the content_id portion to extract the proper content_id to use for replacement | |
const urlref = matching.parentElement.attributes[0].nodeValue; | |
const firstSubIndex = urlref.indexOf('content_id='); | |
const secondSubIndex = urlref.indexOf("&"); | |
// "content_id=" is 11 characters long and some people hate magic numbers | |
const contentIDToIgnoreSize = 11; | |
const finalID = urlref.substring(firstSubIndex + contentIDToIgnoreSize, secondSubIndex); | |
//replacing img text | |
//again grab and iterate every single img because there's no better way provided via Blackboard. | |
elements = document.getElementsByTagName('img'); | |
for (let i = 0; i < elements.length; i++) { | |
if (elements[i].title === 'Course Content' ) { | |
//need the parent of the img itself, as that's where the link URL actually lives | |
let mainElement = elements[i].parentElement; | |
//The actual URL to be manipulated | |
matching = mainElement.attributes[0].nodeValue; | |
//replace the copied incorrect content ID with the one found previously | |
matching = matching.replace(/content_id=([^&]*)/, "/content_id=" + finalID); | |
//Update BB's link to match | |
mainElement.attributes[0].nodeValue = matching; | |
//chug beers | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment