Last active
April 9, 2016 18:10
-
-
Save RAnders00/4d2c7c739f9ab0f8049c8ab962fca565 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Revert Votes | |
| // @namespace everywhere | |
| // @include https://stackoverflow.com* | |
| // @include http://stackoverflow.com* | |
| // @include https://meta.stackoverflow.com* | |
| // @include http://meta.stackoverflow.com* | |
| // @version 1 | |
| // @grant none | |
| // ==/UserScript== | |
| // So you can tell the Vote Count section is clickable - OCD ;) | |
| var style = $('<style>').text('.vote-count-post { cursor: pointer !important }') | |
| $('head').append(style) | |
| $('.vote-count-post').each(function() { | |
| $(this).attr('data-clicks', '0') // Set number of clicks to 0 | |
| }) | |
| $(document).on('click', '.vote-count-post', function() { | |
| clicks = parseInt($(this).attr('data-clicks')) // Get number of clicks | |
| clicks++ // Increase by 1 | |
| $(this).attr('data-clicks', String(clicks)) // Write new number | |
| // If click is 2nd click (vote counts need to be hidden) | |
| if (clicks == 2) { | |
| title = $(this).attr('title') // In the format "XXX up / XXX down" | |
| upvotes = parseInt(title.match(/^\d+/)[0]) // Number of Upvotes | |
| downvotes = parseInt(title.match(/\d+(?= down$)/)[0]) // Number of Downvotes | |
| score = upvotes - downvotes // Score of post | |
| $(this).text(score) // Replace the vote counts with the score | |
| $(this).attr('data-clicks', '0') // Reset number of clicks | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment