Skip to content

Instantly share code, notes, and snippets.

@tekerson
Created August 30, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekerson/cad483b2eee0ae18eb8667710653d391 to your computer and use it in GitHub Desktop.
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
// ==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