You hate h̶a̶t̶s̶ reputation? Click here to get rid of it
Soo... I recently read a meta-post about the inherent problems of reputation. It listed some things like:
- Confirmation bias.
- Demotivating for low-rep users.
- Hubris and elitism of high-rep users over low-rep users.
- Incorrect representation of competence.
- ...
So I thought to myself: "How would the network be, just without reputation?"
I grabbed the inspector, checked questions, my profile page and the active page and how reputation is displayed.
Then I quickly hacked together the following small user-script (ECMA6) for Greasemonkey that would hide all reputation from sight:
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @description Hides all reputation displays from StackExchange sites
// @author Vogel612
// @grant none
// @include /https?://(meta.)?.*.stackexchange.com/.*/
// @include /https?://(stackoverflow|serverfault|superuser|askubuntu).com/.*/
// ==/UserScript==
/* jshint -W097 */
'use strict';
let slice = function(collection) {
return .slice.call(collection);
}
let repClasses = [ "rep", "reputation", "reputation-score" ];
let hideRepz = function() {
repClasses.forEach(clazz =>
slice(document.getElementsByClassName(clazz))
.forEach(el => {
// this results in minor inconsistencies in CSS, but alas
el.style.visibility = 'hidden';
})
);
}
hideRepz();
// add event listener for live-updates
document.addEventListener("DOMNodeInserted", hideRepz);
This has been running for a while now for me and I like to say it's a refreshing change. That aside:
It hides all reputation numbers on the page. If you're curious you can still find them of course. Also it looks funny on /questions when the active timers are outdented differently, but that's just my OCD going mad there.
It also checks for new questions you load over the notification.
What can I do better in that userscript?
javascript stackexchange ecmascript-6 userscript
|
show 2 more comments
Soo... I recently read a meta-post about the inherent problems of reputation. It listed some things like:
- Confirmation bias.
- Demotivating for low-rep users.
- Hubris and elitism of high-rep users over low-rep users.
- Incorrect representation of competence.
- ...
So I thought to myself: "How would the network be, just without reputation?"
I grabbed the inspector, checked questions, my profile page and the active page and how reputation is displayed.
Then I quickly hacked together the following small user-script (ECMA6) for Greasemonkey that would hide all reputation from sight:
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @description Hides all reputation displays from StackExchange sites
// @author Vogel612
// @grant none
// @include /https?://(meta.)?.*.stackexchange.com/.*/
// @include /https?://(stackoverflow|serverfault|superuser|askubuntu).com/.*/
// ==/UserScript==
/* jshint -W097 */
'use strict';
let slice = function(collection) {
return .slice.call(collection);
}
let repClasses = [ "rep", "reputation", "reputation-score" ];
let hideRepz = function() {
repClasses.forEach(clazz =>
slice(document.getElementsByClassName(clazz))
.forEach(el => {
// this results in minor inconsistencies in CSS, but alas
el.style.visibility = 'hidden';
})
);
}
hideRepz();
// add event listener for live-updates
document.addEventListener("DOMNodeInserted", hideRepz);
This has been running for a while now for me and I like to say it's a refreshing change. That aside:
It hides all reputation numbers on the page. If you're curious you can still find them of course. Also it looks funny on /questions when the active timers are outdented differently, but that's just my OCD going mad there.
It also checks for new questions you load over the notification.
What can I do better in that userscript?
javascript stackexchange ecmascript-6 userscript
55
Welcome to Stack Exchange, the network where everything's made up and the points don't matter.
– Josay
Feb 15 '16 at 15:59
19
Why are you using JS for this? Wouldn't custom CSS solve this better (and much easier)?
– Bergi
Feb 15 '16 at 16:18
7
You could do the same from a userscript actually. Justdocument.head.appendChild(document.createElement("style")).textContent = ".rep, .reputation, .reputation-scope { visibility: hidden; }";
– Bergi
Feb 15 '16 at 16:44
5
Will you post this on StackApps?
– A.L
Feb 16 '16 at 12:08
1
@A.L. I didn't intend to originally, but now I am considering. I would add some more functionality though before doing that. Feel free to post yourself, even though it's 3 lines of CSS for that matter
– Vogel612♦
Feb 16 '16 at 12:10
|
show 2 more comments
Soo... I recently read a meta-post about the inherent problems of reputation. It listed some things like:
- Confirmation bias.
- Demotivating for low-rep users.
- Hubris and elitism of high-rep users over low-rep users.
- Incorrect representation of competence.
- ...
So I thought to myself: "How would the network be, just without reputation?"
I grabbed the inspector, checked questions, my profile page and the active page and how reputation is displayed.
Then I quickly hacked together the following small user-script (ECMA6) for Greasemonkey that would hide all reputation from sight:
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @description Hides all reputation displays from StackExchange sites
// @author Vogel612
// @grant none
// @include /https?://(meta.)?.*.stackexchange.com/.*/
// @include /https?://(stackoverflow|serverfault|superuser|askubuntu).com/.*/
// ==/UserScript==
/* jshint -W097 */
'use strict';
let slice = function(collection) {
return .slice.call(collection);
}
let repClasses = [ "rep", "reputation", "reputation-score" ];
let hideRepz = function() {
repClasses.forEach(clazz =>
slice(document.getElementsByClassName(clazz))
.forEach(el => {
// this results in minor inconsistencies in CSS, but alas
el.style.visibility = 'hidden';
})
);
}
hideRepz();
// add event listener for live-updates
document.addEventListener("DOMNodeInserted", hideRepz);
This has been running for a while now for me and I like to say it's a refreshing change. That aside:
It hides all reputation numbers on the page. If you're curious you can still find them of course. Also it looks funny on /questions when the active timers are outdented differently, but that's just my OCD going mad there.
It also checks for new questions you load over the notification.
What can I do better in that userscript?
javascript stackexchange ecmascript-6 userscript
Soo... I recently read a meta-post about the inherent problems of reputation. It listed some things like:
- Confirmation bias.
- Demotivating for low-rep users.
- Hubris and elitism of high-rep users over low-rep users.
- Incorrect representation of competence.
- ...
So I thought to myself: "How would the network be, just without reputation?"
I grabbed the inspector, checked questions, my profile page and the active page and how reputation is displayed.
Then I quickly hacked together the following small user-script (ECMA6) for Greasemonkey that would hide all reputation from sight:
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @description Hides all reputation displays from StackExchange sites
// @author Vogel612
// @grant none
// @include /https?://(meta.)?.*.stackexchange.com/.*/
// @include /https?://(stackoverflow|serverfault|superuser|askubuntu).com/.*/
// ==/UserScript==
/* jshint -W097 */
'use strict';
let slice = function(collection) {
return .slice.call(collection);
}
let repClasses = [ "rep", "reputation", "reputation-score" ];
let hideRepz = function() {
repClasses.forEach(clazz =>
slice(document.getElementsByClassName(clazz))
.forEach(el => {
// this results in minor inconsistencies in CSS, but alas
el.style.visibility = 'hidden';
})
);
}
hideRepz();
// add event listener for live-updates
document.addEventListener("DOMNodeInserted", hideRepz);
This has been running for a while now for me and I like to say it's a refreshing change. That aside:
It hides all reputation numbers on the page. If you're curious you can still find them of course. Also it looks funny on /questions when the active timers are outdented differently, but that's just my OCD going mad there.
It also checks for new questions you load over the notification.
What can I do better in that userscript?
javascript stackexchange ecmascript-6 userscript
javascript stackexchange ecmascript-6 userscript
edited Feb 17 '16 at 12:29
Ilmari Karonen
1,747915
1,747915
asked Feb 15 '16 at 13:33
Vogel612♦
21.3k346128
21.3k346128
55
Welcome to Stack Exchange, the network where everything's made up and the points don't matter.
– Josay
Feb 15 '16 at 15:59
19
Why are you using JS for this? Wouldn't custom CSS solve this better (and much easier)?
– Bergi
Feb 15 '16 at 16:18
7
You could do the same from a userscript actually. Justdocument.head.appendChild(document.createElement("style")).textContent = ".rep, .reputation, .reputation-scope { visibility: hidden; }";
– Bergi
Feb 15 '16 at 16:44
5
Will you post this on StackApps?
– A.L
Feb 16 '16 at 12:08
1
@A.L. I didn't intend to originally, but now I am considering. I would add some more functionality though before doing that. Feel free to post yourself, even though it's 3 lines of CSS for that matter
– Vogel612♦
Feb 16 '16 at 12:10
|
show 2 more comments
55
Welcome to Stack Exchange, the network where everything's made up and the points don't matter.
– Josay
Feb 15 '16 at 15:59
19
Why are you using JS for this? Wouldn't custom CSS solve this better (and much easier)?
– Bergi
Feb 15 '16 at 16:18
7
You could do the same from a userscript actually. Justdocument.head.appendChild(document.createElement("style")).textContent = ".rep, .reputation, .reputation-scope { visibility: hidden; }";
– Bergi
Feb 15 '16 at 16:44
5
Will you post this on StackApps?
– A.L
Feb 16 '16 at 12:08
1
@A.L. I didn't intend to originally, but now I am considering. I would add some more functionality though before doing that. Feel free to post yourself, even though it's 3 lines of CSS for that matter
– Vogel612♦
Feb 16 '16 at 12:10
55
55
Welcome to Stack Exchange, the network where everything's made up and the points don't matter.
– Josay
Feb 15 '16 at 15:59
Welcome to Stack Exchange, the network where everything's made up and the points don't matter.
– Josay
Feb 15 '16 at 15:59
19
19
Why are you using JS for this? Wouldn't custom CSS solve this better (and much easier)?
– Bergi
Feb 15 '16 at 16:18
Why are you using JS for this? Wouldn't custom CSS solve this better (and much easier)?
– Bergi
Feb 15 '16 at 16:18
7
7
You could do the same from a userscript actually. Just
document.head.appendChild(document.createElement("style")).textContent = ".rep, .reputation, .reputation-scope { visibility: hidden; }";– Bergi
Feb 15 '16 at 16:44
You could do the same from a userscript actually. Just
document.head.appendChild(document.createElement("style")).textContent = ".rep, .reputation, .reputation-scope { visibility: hidden; }";– Bergi
Feb 15 '16 at 16:44
5
5
Will you post this on StackApps?
– A.L
Feb 16 '16 at 12:08
Will you post this on StackApps?
– A.L
Feb 16 '16 at 12:08
1
1
@A.L. I didn't intend to originally, but now I am considering. I would add some more functionality though before doing that. Feel free to post yourself, even though it's 3 lines of CSS for that matter
– Vogel612♦
Feb 16 '16 at 12:10
@A.L. I didn't intend to originally, but now I am considering. I would add some more functionality though before doing that. Feel free to post yourself, even though it's 3 lines of CSS for that matter
– Vogel612♦
Feb 16 '16 at 12:10
|
show 2 more comments
6 Answers
6
active
oldest
votes
It would be better to do this with a user style, e.g. using the Stylish extension, like this:
.rep, .reputation, .reputation-score {
visibility: hidden;
}
One advantage of user styles over scripts is that they're applied as soon as the page starts to load, so you won't see the rep counts flicker briefly while the page is loading. Also, user styles will automatically apply also to new dynamic content loaded e.g. via Ajax (such as new answers posted while you're viewing the page).
If you insist on using a user script, it's possibly to emulate user styles by using @run-at document-start and injecting a custom style element into the page early, like this:
// ==UserScript==
// @name Hide Stack Exchange reputation (demo)
// @namespace http://vyznev.net/
// @description A demonstration of using style injection to emulate user styles
// @author Ilmari Karonen
// @version 1.0
// @license Public domain
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.askubuntu.com/*
// @homepageURL http://codereview.stackexchange.com/a/120100
// @grant none
// @run-at document-start
// ==/UserScript==
var css =
".rep, .reputation, .reputation-score {n" +
" visibility: hidden;n" +
"}n";
var style = document.createElement('style');
style.textContent = css;
(document.head || document.documentElement).appendChild(style);
I use this method in my Stack Overflow Unofficial Patch (SOUP) user script (which combines a bunch of more or less minor interface bugfixes and improvements together) to let me efficiently apply both CSS-only and JS-based tweaks from a single user script.
One detail worth noting is that styles injected this way will generally end up being included before any actual site style sheets on the page, which means that they will be overridden by site CSS selectors of equal specificity. In some cases, you may need to use !important and/or various specificity hacks to make sure that your custom styles will take precedence.
13
If ES6 is available, best use template strings instead of concatenating.
– Joseph
Feb 16 '16 at 14:59
add a comment |
You could use querySelectorAll instead of getElementsByClassName. That way, you have a bit more flexibility in targeting elements. It also allows multiple selectors. That way, you don't have to loop twice.
Instead of .slice which uses an unnecessary array as host, try using Array.prototype.slice.call instead. Longer, but without that extra array.
Also, try using display:none as visibility just hides the element but maintain layout. This way, there's no awkward whitespace where the reputation was, making the layout all natural.
Seeing that you put ES6, we can use the handy dandy arrow functions as well.
'use strict';
const REPUTATION_ELEMENTS = '.rep, .reputation, .reputation-score';
function getElementArray(selector){
return Array.prototype.slice.call(document.querySelectorAll(selector));
}
document.addEventListener("DOMNodeInserted", event => {
getElementArray(REPUTATION_ELEMENTS).forEach( element => {
element.style.display = 'none';
});
});
6
Thedisplay:noneadvice is worth gold. One small thing: this doesn't run when loading the page by default. That's just a really minor thing. Also I recall hearing something aboutquerySelectorAllbeing slower than the more specialized calls, but I might be wrong. Thanks for the review :)
– Vogel612♦
Feb 15 '16 at 15:28
8
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
2
Another way to hide things:element.hidden = true. ciu, whatwg
– deltab
Feb 15 '16 at 17:54
1
@Vogel612 Yup, it's relatively slower than the older element selection APIs, but for a few elements it's probably negligible and more familiar because of jQuery. Speaking of jQuery, not sure if possible, but if the userscript can utilize the one that is already on the page, it can be as simple as$(selector).hide().
– Joseph
Feb 16 '16 at 1:24
@BergiforEachjust came out of instinct, especially with arrays. :D
– Joseph
Feb 16 '16 at 1:29
add a comment |
Update url
UserScripts have the magical ability to update themselves if you provide a link to a raw version of your script as a UserScript header:
Note: You actually have to increase the version, or it won't update.
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @downloadURL
// @updateURL
Method
I'm not particularly a fan of your method.
Checking for DOM updates before scanning through everything all over again.
It would make more sense to simply inject a stylesheet to override SE's stylesheets.
Much more labour performant.
ES6 features
I like the use of ES6 in your code, but you haven't used it to its full potential:
let slice = function(collection) {
return .slice.call(collection);
}
Instead of using the old function(collection){} way, you can use (collection) => ():
let slice = (collection) => .slice.call(collection)
The same thing applies to the function in your main loop.
Slicing and Dicing
Currently, you only use slice with your element selection.
You should combine the two!
slice(document.getElementsByClassName(clazz))
let fetchElements(clazz) => .slice.call(document.getElementsByClassName(clazz))
Or hey, let's take it a step further and do some concatenation magic:
let fetchElements = (clazzArrey) =>
clazzArrey.map((clazz) => .slice.call(document.getElementsByClassName(clazz)))
Alternatively, you can use string concatenation to make one huge selector string and use querySelectorAll as Joseph described.
I find that querySelector* can have worse performance, but its always been edge cases that trigger that for me.
Future gazing
This isn't usually a review point I add, however, I think you could add support for other fields, and make a handy dandy dialog box to choose which you want to hide. That'd be a StackApps worthy creation in my eyes.
add a comment |
Instead of document.getElementsByClassName, you can use document.querySelectorAll(CSS selector).
Edit(Reply to @200_success):
You can use anyone of those. Just I prefer document.querySelectorAll since I think it is better a little.
document.getElementsByClassNamehas 31 letters, anddocument.querySelectorAllhas 25 letters.
document.querySelectorAlluses CSS to get DOM elements, butdocument.getElementsByClassNamedoes not.- IE 8+ supports
document.querySelectorAll(IE 8 only supports CSS2 selectors), butdocument.getElementsByClassNameis for IE 9+.
And you don't have to make an Array from the DOMNodeList using slice, since a DOMNodeList object is Array-like. i.e. you can use it as an Array using Array.prototype.forEach.call(DOMNodeList, callbackFunction).
window.addEventListener("load", _ => {
Array.prototype.forEach.call(document.querySelectorAll(".rep, .reputation, .reputation-score, .-flair"), element => {
element.style.display = "none";
});
});
add a comment |
Since you're using ES6, you could replace your slice function with Array.from like this (implementing Josephs changes too);
let hideRepz = function() {
repClasses.forEach(clazz =>
Array.from(document.querySelectorAll(`.${clazz}`))
.forEach(el => {
el.style.display = 'none';
})
);
}
4
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
3
@Bergi Other than the "it's there, so let's use it" argument, is there a concrete reason whyfor(..of..)is preferable?
– spender
Feb 16 '16 at 2:17
1
It's somewhere between "more concise, more elegant, more performant, less to type, easier to understand" - if there was an adjective like "pythonic" for JS, it would be that. The technical arguments are that it doesn't require intermediate arrays and that you canbreakfrom it; basicallyforEachis deprecated with ES6.
– Bergi
Feb 16 '16 at 13:44
add a comment |
Avoid using deprecated events
Mutation Events (DOMNodeInserted) is deprecated and you should use Mutation Observers instead.
Sample usage:
function processNewNodes(topNode) {
var nodes = topNode.querySelectorAll(selector);
// ...
}
var observer = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
Array.prototype.forEach.call(mutation.addedNodes, processNewNodes);
});
});
observer.observe(document, {
subtree: true,
childList: true
});
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f120034%2fyou-hate-h%25cc%25b6a%25cc%25b6t%25cc%25b6s%25cc%25b6-reputation-click-here-to-get-rid-of-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
It would be better to do this with a user style, e.g. using the Stylish extension, like this:
.rep, .reputation, .reputation-score {
visibility: hidden;
}
One advantage of user styles over scripts is that they're applied as soon as the page starts to load, so you won't see the rep counts flicker briefly while the page is loading. Also, user styles will automatically apply also to new dynamic content loaded e.g. via Ajax (such as new answers posted while you're viewing the page).
If you insist on using a user script, it's possibly to emulate user styles by using @run-at document-start and injecting a custom style element into the page early, like this:
// ==UserScript==
// @name Hide Stack Exchange reputation (demo)
// @namespace http://vyznev.net/
// @description A demonstration of using style injection to emulate user styles
// @author Ilmari Karonen
// @version 1.0
// @license Public domain
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.askubuntu.com/*
// @homepageURL http://codereview.stackexchange.com/a/120100
// @grant none
// @run-at document-start
// ==/UserScript==
var css =
".rep, .reputation, .reputation-score {n" +
" visibility: hidden;n" +
"}n";
var style = document.createElement('style');
style.textContent = css;
(document.head || document.documentElement).appendChild(style);
I use this method in my Stack Overflow Unofficial Patch (SOUP) user script (which combines a bunch of more or less minor interface bugfixes and improvements together) to let me efficiently apply both CSS-only and JS-based tweaks from a single user script.
One detail worth noting is that styles injected this way will generally end up being included before any actual site style sheets on the page, which means that they will be overridden by site CSS selectors of equal specificity. In some cases, you may need to use !important and/or various specificity hacks to make sure that your custom styles will take precedence.
13
If ES6 is available, best use template strings instead of concatenating.
– Joseph
Feb 16 '16 at 14:59
add a comment |
It would be better to do this with a user style, e.g. using the Stylish extension, like this:
.rep, .reputation, .reputation-score {
visibility: hidden;
}
One advantage of user styles over scripts is that they're applied as soon as the page starts to load, so you won't see the rep counts flicker briefly while the page is loading. Also, user styles will automatically apply also to new dynamic content loaded e.g. via Ajax (such as new answers posted while you're viewing the page).
If you insist on using a user script, it's possibly to emulate user styles by using @run-at document-start and injecting a custom style element into the page early, like this:
// ==UserScript==
// @name Hide Stack Exchange reputation (demo)
// @namespace http://vyznev.net/
// @description A demonstration of using style injection to emulate user styles
// @author Ilmari Karonen
// @version 1.0
// @license Public domain
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.askubuntu.com/*
// @homepageURL http://codereview.stackexchange.com/a/120100
// @grant none
// @run-at document-start
// ==/UserScript==
var css =
".rep, .reputation, .reputation-score {n" +
" visibility: hidden;n" +
"}n";
var style = document.createElement('style');
style.textContent = css;
(document.head || document.documentElement).appendChild(style);
I use this method in my Stack Overflow Unofficial Patch (SOUP) user script (which combines a bunch of more or less minor interface bugfixes and improvements together) to let me efficiently apply both CSS-only and JS-based tweaks from a single user script.
One detail worth noting is that styles injected this way will generally end up being included before any actual site style sheets on the page, which means that they will be overridden by site CSS selectors of equal specificity. In some cases, you may need to use !important and/or various specificity hacks to make sure that your custom styles will take precedence.
13
If ES6 is available, best use template strings instead of concatenating.
– Joseph
Feb 16 '16 at 14:59
add a comment |
It would be better to do this with a user style, e.g. using the Stylish extension, like this:
.rep, .reputation, .reputation-score {
visibility: hidden;
}
One advantage of user styles over scripts is that they're applied as soon as the page starts to load, so you won't see the rep counts flicker briefly while the page is loading. Also, user styles will automatically apply also to new dynamic content loaded e.g. via Ajax (such as new answers posted while you're viewing the page).
If you insist on using a user script, it's possibly to emulate user styles by using @run-at document-start and injecting a custom style element into the page early, like this:
// ==UserScript==
// @name Hide Stack Exchange reputation (demo)
// @namespace http://vyznev.net/
// @description A demonstration of using style injection to emulate user styles
// @author Ilmari Karonen
// @version 1.0
// @license Public domain
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.askubuntu.com/*
// @homepageURL http://codereview.stackexchange.com/a/120100
// @grant none
// @run-at document-start
// ==/UserScript==
var css =
".rep, .reputation, .reputation-score {n" +
" visibility: hidden;n" +
"}n";
var style = document.createElement('style');
style.textContent = css;
(document.head || document.documentElement).appendChild(style);
I use this method in my Stack Overflow Unofficial Patch (SOUP) user script (which combines a bunch of more or less minor interface bugfixes and improvements together) to let me efficiently apply both CSS-only and JS-based tweaks from a single user script.
One detail worth noting is that styles injected this way will generally end up being included before any actual site style sheets on the page, which means that they will be overridden by site CSS selectors of equal specificity. In some cases, you may need to use !important and/or various specificity hacks to make sure that your custom styles will take precedence.
It would be better to do this with a user style, e.g. using the Stylish extension, like this:
.rep, .reputation, .reputation-score {
visibility: hidden;
}
One advantage of user styles over scripts is that they're applied as soon as the page starts to load, so you won't see the rep counts flicker briefly while the page is loading. Also, user styles will automatically apply also to new dynamic content loaded e.g. via Ajax (such as new answers posted while you're viewing the page).
If you insist on using a user script, it's possibly to emulate user styles by using @run-at document-start and injecting a custom style element into the page early, like this:
// ==UserScript==
// @name Hide Stack Exchange reputation (demo)
// @namespace http://vyznev.net/
// @description A demonstration of using style injection to emulate user styles
// @author Ilmari Karonen
// @version 1.0
// @license Public domain
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.askubuntu.com/*
// @homepageURL http://codereview.stackexchange.com/a/120100
// @grant none
// @run-at document-start
// ==/UserScript==
var css =
".rep, .reputation, .reputation-score {n" +
" visibility: hidden;n" +
"}n";
var style = document.createElement('style');
style.textContent = css;
(document.head || document.documentElement).appendChild(style);
I use this method in my Stack Overflow Unofficial Patch (SOUP) user script (which combines a bunch of more or less minor interface bugfixes and improvements together) to let me efficiently apply both CSS-only and JS-based tweaks from a single user script.
One detail worth noting is that styles injected this way will generally end up being included before any actual site style sheets on the page, which means that they will be overridden by site CSS selectors of equal specificity. In some cases, you may need to use !important and/or various specificity hacks to make sure that your custom styles will take precedence.
edited May 23 '17 at 12:40
Community♦
1
1
answered Feb 16 '16 at 0:48
Ilmari Karonen
1,747915
1,747915
13
If ES6 is available, best use template strings instead of concatenating.
– Joseph
Feb 16 '16 at 14:59
add a comment |
13
If ES6 is available, best use template strings instead of concatenating.
– Joseph
Feb 16 '16 at 14:59
13
13
If ES6 is available, best use template strings instead of concatenating.
– Joseph
Feb 16 '16 at 14:59
If ES6 is available, best use template strings instead of concatenating.
– Joseph
Feb 16 '16 at 14:59
add a comment |
You could use querySelectorAll instead of getElementsByClassName. That way, you have a bit more flexibility in targeting elements. It also allows multiple selectors. That way, you don't have to loop twice.
Instead of .slice which uses an unnecessary array as host, try using Array.prototype.slice.call instead. Longer, but without that extra array.
Also, try using display:none as visibility just hides the element but maintain layout. This way, there's no awkward whitespace where the reputation was, making the layout all natural.
Seeing that you put ES6, we can use the handy dandy arrow functions as well.
'use strict';
const REPUTATION_ELEMENTS = '.rep, .reputation, .reputation-score';
function getElementArray(selector){
return Array.prototype.slice.call(document.querySelectorAll(selector));
}
document.addEventListener("DOMNodeInserted", event => {
getElementArray(REPUTATION_ELEMENTS).forEach( element => {
element.style.display = 'none';
});
});
6
Thedisplay:noneadvice is worth gold. One small thing: this doesn't run when loading the page by default. That's just a really minor thing. Also I recall hearing something aboutquerySelectorAllbeing slower than the more specialized calls, but I might be wrong. Thanks for the review :)
– Vogel612♦
Feb 15 '16 at 15:28
8
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
2
Another way to hide things:element.hidden = true. ciu, whatwg
– deltab
Feb 15 '16 at 17:54
1
@Vogel612 Yup, it's relatively slower than the older element selection APIs, but for a few elements it's probably negligible and more familiar because of jQuery. Speaking of jQuery, not sure if possible, but if the userscript can utilize the one that is already on the page, it can be as simple as$(selector).hide().
– Joseph
Feb 16 '16 at 1:24
@BergiforEachjust came out of instinct, especially with arrays. :D
– Joseph
Feb 16 '16 at 1:29
add a comment |
You could use querySelectorAll instead of getElementsByClassName. That way, you have a bit more flexibility in targeting elements. It also allows multiple selectors. That way, you don't have to loop twice.
Instead of .slice which uses an unnecessary array as host, try using Array.prototype.slice.call instead. Longer, but without that extra array.
Also, try using display:none as visibility just hides the element but maintain layout. This way, there's no awkward whitespace where the reputation was, making the layout all natural.
Seeing that you put ES6, we can use the handy dandy arrow functions as well.
'use strict';
const REPUTATION_ELEMENTS = '.rep, .reputation, .reputation-score';
function getElementArray(selector){
return Array.prototype.slice.call(document.querySelectorAll(selector));
}
document.addEventListener("DOMNodeInserted", event => {
getElementArray(REPUTATION_ELEMENTS).forEach( element => {
element.style.display = 'none';
});
});
6
Thedisplay:noneadvice is worth gold. One small thing: this doesn't run when loading the page by default. That's just a really minor thing. Also I recall hearing something aboutquerySelectorAllbeing slower than the more specialized calls, but I might be wrong. Thanks for the review :)
– Vogel612♦
Feb 15 '16 at 15:28
8
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
2
Another way to hide things:element.hidden = true. ciu, whatwg
– deltab
Feb 15 '16 at 17:54
1
@Vogel612 Yup, it's relatively slower than the older element selection APIs, but for a few elements it's probably negligible and more familiar because of jQuery. Speaking of jQuery, not sure if possible, but if the userscript can utilize the one that is already on the page, it can be as simple as$(selector).hide().
– Joseph
Feb 16 '16 at 1:24
@BergiforEachjust came out of instinct, especially with arrays. :D
– Joseph
Feb 16 '16 at 1:29
add a comment |
You could use querySelectorAll instead of getElementsByClassName. That way, you have a bit more flexibility in targeting elements. It also allows multiple selectors. That way, you don't have to loop twice.
Instead of .slice which uses an unnecessary array as host, try using Array.prototype.slice.call instead. Longer, but without that extra array.
Also, try using display:none as visibility just hides the element but maintain layout. This way, there's no awkward whitespace where the reputation was, making the layout all natural.
Seeing that you put ES6, we can use the handy dandy arrow functions as well.
'use strict';
const REPUTATION_ELEMENTS = '.rep, .reputation, .reputation-score';
function getElementArray(selector){
return Array.prototype.slice.call(document.querySelectorAll(selector));
}
document.addEventListener("DOMNodeInserted", event => {
getElementArray(REPUTATION_ELEMENTS).forEach( element => {
element.style.display = 'none';
});
});
You could use querySelectorAll instead of getElementsByClassName. That way, you have a bit more flexibility in targeting elements. It also allows multiple selectors. That way, you don't have to loop twice.
Instead of .slice which uses an unnecessary array as host, try using Array.prototype.slice.call instead. Longer, but without that extra array.
Also, try using display:none as visibility just hides the element but maintain layout. This way, there's no awkward whitespace where the reputation was, making the layout all natural.
Seeing that you put ES6, we can use the handy dandy arrow functions as well.
'use strict';
const REPUTATION_ELEMENTS = '.rep, .reputation, .reputation-score';
function getElementArray(selector){
return Array.prototype.slice.call(document.querySelectorAll(selector));
}
document.addEventListener("DOMNodeInserted", event => {
getElementArray(REPUTATION_ELEMENTS).forEach( element => {
element.style.display = 'none';
});
});
answered Feb 15 '16 at 14:15
Joseph
22.5k21835
22.5k21835
6
Thedisplay:noneadvice is worth gold. One small thing: this doesn't run when loading the page by default. That's just a really minor thing. Also I recall hearing something aboutquerySelectorAllbeing slower than the more specialized calls, but I might be wrong. Thanks for the review :)
– Vogel612♦
Feb 15 '16 at 15:28
8
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
2
Another way to hide things:element.hidden = true. ciu, whatwg
– deltab
Feb 15 '16 at 17:54
1
@Vogel612 Yup, it's relatively slower than the older element selection APIs, but for a few elements it's probably negligible and more familiar because of jQuery. Speaking of jQuery, not sure if possible, but if the userscript can utilize the one that is already on the page, it can be as simple as$(selector).hide().
– Joseph
Feb 16 '16 at 1:24
@BergiforEachjust came out of instinct, especially with arrays. :D
– Joseph
Feb 16 '16 at 1:29
add a comment |
6
Thedisplay:noneadvice is worth gold. One small thing: this doesn't run when loading the page by default. That's just a really minor thing. Also I recall hearing something aboutquerySelectorAllbeing slower than the more specialized calls, but I might be wrong. Thanks for the review :)
– Vogel612♦
Feb 15 '16 at 15:28
8
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
2
Another way to hide things:element.hidden = true. ciu, whatwg
– deltab
Feb 15 '16 at 17:54
1
@Vogel612 Yup, it's relatively slower than the older element selection APIs, but for a few elements it's probably negligible and more familiar because of jQuery. Speaking of jQuery, not sure if possible, but if the userscript can utilize the one that is already on the page, it can be as simple as$(selector).hide().
– Joseph
Feb 16 '16 at 1:24
@BergiforEachjust came out of instinct, especially with arrays. :D
– Joseph
Feb 16 '16 at 1:29
6
6
The
display:noneadvice is worth gold. One small thing: this doesn't run when loading the page by default. That's just a really minor thing. Also I recall hearing something about querySelectorAll being slower than the more specialized calls, but I might be wrong. Thanks for the review :)– Vogel612♦
Feb 15 '16 at 15:28
The
display:noneadvice is worth gold. One small thing: this doesn't run when loading the page by default. That's just a really minor thing. Also I recall hearing something about querySelectorAll being slower than the more specialized calls, but I might be wrong. Thanks for the review :)– Vogel612♦
Feb 15 '16 at 15:28
8
8
If you're using ES6, you should rather use a
for of loop instead of forEach.– Bergi
Feb 15 '16 at 16:17
If you're using ES6, you should rather use a
for of loop instead of forEach.– Bergi
Feb 15 '16 at 16:17
2
2
Another way to hide things:
element.hidden = true. ciu, whatwg– deltab
Feb 15 '16 at 17:54
Another way to hide things:
element.hidden = true. ciu, whatwg– deltab
Feb 15 '16 at 17:54
1
1
@Vogel612 Yup, it's relatively slower than the older element selection APIs, but for a few elements it's probably negligible and more familiar because of jQuery. Speaking of jQuery, not sure if possible, but if the userscript can utilize the one that is already on the page, it can be as simple as
$(selector).hide().– Joseph
Feb 16 '16 at 1:24
@Vogel612 Yup, it's relatively slower than the older element selection APIs, but for a few elements it's probably negligible and more familiar because of jQuery. Speaking of jQuery, not sure if possible, but if the userscript can utilize the one that is already on the page, it can be as simple as
$(selector).hide().– Joseph
Feb 16 '16 at 1:24
@Bergi
forEach just came out of instinct, especially with arrays. :D– Joseph
Feb 16 '16 at 1:29
@Bergi
forEach just came out of instinct, especially with arrays. :D– Joseph
Feb 16 '16 at 1:29
add a comment |
Update url
UserScripts have the magical ability to update themselves if you provide a link to a raw version of your script as a UserScript header:
Note: You actually have to increase the version, or it won't update.
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @downloadURL
// @updateURL
Method
I'm not particularly a fan of your method.
Checking for DOM updates before scanning through everything all over again.
It would make more sense to simply inject a stylesheet to override SE's stylesheets.
Much more labour performant.
ES6 features
I like the use of ES6 in your code, but you haven't used it to its full potential:
let slice = function(collection) {
return .slice.call(collection);
}
Instead of using the old function(collection){} way, you can use (collection) => ():
let slice = (collection) => .slice.call(collection)
The same thing applies to the function in your main loop.
Slicing and Dicing
Currently, you only use slice with your element selection.
You should combine the two!
slice(document.getElementsByClassName(clazz))
let fetchElements(clazz) => .slice.call(document.getElementsByClassName(clazz))
Or hey, let's take it a step further and do some concatenation magic:
let fetchElements = (clazzArrey) =>
clazzArrey.map((clazz) => .slice.call(document.getElementsByClassName(clazz)))
Alternatively, you can use string concatenation to make one huge selector string and use querySelectorAll as Joseph described.
I find that querySelector* can have worse performance, but its always been edge cases that trigger that for me.
Future gazing
This isn't usually a review point I add, however, I think you could add support for other fields, and make a handy dandy dialog box to choose which you want to hide. That'd be a StackApps worthy creation in my eyes.
add a comment |
Update url
UserScripts have the magical ability to update themselves if you provide a link to a raw version of your script as a UserScript header:
Note: You actually have to increase the version, or it won't update.
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @downloadURL
// @updateURL
Method
I'm not particularly a fan of your method.
Checking for DOM updates before scanning through everything all over again.
It would make more sense to simply inject a stylesheet to override SE's stylesheets.
Much more labour performant.
ES6 features
I like the use of ES6 in your code, but you haven't used it to its full potential:
let slice = function(collection) {
return .slice.call(collection);
}
Instead of using the old function(collection){} way, you can use (collection) => ():
let slice = (collection) => .slice.call(collection)
The same thing applies to the function in your main loop.
Slicing and Dicing
Currently, you only use slice with your element selection.
You should combine the two!
slice(document.getElementsByClassName(clazz))
let fetchElements(clazz) => .slice.call(document.getElementsByClassName(clazz))
Or hey, let's take it a step further and do some concatenation magic:
let fetchElements = (clazzArrey) =>
clazzArrey.map((clazz) => .slice.call(document.getElementsByClassName(clazz)))
Alternatively, you can use string concatenation to make one huge selector string and use querySelectorAll as Joseph described.
I find that querySelector* can have worse performance, but its always been edge cases that trigger that for me.
Future gazing
This isn't usually a review point I add, however, I think you could add support for other fields, and make a handy dandy dialog box to choose which you want to hide. That'd be a StackApps worthy creation in my eyes.
add a comment |
Update url
UserScripts have the magical ability to update themselves if you provide a link to a raw version of your script as a UserScript header:
Note: You actually have to increase the version, or it won't update.
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @downloadURL
// @updateURL
Method
I'm not particularly a fan of your method.
Checking for DOM updates before scanning through everything all over again.
It would make more sense to simply inject a stylesheet to override SE's stylesheets.
Much more labour performant.
ES6 features
I like the use of ES6 in your code, but you haven't used it to its full potential:
let slice = function(collection) {
return .slice.call(collection);
}
Instead of using the old function(collection){} way, you can use (collection) => ():
let slice = (collection) => .slice.call(collection)
The same thing applies to the function in your main loop.
Slicing and Dicing
Currently, you only use slice with your element selection.
You should combine the two!
slice(document.getElementsByClassName(clazz))
let fetchElements(clazz) => .slice.call(document.getElementsByClassName(clazz))
Or hey, let's take it a step further and do some concatenation magic:
let fetchElements = (clazzArrey) =>
clazzArrey.map((clazz) => .slice.call(document.getElementsByClassName(clazz)))
Alternatively, you can use string concatenation to make one huge selector string and use querySelectorAll as Joseph described.
I find that querySelector* can have worse performance, but its always been edge cases that trigger that for me.
Future gazing
This isn't usually a review point I add, however, I think you could add support for other fields, and make a handy dandy dialog box to choose which you want to hide. That'd be a StackApps worthy creation in my eyes.
Update url
UserScripts have the magical ability to update themselves if you provide a link to a raw version of your script as a UserScript header:
Note: You actually have to increase the version, or it won't update.
// ==UserScript==
// @name Reputation Hider
// @namespace http://gihub.com/Vogel612/ReputationHider
// @version 0.1
// @downloadURL
// @updateURL
Method
I'm not particularly a fan of your method.
Checking for DOM updates before scanning through everything all over again.
It would make more sense to simply inject a stylesheet to override SE's stylesheets.
Much more labour performant.
ES6 features
I like the use of ES6 in your code, but you haven't used it to its full potential:
let slice = function(collection) {
return .slice.call(collection);
}
Instead of using the old function(collection){} way, you can use (collection) => ():
let slice = (collection) => .slice.call(collection)
The same thing applies to the function in your main loop.
Slicing and Dicing
Currently, you only use slice with your element selection.
You should combine the two!
slice(document.getElementsByClassName(clazz))
let fetchElements(clazz) => .slice.call(document.getElementsByClassName(clazz))
Or hey, let's take it a step further and do some concatenation magic:
let fetchElements = (clazzArrey) =>
clazzArrey.map((clazz) => .slice.call(document.getElementsByClassName(clazz)))
Alternatively, you can use string concatenation to make one huge selector string and use querySelectorAll as Joseph described.
I find that querySelector* can have worse performance, but its always been edge cases that trigger that for me.
Future gazing
This isn't usually a review point I add, however, I think you could add support for other fields, and make a handy dandy dialog box to choose which you want to hide. That'd be a StackApps worthy creation in my eyes.
edited 42 mins ago
answered Feb 15 '16 at 22:39
Quill
10.4k53287
10.4k53287
add a comment |
add a comment |
Instead of document.getElementsByClassName, you can use document.querySelectorAll(CSS selector).
Edit(Reply to @200_success):
You can use anyone of those. Just I prefer document.querySelectorAll since I think it is better a little.
document.getElementsByClassNamehas 31 letters, anddocument.querySelectorAllhas 25 letters.
document.querySelectorAlluses CSS to get DOM elements, butdocument.getElementsByClassNamedoes not.- IE 8+ supports
document.querySelectorAll(IE 8 only supports CSS2 selectors), butdocument.getElementsByClassNameis for IE 9+.
And you don't have to make an Array from the DOMNodeList using slice, since a DOMNodeList object is Array-like. i.e. you can use it as an Array using Array.prototype.forEach.call(DOMNodeList, callbackFunction).
window.addEventListener("load", _ => {
Array.prototype.forEach.call(document.querySelectorAll(".rep, .reputation, .reputation-score, .-flair"), element => {
element.style.display = "none";
});
});
add a comment |
Instead of document.getElementsByClassName, you can use document.querySelectorAll(CSS selector).
Edit(Reply to @200_success):
You can use anyone of those. Just I prefer document.querySelectorAll since I think it is better a little.
document.getElementsByClassNamehas 31 letters, anddocument.querySelectorAllhas 25 letters.
document.querySelectorAlluses CSS to get DOM elements, butdocument.getElementsByClassNamedoes not.- IE 8+ supports
document.querySelectorAll(IE 8 only supports CSS2 selectors), butdocument.getElementsByClassNameis for IE 9+.
And you don't have to make an Array from the DOMNodeList using slice, since a DOMNodeList object is Array-like. i.e. you can use it as an Array using Array.prototype.forEach.call(DOMNodeList, callbackFunction).
window.addEventListener("load", _ => {
Array.prototype.forEach.call(document.querySelectorAll(".rep, .reputation, .reputation-score, .-flair"), element => {
element.style.display = "none";
});
});
add a comment |
Instead of document.getElementsByClassName, you can use document.querySelectorAll(CSS selector).
Edit(Reply to @200_success):
You can use anyone of those. Just I prefer document.querySelectorAll since I think it is better a little.
document.getElementsByClassNamehas 31 letters, anddocument.querySelectorAllhas 25 letters.
document.querySelectorAlluses CSS to get DOM elements, butdocument.getElementsByClassNamedoes not.- IE 8+ supports
document.querySelectorAll(IE 8 only supports CSS2 selectors), butdocument.getElementsByClassNameis for IE 9+.
And you don't have to make an Array from the DOMNodeList using slice, since a DOMNodeList object is Array-like. i.e. you can use it as an Array using Array.prototype.forEach.call(DOMNodeList, callbackFunction).
window.addEventListener("load", _ => {
Array.prototype.forEach.call(document.querySelectorAll(".rep, .reputation, .reputation-score, .-flair"), element => {
element.style.display = "none";
});
});
Instead of document.getElementsByClassName, you can use document.querySelectorAll(CSS selector).
Edit(Reply to @200_success):
You can use anyone of those. Just I prefer document.querySelectorAll since I think it is better a little.
document.getElementsByClassNamehas 31 letters, anddocument.querySelectorAllhas 25 letters.
document.querySelectorAlluses CSS to get DOM elements, butdocument.getElementsByClassNamedoes not.- IE 8+ supports
document.querySelectorAll(IE 8 only supports CSS2 selectors), butdocument.getElementsByClassNameis for IE 9+.
And you don't have to make an Array from the DOMNodeList using slice, since a DOMNodeList object is Array-like. i.e. you can use it as an Array using Array.prototype.forEach.call(DOMNodeList, callbackFunction).
window.addEventListener("load", _ => {
Array.prototype.forEach.call(document.querySelectorAll(".rep, .reputation, .reputation-score, .-flair"), element => {
element.style.display = "none";
});
});
edited Sep 25 '16 at 0:13
answered Feb 15 '16 at 20:03
K._
1614
1614
add a comment |
add a comment |
Since you're using ES6, you could replace your slice function with Array.from like this (implementing Josephs changes too);
let hideRepz = function() {
repClasses.forEach(clazz =>
Array.from(document.querySelectorAll(`.${clazz}`))
.forEach(el => {
el.style.display = 'none';
})
);
}
4
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
3
@Bergi Other than the "it's there, so let's use it" argument, is there a concrete reason whyfor(..of..)is preferable?
– spender
Feb 16 '16 at 2:17
1
It's somewhere between "more concise, more elegant, more performant, less to type, easier to understand" - if there was an adjective like "pythonic" for JS, it would be that. The technical arguments are that it doesn't require intermediate arrays and that you canbreakfrom it; basicallyforEachis deprecated with ES6.
– Bergi
Feb 16 '16 at 13:44
add a comment |
Since you're using ES6, you could replace your slice function with Array.from like this (implementing Josephs changes too);
let hideRepz = function() {
repClasses.forEach(clazz =>
Array.from(document.querySelectorAll(`.${clazz}`))
.forEach(el => {
el.style.display = 'none';
})
);
}
4
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
3
@Bergi Other than the "it's there, so let's use it" argument, is there a concrete reason whyfor(..of..)is preferable?
– spender
Feb 16 '16 at 2:17
1
It's somewhere between "more concise, more elegant, more performant, less to type, easier to understand" - if there was an adjective like "pythonic" for JS, it would be that. The technical arguments are that it doesn't require intermediate arrays and that you canbreakfrom it; basicallyforEachis deprecated with ES6.
– Bergi
Feb 16 '16 at 13:44
add a comment |
Since you're using ES6, you could replace your slice function with Array.from like this (implementing Josephs changes too);
let hideRepz = function() {
repClasses.forEach(clazz =>
Array.from(document.querySelectorAll(`.${clazz}`))
.forEach(el => {
el.style.display = 'none';
})
);
}
Since you're using ES6, you could replace your slice function with Array.from like this (implementing Josephs changes too);
let hideRepz = function() {
repClasses.forEach(clazz =>
Array.from(document.querySelectorAll(`.${clazz}`))
.forEach(el => {
el.style.display = 'none';
})
);
}
answered Feb 15 '16 at 15:57
Jivings
2,269917
2,269917
4
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
3
@Bergi Other than the "it's there, so let's use it" argument, is there a concrete reason whyfor(..of..)is preferable?
– spender
Feb 16 '16 at 2:17
1
It's somewhere between "more concise, more elegant, more performant, less to type, easier to understand" - if there was an adjective like "pythonic" for JS, it would be that. The technical arguments are that it doesn't require intermediate arrays and that you canbreakfrom it; basicallyforEachis deprecated with ES6.
– Bergi
Feb 16 '16 at 13:44
add a comment |
4
If you're using ES6, you should rather use afor ofloop instead offorEach.
– Bergi
Feb 15 '16 at 16:17
3
@Bergi Other than the "it's there, so let's use it" argument, is there a concrete reason whyfor(..of..)is preferable?
– spender
Feb 16 '16 at 2:17
1
It's somewhere between "more concise, more elegant, more performant, less to type, easier to understand" - if there was an adjective like "pythonic" for JS, it would be that. The technical arguments are that it doesn't require intermediate arrays and that you canbreakfrom it; basicallyforEachis deprecated with ES6.
– Bergi
Feb 16 '16 at 13:44
4
4
If you're using ES6, you should rather use a
for of loop instead of forEach.– Bergi
Feb 15 '16 at 16:17
If you're using ES6, you should rather use a
for of loop instead of forEach.– Bergi
Feb 15 '16 at 16:17
3
3
@Bergi Other than the "it's there, so let's use it" argument, is there a concrete reason why
for(..of..) is preferable?– spender
Feb 16 '16 at 2:17
@Bergi Other than the "it's there, so let's use it" argument, is there a concrete reason why
for(..of..) is preferable?– spender
Feb 16 '16 at 2:17
1
1
It's somewhere between "more concise, more elegant, more performant, less to type, easier to understand" - if there was an adjective like "pythonic" for JS, it would be that. The technical arguments are that it doesn't require intermediate arrays and that you can
break from it; basically forEach is deprecated with ES6.– Bergi
Feb 16 '16 at 13:44
It's somewhere between "more concise, more elegant, more performant, less to type, easier to understand" - if there was an adjective like "pythonic" for JS, it would be that. The technical arguments are that it doesn't require intermediate arrays and that you can
break from it; basically forEach is deprecated with ES6.– Bergi
Feb 16 '16 at 13:44
add a comment |
Avoid using deprecated events
Mutation Events (DOMNodeInserted) is deprecated and you should use Mutation Observers instead.
Sample usage:
function processNewNodes(topNode) {
var nodes = topNode.querySelectorAll(selector);
// ...
}
var observer = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
Array.prototype.forEach.call(mutation.addedNodes, processNewNodes);
});
});
observer.observe(document, {
subtree: true,
childList: true
});
add a comment |
Avoid using deprecated events
Mutation Events (DOMNodeInserted) is deprecated and you should use Mutation Observers instead.
Sample usage:
function processNewNodes(topNode) {
var nodes = topNode.querySelectorAll(selector);
// ...
}
var observer = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
Array.prototype.forEach.call(mutation.addedNodes, processNewNodes);
});
});
observer.observe(document, {
subtree: true,
childList: true
});
add a comment |
Avoid using deprecated events
Mutation Events (DOMNodeInserted) is deprecated and you should use Mutation Observers instead.
Sample usage:
function processNewNodes(topNode) {
var nodes = topNode.querySelectorAll(selector);
// ...
}
var observer = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
Array.prototype.forEach.call(mutation.addedNodes, processNewNodes);
});
});
observer.observe(document, {
subtree: true,
childList: true
});
Avoid using deprecated events
Mutation Events (DOMNodeInserted) is deprecated and you should use Mutation Observers instead.
Sample usage:
function processNewNodes(topNode) {
var nodes = topNode.querySelectorAll(selector);
// ...
}
var observer = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
Array.prototype.forEach.call(mutation.addedNodes, processNewNodes);
});
});
observer.observe(document, {
subtree: true,
childList: true
});
answered Feb 16 '16 at 23:53
Bob
39915
39915
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f120034%2fyou-hate-h%25cc%25b6a%25cc%25b6t%25cc%25b6s%25cc%25b6-reputation-click-here-to-get-rid-of-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
55
Welcome to Stack Exchange, the network where everything's made up and the points don't matter.
– Josay
Feb 15 '16 at 15:59
19
Why are you using JS for this? Wouldn't custom CSS solve this better (and much easier)?
– Bergi
Feb 15 '16 at 16:18
7
You could do the same from a userscript actually. Just
document.head.appendChild(document.createElement("style")).textContent = ".rep, .reputation, .reputation-scope { visibility: hidden; }";– Bergi
Feb 15 '16 at 16:44
5
Will you post this on StackApps?
– A.L
Feb 16 '16 at 12:08
1
@A.L. I didn't intend to originally, but now I am considering. I would add some more functionality though before doing that. Feel free to post yourself, even though it's 3 lines of CSS for that matter
– Vogel612♦
Feb 16 '16 at 12:10