jakebathman
3/1/2017 - 2:07 PM

Data.Medicare.Gov helper script

Data.Medicare.Gov helper script

This helps with the data "tables" (which are really nested divs in divs) on data.medicare.gov

One of the main features is the ability to copy values in the data tables by Ctrl+clicking on a value.

The selected and/or copied text is displayed above the table for confirmation.

NOTE: The method used to detect what was clicked isn't very reliable, mostly due to the way this "table" is created and clicks are detected. I'll continue to work on a better method and update the script accordingly.

Finally, there are some basic log outputs in the console, which may help you determine what's going on if it's not expected.

// ==UserScript==
// @name         Helper for data.medicare.gov
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @description  Ctrl+click copy and more
// @author       Jake Bathman
// @downloadURL  https://gist.githubusercontent.com/jakebathman/8d2ca9a798e4f3e83baefda2ffc22b32/raw
// @include      https://data.medicare.gov/Home-Health-Compare*
// @include      https://data.medicare.gov/Hospital-Compare*
// @grant GM_setClipboard
// ==/UserScript==

$("#searchForm").on('click',function(){
    $("input.searchField").focus().select();
});

$(document).keydown(function(event){
    if(event.which=="17")
        cntrlIsPressed = true;
});

$(document).keyup(function(){
    cntrlIsPressed = false;
});

var cntrlIsPressed = false;
$("#description").html('');
$("#infoBox").append('<div style="padding:5px;font-size:13px;color:grey;margin:5px;" id="copiedText"></div>');

(function() {
    $('.outerContainer').on('click',function (event) {
        el = $('.blist-hot')[0];
        console.debug($(el).html());
        $(el).css('background-color','#c9f5c9');

        $("#description").html('');
        $("#copiedText").css('color','grey').css('background-color','inherit').html($(el).html());

        if(cntrlIsPressed)
        {
            GM_setClipboard($(el).html()); // Copy to clipboard
            $("#copiedText").css('color','black').css('background-color','#c9f5c9').html("COPIED: <strong>" + $(el).html() + "</strong");
            timeoutEl = setTimeout(function(){
                $("#copiedText").html('').css('color','grey').css('background-color','inherit');
            }, 2000);
            console.log("Copied to clipboard: ");
            console.debug($(el).html());
        }
    });
})();