Forked from mikemanger/humble-bundle-key-cache.user.js
Last active
December 6, 2016 03:14
-
-
Save markstinson/eb377c2c21b3b14c5676d375f619bdad to your computer and use it in GitHub Desktop.
Caches your Humble bundle key list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Humble Bundle key cache | |
// @include https://www.humblebundle.com/home* | |
// @updateURL https://gist.githubusercontent.com/markstinson/eb377c2c21b3b14c5676d375f619bdad/raw | |
// @downloadURL https://gist.githubusercontent.com/markstinson/eb377c2c21b3b14c5676d375f619bdad/raw | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @run-at document-end | |
// @version 1.1.4 | |
// ==/UserScript== | |
// update with your username/checksum | |
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