Last active
September 1, 2015 11:09
-
-
Save raldred/fc37faa3abb5ef96781b to your computer and use it in GitHub Desktop.
Digitally Imported Responsive Fix
This file contains 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 Digitally Imported Unresponsive Fix | |
// @namespace http://robaldred.co.uk/ | |
// @version 0.1 | |
// @description Watches for the annoying unresponsive popup that's presented and resumes playback. | |
// @match http://www.di.fm/* | |
// @copyright 2015+, Rob Aldred | |
// ==/UserScript== | |
;(function(window) { | |
'use strict'; | |
var listeners = [], | |
document = window.document, | |
MutationObserver = window.MutationObserver || window.WebKitMutationObserver, | |
observer; | |
function watch(selector, callback){ | |
listeners.push({ | |
selector: selector, | |
callback: callback | |
}); | |
if(!observer){ | |
// Watch for changes in the document | |
observer = new MutationObserver(check); | |
observer.observe(doc.documentElement, { | |
childList: true, | |
subtree: true | |
}); | |
} | |
// Check if the element is currently in the DOM | |
check(); | |
} | |
function checkVisibility(){ | |
// Check the DOM for elements matching a stored selector | |
for(var i = 0, len = listeners.length, listener, elements; i < len; i++){ | |
listener = listeners[i]; | |
// Query for elements matching the specified selector | |
elements = doc.querySelectorAll(listener.selector); | |
for(var j = 0, jLen = elements.length, element; j < jLen; j++){ | |
element = elements[j]; | |
// Make sure the callback isn't invoked with the | |
// same element more than once | |
if(!element.ready){ | |
element.ready = true; | |
// Invoke the callback with the element | |
listener.fn.call(element, element); | |
} | |
} | |
} | |
} | |
watch('#panel-unresponsive',function(element) { | |
}); | |
})(window); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment