Guest User

Untitled

a guest
Nov 28th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     JoyReactor comment rating
  3. // @version  1
  4. // @grant    none
  5. // @include  http://old.reactor.cc/*
  6. // ==/UserScript==
  7.  
  8. $(document).ready(function () {
  9.   console.log('initialized');
  10.  
  11.   if ((/\/post\/[0-9]+/).test(location.pathname)) {
  12.     fetch(location.toString(), {'credentials' : 'omit'})
  13.       .then(r => r.text())
  14.       .then(t => $(t).find('.comment_rating'))
  15.       .then(function(d) {
  16.           d.each((i ,r) => {
  17.             var commentNodeId = 'comment' + r.attributes.comment_id.nodeValue;
  18.             var commentNode = document.getElementById(commentNodeId);
  19.  
  20.             var innerNode = commentNode.querySelector('.comment_rating > span');
  21.            
  22.             if (innerNode.childNodes[0].nodeName === '#text') {
  23.                 innerNode.childNodes[0].textContent = r.textContent.trim() + ' ';
  24.             } else {
  25.                 innerNode.prepend(document.createTextNode(r.textContent.trim() + ' '));
  26.             }
  27.           });
  28.       });
  29.   }
  30. });
Advertisement
Add Comment
Please, Sign In to add comment