Skip to content

Instantly share code, notes, and snippets.

@neenjaw
Last active May 12, 2019 04:08
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 neenjaw/a5fd5ec2309b15f31d29a8598c2035c4 to your computer and use it in GitHub Desktop.
Save neenjaw/a5fd5ec2309b15f31d29a8598c2035c4 to your computer and use it in GitHub Desktop.
Exercism.io -- Hide comment panel to increase readability of code panel
// ==UserScript==
// @name Exercism panel expand
// @namespace Exercism
// @version 0.1
// @description Expand coding panel by hiding the comment panel
// @author Tim Austin
// @match https://exercism.io/*/solutions/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function toggleElement() {
const hideMessage = "Hide Comment Panel";
const showMessage = "Show Comment Panel";
const singlePanelClass = 'pure-u-md-1-1';
const dualPanelClass = 'pure-u-md-1-2';
const leftPanelQuery = 'div.panels > div.lhs';
const rightPanelQuery = 'div.panels > div.rhs';
const leftPanel = document.querySelector(leftPanelQuery);
const rightPanel = document.querySelector(rightPanelQuery);
const toggleHtml = `
<div class="toggle-pane-width">
<span class="button">${hideMessage}</span>
</div>`;
// Create the template element
const template = document.createElement('template');
template.innerHTML = toggleHtml.trim();
//create the toggle div and style it
const toggleDiv = template.content.firstChild;
toggleDiv.style.marginBottom = "18px";
toggleDiv.style.display = "flex";
toggleDiv.style.justifyContent = "flex-end";
//create the toggle button and style it
const toggleButton = toggleDiv.querySelector(".button");
toggleButton.style.border = "1px solid #CCCCCC";
toggleButton.style.borderRadius = "3px";
toggleButton.style.padding = "3px 3px 3px 3px";
toggleButton.style.backgroundColor = "#EEEEEE";
toggleButton.addEventListener("click", (e) => {
if (rightPanel.style.display == "") {
toggleButton.innerText = showMessage;
rightPanel.style.display = "none";
leftPanel.classList.remove(dualPanelClass);
leftPanel.classList.add(singlePanelClass);
} else {
toggleButton.innerText = hideMessage;
rightPanel.style.display = "";
leftPanel.classList.remove(singlePanelClass);
leftPanel.classList.add(dualPanelClass);
}
});
return toggleDiv;
}
const tabsDiv = document.querySelector('div.panels div.tabs');
const nextSiblingToTabsDiv = tabsDiv.nextElementSibling;
const parentContainer = nextSiblingToTabsDiv.parentNode;
// Insert the new toggle button
parentContainer.insertBefore(toggleElement(), nextSiblingToTabsDiv);
})();
@neenjaw
Copy link
Author

neenjaw commented May 12, 2019

Install tampermonkey chrome extension (link), copy gist contents to a new script, navigate to a solution, then click the button!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment