You hate h̶a̶t̶s̶ reputation? Click here to get rid of it












70














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?










share|improve this question




















  • 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
















70














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?










share|improve this question




















  • 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














70












70








70


10





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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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. 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














  • 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








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










6 Answers
6






active

oldest

votes


















46














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.






share|improve this answer



















  • 13




    If ES6 is available, best use template strings instead of concatenating.
    – Joseph
    Feb 16 '16 at 14:59



















28














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';
});
});





share|improve this answer

















  • 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






  • 8




    If you're using ES6, you should rather use a for of loop instead of forEach.
    – 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












  • @Bergi forEach just came out of instinct, especially with arrays. :D
    – Joseph
    Feb 16 '16 at 1:29



















16














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.






share|improve this answer































    6














    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.





    1. document.getElementsByClassName has 31 letters, and document.querySelectorAll has 25 letters.


    2. document.querySelectorAll uses CSS to get DOM elements, but document.getElementsByClassName does not.

    3. IE 8+ supports document.querySelectorAll(IE 8 only supports CSS2 selectors), but document.getElementsByClassName is 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";
    });
    });





    share|improve this answer































      5














      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';
      })
      );
      }





      share|improve this answer

















      • 4




        If you're using ES6, you should rather use a for of loop instead of forEach.
        – 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 why for(..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 can break from it; basically forEach is deprecated with ES6.
        – Bergi
        Feb 16 '16 at 13:44





















      4














      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
      });





      share|improve this answer





















        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
        });


        }
        });














        draft saved

        draft discarded


















        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









        46














        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.






        share|improve this answer



















        • 13




          If ES6 is available, best use template strings instead of concatenating.
          – Joseph
          Feb 16 '16 at 14:59
















        46














        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.






        share|improve this answer



















        • 13




          If ES6 is available, best use template strings instead of concatenating.
          – Joseph
          Feb 16 '16 at 14:59














        46












        46








        46






        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        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














        • 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













        28














        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';
        });
        });





        share|improve this answer

















        • 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






        • 8




          If you're using ES6, you should rather use a for of loop instead of forEach.
          – 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












        • @Bergi forEach just came out of instinct, especially with arrays. :D
          – Joseph
          Feb 16 '16 at 1:29
















        28














        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';
        });
        });





        share|improve this answer

















        • 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






        • 8




          If you're using ES6, you should rather use a for of loop instead of forEach.
          – 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












        • @Bergi forEach just came out of instinct, especially with arrays. :D
          – Joseph
          Feb 16 '16 at 1:29














        28












        28








        28






        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';
        });
        });





        share|improve this answer












        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';
        });
        });






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 15 '16 at 14:15









        Joseph

        22.5k21835




        22.5k21835








        • 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






        • 8




          If you're using ES6, you should rather use a for of loop instead of forEach.
          – 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












        • @Bergi forEach just came out of instinct, especially with arrays. :D
          – Joseph
          Feb 16 '16 at 1:29














        • 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






        • 8




          If you're using ES6, you should rather use a for of loop instead of forEach.
          – 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












        • @Bergi forEach just 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











        16














        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.






        share|improve this answer




























          16














          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.






          share|improve this answer


























            16












            16








            16






            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.






            share|improve this answer














            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 42 mins ago

























            answered Feb 15 '16 at 22:39









            Quill

            10.4k53287




            10.4k53287























                6














                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.





                1. document.getElementsByClassName has 31 letters, and document.querySelectorAll has 25 letters.


                2. document.querySelectorAll uses CSS to get DOM elements, but document.getElementsByClassName does not.

                3. IE 8+ supports document.querySelectorAll(IE 8 only supports CSS2 selectors), but document.getElementsByClassName is 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";
                });
                });





                share|improve this answer




























                  6














                  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.





                  1. document.getElementsByClassName has 31 letters, and document.querySelectorAll has 25 letters.


                  2. document.querySelectorAll uses CSS to get DOM elements, but document.getElementsByClassName does not.

                  3. IE 8+ supports document.querySelectorAll(IE 8 only supports CSS2 selectors), but document.getElementsByClassName is 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";
                  });
                  });





                  share|improve this answer


























                    6












                    6








                    6






                    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.





                    1. document.getElementsByClassName has 31 letters, and document.querySelectorAll has 25 letters.


                    2. document.querySelectorAll uses CSS to get DOM elements, but document.getElementsByClassName does not.

                    3. IE 8+ supports document.querySelectorAll(IE 8 only supports CSS2 selectors), but document.getElementsByClassName is 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";
                    });
                    });





                    share|improve this answer














                    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.





                    1. document.getElementsByClassName has 31 letters, and document.querySelectorAll has 25 letters.


                    2. document.querySelectorAll uses CSS to get DOM elements, but document.getElementsByClassName does not.

                    3. IE 8+ supports document.querySelectorAll(IE 8 only supports CSS2 selectors), but document.getElementsByClassName is 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";
                    });
                    });






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Sep 25 '16 at 0:13

























                    answered Feb 15 '16 at 20:03









                    K._

                    1614




                    1614























                        5














                        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';
                        })
                        );
                        }





                        share|improve this answer

















                        • 4




                          If you're using ES6, you should rather use a for of loop instead of forEach.
                          – 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 why for(..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 can break from it; basically forEach is deprecated with ES6.
                          – Bergi
                          Feb 16 '16 at 13:44


















                        5














                        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';
                        })
                        );
                        }





                        share|improve this answer

















                        • 4




                          If you're using ES6, you should rather use a for of loop instead of forEach.
                          – 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 why for(..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 can break from it; basically forEach is deprecated with ES6.
                          – Bergi
                          Feb 16 '16 at 13:44
















                        5












                        5








                        5






                        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';
                        })
                        );
                        }





                        share|improve this answer












                        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';
                        })
                        );
                        }






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Feb 15 '16 at 15:57









                        Jivings

                        2,269917




                        2,269917








                        • 4




                          If you're using ES6, you should rather use a for of loop instead of forEach.
                          – 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 why for(..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 can break from it; basically forEach is deprecated with ES6.
                          – Bergi
                          Feb 16 '16 at 13:44
















                        • 4




                          If you're using ES6, you should rather use a for of loop instead of forEach.
                          – 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 why for(..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 can break from it; basically forEach is 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













                        4














                        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
                        });





                        share|improve this answer


























                          4














                          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
                          });





                          share|improve this answer
























                            4












                            4








                            4






                            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
                            });





                            share|improve this answer












                            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
                            });






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 16 '16 at 23:53









                            Bob

                            39915




                            39915






























                                draft saved

                                draft discarded




















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                Morgemoulin

                                Scott Moir

                                Souastre