Skip to content

Instantly share code, notes, and snippets.

@firien
Last active October 4, 2015 06:57
Show Gist options
  • Save firien/2596735 to your computer and use it in GitHub Desktop.
Save firien/2596735 to your computer and use it in GitHub Desktop.
self enclosed js that removes unmentionables from DOM
# encoding: UTF-8
require 'uri'
require 'uglifier'
require 'coffee-script'
js = CoffeeScript.compile DATA.read
#plain js
puts js
#bookmarklet
puts URI.encode('javascript:' + Uglifier.compile(js))
#coffee script source ↓
__END__
Blaster =
empty: (element) ->
if document.documentElement.contains element
element.parentNode.removeChild element
return
query: (selector) ->
#convert NodeList to Array
Array::slice.call document.querySelectorAll selector
Blaster.query('a img').map (i) ->
#if image is not a link to the current domain then remove
parent = i.parentNode
if parent?
parent = parent.parentNode until parent.nodeName.toLowerCase() == 'a'
Blaster.empty(parent) if parent.hostname != window.location.host
return
Blaster.query('img[onclick],iframe,object,video').map (i) ->
i.parentNode.removeChild i
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment