Created
May 7, 2011 12:36
-
-
Save fluxid/960461 to your computer and use it in GitHub Desktop.
Soup.io post-hiding userscript
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== | |
// @include http://www.soup.io/everyone* | |
// @include http://www.soup.io/friends* | |
// @include http://www.soup.io/fof* | |
// @include http://www.soup.io/stalkers* | |
// ==/UserScript== | |
(function() { | |
var _urlget = { | |
'img': 'src', | |
'a': 'href', | |
}; | |
var _urlquery = ''; | |
(function() { | |
for (var key in _urlget) { | |
var value = _urlget[key]; | |
if (_urlquery) { | |
_urlquery += ', '; | |
} | |
_urlquery += key + '[' + value + ']'; | |
} | |
})(); | |
var url_matcher = function(regex) { | |
return function(post) { | |
var nodes = post.querySelectorAll(_urlquery); | |
for (var i = 0, _len = nodes.length; i < _len; i++) { | |
var node = nodes[i]; | |
var url = node.getAttribute(_urlget[node.nodeName.toLowerCase()]); | |
if (regex.test(url)) { | |
return true; | |
} | |
} | |
return false; | |
}; | |
}; | |
var class_matcher = function(class_) { | |
class_ = class_.split(' '); | |
return function(post) { | |
class__ = post.getAttribute('class').split(' '); | |
for (var i = 0, _len1 = class_.length; i < _len1; i++) { | |
var class1 = class_[i].toLowerCase(); | |
if (!class1) { | |
continue; | |
} | |
var found = false; | |
for (var j = 0, _len2 = class__.length; j < _len2; j++) { | |
var class2 = class__[j].toLowerCase(); | |
if (!class2) { | |
continue; | |
} | |
if (class1 == class2) { | |
found = true; | |
break; | |
} | |
} | |
if (!found) { | |
return false; | |
} | |
} | |
return true; | |
} | |
}; | |
var matchers = { | |
//instagram: url_matcher(/^.*(instagram\.heroku\.com|images\.instagram\.com).*$/i), | |
instagram: class_matcher('imported instagram-heroku-com'), | |
}; | |
var get_hidebox_area = function(post) { | |
var prev = post.previousElementSibling; | |
if (prev && prev.getAttribute('class') == '_fxd_hidebox') { | |
return prev.childNodes[1]; | |
} | |
var hidebox = document.createElement('div'); | |
var title = document.createElement('h3'); | |
hidebox.appendChild(title); | |
title.appendChild(document.createTextNode('I have hidden posts here')); | |
var area = document.createElement('div'); | |
hidebox.appendChild(area); | |
post.parentNode.insertBefore(hidebox, post); | |
hidebox.setAttribute('class', '_fxd_hidebox'); | |
var area_toggle = function() { | |
if (area.style.display == 'none') { | |
area.style.display = ''; | |
} else { | |
area.style.display = 'none'; | |
} | |
} | |
area_toggle(); | |
title.addEventListener('click', area_toggle, false); | |
return area; | |
}; | |
var hide_post = function(post) { | |
get_hidebox_area(post).appendChild(post.parentNode.removeChild(post)); | |
}; | |
var match_post = function(post) { | |
for (var matcher in matchers) { | |
matcher = matchers[matcher]; | |
if (matcher(post)) { | |
hide_post(post); | |
return; | |
} | |
} | |
}; | |
var process_batch = function(batch) { | |
var posts = batch.querySelectorAll('div.post'); | |
for (var i = 0, _len = posts.length; i < _len; i++) { | |
match_post(posts[i]); | |
} | |
}; | |
var load = function(evt) { | |
var style = document.createElement('style'); | |
style.appendChild(document.createTextNode('div._fxd_hidebox { margin: 1em 0; border: solid black 1px; border-left: none; border-right: none; }\ndiv._fxd_hidebox h3 { margin: 0.5em; }')); | |
document.getElementsByTagName('head')[0].appendChild(style); | |
var first_batch = document.getElementById('first_batch'); | |
if (first_batch) { | |
process_batch(first_batch); | |
} | |
var posts = document.getElementById('more_history'); | |
if (!posts) { | |
return; // FFFFFFUUUU | |
} | |
var on_node_inserted = function(evt) { | |
if (evt.relatedNode != posts) { | |
return; | |
} | |
process_batch(evt.target); | |
} | |
posts.addEventListener('DOMNodeInserted', on_node_inserted, false); | |
}; | |
if (!!document.body) { | |
load(); | |
} else { | |
document.addEventListener('DOMContentLoaded', load, false); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment