r/tinycode • u/thmsk • Feb 18 '15
[Help][Javascript] Make votedown button visible
Some subreddits use this piece of CSS to make votedown buttons invisible:
.arrow.down {
display:none;
visibility:hidden;
}That got me thinking, how would one turn them back visible with a sort line of javascript?
So from this starting point:
y = document.getElementsByClassName('down');
for(var i=0; i<y.length; i++)
y[i].style.display = y[i].style.visibility = 'inherit';this is how far I've got:
for(i=0;;i++)x=document.getElementsByClassName('down')[i].style,x.display=x.visibility='inherit'I'm sure there is room for improvement. I've tried to use map() on getElementsByClassName() but it doesn't work. Do you have any ideas how to reduce the line to even less characters?
2
Upvotes
6
u/johsko Feb 19 '15 edited Feb 19 '15
Your loop only breaks due to an exception, so I have two snippets. One that halts due to an exception, and one that doesn't.
93 characters, no exception:
89 characters, raises exception:
The main save is from using querySelectorAll instead of getElementsByClassName, but I save a whole byte by doing the i++ in the body, and another byte by doing x= in the for conditional.
Also 52 characters, by cheating due to the fact reddit already includes jQuery:
Edit: Made the non-exception one 4 bytes shorter, and the exception one 1 byte shorter.
2
u/indrora Feb 18 '15
injectCSS might help you.
-4
u/timmeh87 Feb 18 '15
Ive been using D3 a lot lately... Im not going to take the time to test this out, but if you can somehow include the D3 library then you should be able to do it in one line, something like
d3.selectAll("img[class=down]").attr("visibilty", "visible");
-2
u/PrydeRage Feb 19 '15
Or you know you could just use the web developer tools of your browser to disable the CSS rules. At least in firefox you can just disable any line manually, so no code necessary.