Last active
August 29, 2015 14:25
-
-
Save cnelson/b166bdc17b84cea68d15 to your computer and use it in GitHub Desktop.
World War Z Index
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
function world_war_zindex() { | |
DEBUG = false; | |
//include jquery2 if we don't have it | |
if (! jQuery) { | |
var script = document.createElement("script"); | |
script.src = "//code.jquery.com/jquery-2.1.4.min.js"; | |
document.head.appendChild(script); | |
$.noConflict(); | |
} | |
function elements_with_zindex() { | |
var results = {}; | |
//iterate through all elements int he dom, looking for ones | |
//with a zindex set | |
var all_elements = jQuery("*"); | |
for (i=0; i < all_elements.length; i++) { | |
//get a jquery instance for the active element | |
var element = jQuery(all_elements[i]); | |
//see if it has a zindex | |
var zindex = element.css('z-index'); | |
//if not, bounce | |
if (! zindex || zindex == "auto") { | |
continue; | |
} | |
//if we don't have anything at this zindex yet | |
//then add an empty list | |
if (! results[zindex]) { | |
results[zindex] = []; | |
} | |
//stash our find | |
results[zindex].push(all_elements[i]); | |
} | |
return results; | |
} | |
var results = elements_with_zindex(); | |
//if we have no results, then bounce | |
if (! Object.keys(results).length) { | |
return; | |
} | |
target_zindex = Object.keys(results).sort( | |
function(a, b) { return parseInt(a) - parseInt(b); } | |
).reverse()[0]; | |
console.warn("[WWZ] Removing all elements at z-index "+target_zindex); | |
for (j=0; j < results[target_zindex].length; j++) { | |
var element = results[target_zindex][j]; | |
jQuery(element).remove() | |
if (DEBUG) { | |
console.debug("[WWZ] Removing ", element) | |
} | |
} | |
if (DEBUG) { | |
console.debug("[WWZ] z-index is now", elements_with_zindex()); | |
} | |
} | |
world_war_zindex() |
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
javascript:function world_war_zindex(){function e(){var e={},n=jQuery("*");for(i=0;i<n.length;i++){var r=jQuery(n[i]),t=r.css("z-index");t&&"auto"!=t&&(e[t]||(e[t]=[]),e[t].push(n[i]))}return e}if(DEBUG=!1,!jQuery){var n=document.createElement("script");n.src="//code.jquery.com/jquery-2.1.4.min.js",document.head.appendChild(n),$.noConflict()}var r=e();if(Object.keys(r).length){for(target_zindex=Object.keys(r).sort(function(e,n){return parseInt(e)-parseInt(n)}).reverse()[0],console.warn("[WWZ] Removing all elements at z-index "+target_zindex),j=0;j<r[target_zindex].length;j++){var t=r[target_zindex][j];jQuery(t).remove(),DEBUG&&console.debug("[WWZ] Removing ",t)}DEBUG&&console.debug("[WWZ] z-index is now",e())}}world_war_zindex(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment