Skip to content

Instantly share code, notes, and snippets.

@ruthenium
Last active August 8, 2018 14:46
Show Gist options
  • Save ruthenium/237f55bf93f81929019f714da7c3ad81 to your computer and use it in GitHub Desktop.
Save ruthenium/237f55bf93f81929019f714da7c3ad81 to your computer and use it in GitHub Desktop.
Hide all posts without media at the Invision forums
(function(){
function addLink(target) {
var div = document.createElement('div');
var a = document.createElement('a');
a.setAttribute('href', '#');
a.textContent = 'No media in post';
a.addEventListener('click', function(e){
if (target.style.display == "none") {
target.removeAttribute('style');
} else {
target.setAttribute('style', 'display:none');
}
e.preventDefault();
});
div.setAttribute('class', 'userscript hiddenlink'); // might be useful for ajax tracking
div.appendChild(a);
target.parentNode.insertBefore(div, target.nextSibling);
target.setAttribute('style', 'display:none');
}
var divs = document.getElementById('posts').querySelectorAll("div[id^='post_message']"); // old browsers not supported
var len = divs.length;
for (var i = 0; i < len; i++) {
var div = divs[i];
if (div.querySelectorAll('img:not(.inlineimg), iframe, div:not(.userscript)').length <= 0) { // .inlineimg is a class for emojis; iframe is for youtube
addLink(div);
}
}
})();
!function(){function e(e){var t=document.createElement("div"),n=document.createElement("a");n.setAttribute("href","#"),n.textContent="No media in post",n.addEventListener("click",function(t){"none"==e.style.display?e.removeAttribute("style"):e.setAttribute("style","display:none"),t.preventDefault()}),t.setAttribute("class","userscript hiddenlink"),t.appendChild(n),e.parentNode.insertBefore(t,e.nextSibling),e.setAttribute("style","display:none")}for(var t=document.getElementById("posts").querySelectorAll("div[id^='post_message']"),n=t.length,i=0;i<n;i++){var r=t[i];r.querySelectorAll("img:not(.inlineimg), iframe, div:not(.userscript)").length<=0&&e(r)}}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment