Advertisement
Guest User

Improve Stack Overflow

a guest
Mar 22nd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Improve Stack Overflow
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.0
  5. // @description  Helps Stack Overflow to be a more enjoyable website to use.
  6. // @author       Blue Cow
  7. // @match        https://stackoverflow.com/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. var USER_ID = 100;
  12.  
  13. function hide_annoying_page_elements() {
  14.     'use strict';
  15.  
  16.     // Hide the area about developer jobs.
  17.     $("#nav-jobs").hide();
  18.     // Hide the button for the review queues.
  19.     $(".js-review-button").hide();
  20.     // Modify the sidebar to behave better.
  21.     hide_sidebar_distractions();
  22.     // When the sidebar changes, run its mutator again.
  23.     var mo = new MutationObserver(hide_sidebar_distractions);
  24.     $("#sidebar").each(function() { mo.observe(this, {childList: true, subtree: true}); });
  25. }
  26.  
  27. function hide_sidebar_distractions() {
  28.     'use strict';
  29.  
  30.     // Hide everything except the Ask Question button, statistics about the question, and linked questions.
  31.     $("#sidebar > :not(.aside-cta,.question-stats,.sidebar-linked)").hide();
  32.  
  33. }
  34.  
  35. function prevent_reputation_loss() {
  36.     'use strict';
  37.  
  38.     // Prevent loosing reputation from downvoting.
  39.     $(".vote-down-off").hide();
  40.     // Prevent loosing reputation from making bounties.
  41.     $(".bounty-link").hide();
  42. }
  43.  
  44. function block_broken_elements() {
  45.     'use strict';
  46.  
  47.     // Block all imgur images since the proxy interferes.
  48.     $("img[src*='i.stack.imgur.com']").hide();
  49.     $("a[href*='i.stack.imgur.com']").hide();
  50. }
  51.  
  52. function help_review_tag(tag_name) {
  53.     'use strict';
  54.  
  55.     var question_with_tag = $(`.post-taglist a[href='/questions/tagged/${tag_name}']`).length > 0;
  56.     // Only help to review tags of tag_name.
  57.     if (question_with_tag) {
  58.         var pending_close_or_reopen = $(".existing-flag-count").length > 0;
  59.         // Push through close or reopen votes if possible.
  60.         if (pending_close_or_reopen) {
  61.             $(".close-question-link:not([title^='You voted to '])").click();
  62.         }
  63.         var not_needed = pending_close_or_reopen || $("[title^='vote to reopen']").length > 0;
  64.         var probably_duplicate = $("span.comment-copy:contains(Possible duplicate of)").length > 0;
  65.         probably_duplicate = probably_duplicate || $(".question-originals-of-duplicate").length > 0;
  66.         var question_by_me = $(`.question .user-details a[href^='/users/${USER_ID}/']`).length > 0;
  67.         // Promote questions that have no negative signs if they are not my own.
  68.         if ((!not_needed || probably_duplicate) && !question_by_me) {
  69.             $(".question a.vote-up-off:not(.vote-up-on)").click();
  70.         }
  71.         var has_accepted_answer = $(".vote-accepted-on").length > 0;
  72.         var answer_by_me = $(`.accepted-answer .user-details a[href^='/users/${USER_ID}/']`).length > 0;
  73.         // Promote answers that appear to be correct if they are not my own.
  74.         if (has_accepted_answer && !answer_by_me) {
  75.             $(".accepted-answer a.vote-up-off:not(.vote-up-on)").click();
  76.         }
  77.     }
  78. }
  79.  
  80. function change_background_colors(shift) {
  81.     'use strict';
  82.  
  83.     var white = 0xFF;
  84.     var interesting = $(".tagged-interesting");
  85.     var old_color = interesting.css("background-color").match(/^rgb\((\d+), (\d+), (\d+)\)$/).slice(1).map(x => parseInt(x));
  86.     var new_color = "#" + old_color.map(x => (white - (white - x) * shift).toString(16).padStart(2, "0")).join("");
  87.     interesting.css({"background-color": new_color});
  88. }
  89.  
  90. (function() {
  91.     'use strict';
  92.  
  93.     hide_annoying_page_elements();
  94.     prevent_reputation_loss();
  95.     block_broken_elements();
  96.     setTimeout(function() { change_background_colors(3); }, 500);
  97.     setTimeout(function() { help_review_tag("python-3.x"); }, 1000);
  98. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement