erinx icon

imgur ups&downs

erinx | PRO | 03/28/21 11:43:11 AM UTC | 0 ⭐ | 773 👁️ | Never ⏰ | []
JavaScript |

1.38 KB

|

None

|

0 👍

/

0 👎

// ==UserScript==
// @name Imgur Up/Down Votes
// @namespace erin
// @include *imgur.com/*
// @run-at document-end
// @grant  GM_xmlhttpRequest
// ==/UserScript==
 
 
function imUpDown(){
  var d, db, $;
 
  d = document;
  db = document.body;
 
  $ = function(s, p){
    if(!p || p == null){
      p = db;
    }
    return p.querySelector(s);
  };
 
  $.JSON = function(s){
    if(typeof s == 'string'){
      return JSON.parse(s);
    }else{
      return JSON.stringify(s);
    }
  };
 
  function getUpDown(){
    var pUrl = window.location.href.split('gallery/')[1];
    GM_xmlhttpRequest({
      method: "GET",
      url: "https://api.imgur.com/3/gallery/" + pUrl + "/votes",
      headers: {
        "Authorization": "Client-ID aa85c35462e5c53"
      },
      onload: function(response){
        var rx = $.JSON(response.responseText)['data'];
        $('.post-action-stats-points').innerHTML += 
          '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>▲' 
          + rx['ups'] + 
          '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;▼' 
          + rx['downs'] + '</span>';
      }
    });   
  }
  
  $('.navNext').onclick = function(){ 
     window.setTimeout(function(){getUpDown();}, 200);
  }
  
  $('.navPrev').onclick = function(){ 
     window.setTimeout(function(){getUpDown();}, 200);
  }
  
  getUpDown();
}
imUpDown();

Comments