Created
August 30, 2018 14:47
-
-
Save tekerson/cad483b2eee0ae18eb8667710653d391 to your computer and use it in GitHub Desktop.
Userscript to add a "Community Solutions" link to the mentor page on Exercism.io
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
// ==UserScript== | |
// @name Show Community Solutions | |
// @namespace tekerson.com | |
// @version 1.0.0 | |
// @description Add a "Community Solutions" link to the mentor page on Exercism.io | |
// @match https://exercism.io/mentor/solutions/* | |
// @grant GM_openInTab | |
// @noframes | |
// @run-at document-end | |
// ==/UserScript== | |
function showCommunitySolutions() { | |
const headerEl = document.querySelector('#mentor-solution-page .track-header h2') | |
const tabs = document.querySelector('#mentor-solution-page .tabs') | |
const [titleEl, trackEl] = Array.from(headerEl.querySelectorAll('strong')); | |
const title = kebabCase(titleEl.innerText) | |
const track = kebabCase(trackEl.innerText.replace(/ Track$/, '')) | |
const path = `/tracks/${track}/exercises/${title}/solutions` | |
const tab = document.createElement('div') | |
tab.setAttribute('class', 'tab tab-4') | |
tab.addEventListener('click', () => GM_openInTab(path)) | |
tab.innerHTML = 'Community Solutions' | |
tabs.append(tab) | |
} | |
function kebabCase(title) { | |
return title.toLowerCase().split(' ').join('-') | |
} | |
showCommunitySolutions() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment