Skip to content

Instantly share code, notes, and snippets.

@mikemanger
Last active January 20, 2018 20:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikemanger/b5bb71c9b9a1ac70b7ad to your computer and use it in GitHub Desktop.
Save mikemanger/b5bb71c9b9a1ac70b7ad to your computer and use it in GitHub Desktop.
Caches your Humble bundle key list
// ==UserScript==
// @name Humble Bundle key cache
// @include https://www.humblebundle.com/home*
// @updateURL https://gist.githubusercontent.com/mikemanger/b5bb71c9b9a1ac70b7ad/raw
// @downloadURL https://gist.githubusercontent.com/mikemanger/b5bb71c9b9a1ac70b7ad/raw
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-end
// @version 1.1.4
// ==/UserScript==
function mm_bundle_keys_cache_output_cache() {
var cache = GM_getValue( document.title + 'bundle-keys', '' ),
cache_wrapper = document.createElement( 'div' ),
main_wrapper = document.querySelector( '.base-main-wrapper' ),
top_element = document.getElementById( 'account-claim-box' );
cache_wrapper.className = 'mm_bundle_keys_cache';
cache_wrapper.innerHTML = cache;
main_wrapper.insertBefore( cache_wrapper, top_element );
}
function mm_bundle_keys_cache_update() {
// We have finished loading, set our cache.
var bundle_list = document.querySelector( '.js-purchase-list-box' ),
bundle_list_copy = bundle_list.cloneNode( true ),
heading = bundle_list_copy.getElementsByTagName( 'h1' ),
cache_wrapper = document.querySelector( '.mm_bundle_keys_cache' );
// Update cached list with live one
cache_wrapper.innerHTML = '';
cache_wrapper.appendChild( bundle_list );
// Store live one for next page load
heading[0].innerHTML += ' [cached]';
GM_setValue( document.title + 'bundle-keys', bundle_list_copy.innerHTML );
console.log( 'Humble Bundle Key Cache Updated' );
}
function mm_bundle_keys_cache_load() {
var target = document.querySelector( '.js-pre-downloads-holder' );
if ( ! target ) {
return;
}
mm_bundle_keys_cache_output_cache();
// Create an observer to monitor when the downloads holder div is hidden
var observer = new MutationObserver( function( mutations ) {
if ( 'none' === target.style.display ) {
observer.disconnect();
mm_bundle_keys_cache_update();
}
} );
var config = {
attributes: true
};
observer.observe( target, config );
}
window.addEventListener( 'DOMContentLoaded', mm_bundle_keys_cache_load );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment