Guest User

Discordomet v2

a guest
Apr 14th, 2016
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.86 KB | None | 0 0
  1. // ==UserScript==
  2. // @name          Discordomet v2
  3. // @namespace     http://tabun.everypony.ru
  4. // @description   ДИСКОРДОМЕТ ПЫЩЩЬ ПЫЩЩЬ ПОПЯЧСА ОЛОЛО
  5. // @include       http://tabun.everypony.ru/blog/*
  6. // @require       http://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js
  7. // ==/UserScript==
  8.  
  9. var mode = "single";
  10.  
  11. function switchMode()
  12. {
  13.     if(mode == "single")
  14.     {
  15.         mode = "all";
  16.         $("#discordModeBtn").text("A");
  17.     }
  18.     else
  19.     {
  20.         mode = "single";
  21.         $("#discordModeBtn").text("S");
  22.     }
  23. }
  24.  
  25. function collectVoteFunctionPairs(onlyOne)
  26. {
  27.     var voteFunctionPairs = [];
  28.     var arrowContainers = $(".vote");
  29.    
  30.     var inacceptableClasses = [ "voted", "guest", "vote-expired" ];
  31.    
  32.     for(var i = 0; i < arrowContainers.length; i++)
  33.     {
  34.         var votable = true;
  35.        
  36.         for(var j = 0; j < inacceptableClasses.length; j++)
  37.         {
  38.             if($(arrowContainers[i]).hasClass(inacceptableClasses[j]))
  39.             {
  40.                 votable = false;
  41.                 break;
  42.             }
  43.         }
  44.        
  45.         if(votable)
  46.         {
  47.             voteFunctionPairs.push({
  48.                 "voteUpFunc" : new Function($(arrowContainers[i]).find(".vote-up").attr("onclick")),
  49.                 "voteDownFunc" : new Function($(arrowContainers[i]).find(".vote-down").attr("onclick"))
  50.             });
  51.            
  52.             if(onlyOne)
  53.             {
  54.                 break;
  55.             }
  56.         }
  57.     }
  58.    
  59.     return voteFunctionPairs;
  60. }
  61.  
  62. function vote(voteMode)
  63. {
  64.     var voteFunctionPairs = collectVoteFunctionPairs(mode == "single");
  65.    
  66.     if(voteFunctionPairs.length == 0)
  67.     {
  68.         alert("There's no work for Discord.");
  69.     }
  70.    
  71.     for(var i = 0; i < voteFunctionPairs.length; i++)
  72.     {
  73.         switch(voteMode)
  74.         {
  75.             case 1:
  76.                 voteFunctionPairs[i]["voteUpFunc"]();
  77.                 break;
  78.                
  79.             case 2:
  80.                 voteFunctionPairs[i]["voteDownFunc"]();
  81.                 break;
  82.                
  83.             case 3:
  84.                 if(Math.random() > 0.5)
  85.                 {
  86.                     voteFunctionPairs[i]["voteUpFunc"]();
  87.                 }
  88.                 else
  89.                 {
  90.                     voteFunctionPairs[i]["voteDownFunc"]();
  91.                 }
  92.                 break;
  93.         }
  94.     }
  95. }
  96.  
  97. if(new RegExp("[0-9]+.html").test(document.URL))
  98. {
  99.     var updateBar = $("#update");
  100.    
  101.     var discordMenu = updateBar.clone();
  102.     discordMenu.css("bottom", 200);
  103.     discordMenu.html("");
  104.     updateBar.before(discordMenu);
  105.    
  106.     var buttons = [
  107.       { "id" : "discordUpvoteBtn",      "symbol" : "+",         "color" : "green",      "onClick" : function(){ vote(1); }  },
  108.       { "id" : "discordDownvoteBtn",    "symbol" : "&#8212;",   "color" : "red",        "onClick" : function(){ vote(2); }  },
  109.       { "id" : "discordRandomvoteBtn",  "symbol" : "?",         "color" : "blue",       "onClick" : function(){ vote(3); }  },
  110.       { "id" : "discordModeBtn",        "symbol" : "S",         "color" : "#FF0080",    "onClick" : switchMode              }
  111.     ];
  112.    
  113.     var buttonSize = 25;
  114.     var discordFontSize = 14;
  115.    
  116.     for(var i = 0; i < buttons.length; i++)
  117.     {
  118.         discordMenu.html(discordMenu.html() + "<button id='" + buttons[i]["id"] + "'>" + buttons[i]["symbol"] + "</button><br>");
  119.     }
  120.    
  121.     for(var i = 0; i < buttons.length; i++)
  122.     {
  123.         $("#" + buttons[i]["id"]).css({
  124.             "width" : buttonSize,
  125.             "height" : buttonSize,
  126.             "background-color" : "transparent",
  127.             "font-size" : discordFontSize,
  128.             "color" : buttons[i]["color"],
  129.             "border" : 0,
  130.             "font-weight" : "bold"
  131.         }).attr('onclick', '').click(buttons[i]["onClick"]);
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment