Bubba / Hint Spoiler (Khan Academy)

// ==UserScript==
// @name         Hint Spoiler (Khan Academy)
// @version      0.1
// @description  Hides the "Hint" in coding challanges by default, and allows you to show it with the click of a button.
// @namespace    http://bigbub.net/
// @homepageURL  http://bigbub.net/
// @author       Jespser Gustafsson
// @include      http*://www.khanacademy.org/computer-programming/*
// @include      http*://www.khanacademy.org/computing/computer-programming/*/*/p/*
// @grant        none
// @require      http://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==

(function() {
    'use strict';

    //
    function wrapHintInSpoiler() {
        var $hint = $('h3:contains("Hint")').parent().children().last();
        if ($hint.length > 0) {
            // Toggle hint (show/hide it) when it is clicked
            $hint.on('click', function() {
                if ($hint.children().first().css('visibility') == 'hidden') {
                    $hint.children().css('visibility', 'visible');
                } else {
                    $hint.children().css('visibility', 'hidden');
                }
            });
            // Hide it by default
            $hint.children().css('visibility', 'hidden');
            return true;
        }
        return false;
    }

    // Try wrapping the hint until we succeed
    var intv = setInterval(function() {
        var success = wrapHintInSpoiler(); // Try wrapping hint
        if (success) { clearInterval(intv); } // If successful, stop trying
    }, 0);
})();