nuwcareuiu4tb67

Destacar Nuevos

Apr 8th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Descarga la nueva versión en https://greasyfork.org/es/scripts/400519-meneame-net-destacar-comentarios-de-usuarios-recientes/code
  2. //
  3. // ==UserScript==
  4. // @name        meneame.net - Destacar comentarios de usuarios recientes
  5. // @namespace   http://tampermonkey.net/
  6. // @version     1.3
  7. // @description Destacar comentarios de usuarios con menos de 90 días.
  8. // @author      Niko
  9. // @match       *://*.meneame.net/*
  10. // @include     /https?:\/\/((.+)\.)*meneame.net.*$/
  11. // @grant       GM.setValue
  12. // @grant       GM.getValue
  13. // ==/UserScript==
  14.  
  15. /*jshint esversion: 6 */
  16.  
  17. // ---- SCRIPT CONFIG ----
  18. const NOOB_DAYS = 90;
  19. const BG_PLAIN_COLOR = '#ebeef5'; // Azul Mediat1ze XD
  20. const BG_STRIPES_COLOR = '#fff';
  21. const STYLE = "STRIPES"; // PLAIN or STRIPES
  22.  
  23. // ---- API values ----
  24. const USERNAME_CLASS = '.username';
  25. const REQUEST_URL = 'https://www.meneame.net/backend/get_user_info?id=';
  26.  
  27. window.onload = function () {
  28.     let usernames = document.querySelectorAll(USERNAME_CLASS);
  29.     usernames.forEach( function(node) {
  30.         processUserNode(node);
  31.     });
  32. };
  33.  
  34. function processUserNode(node) {
  35.     const user = node.textContent;
  36.     let date = "";
  37.     (async() => {
  38.         let date = await GM.getValue(user, "");
  39.         if (date === "") {
  40.             let date = requestRegistrationDate(node, user);
  41.         }
  42.         checkIfNoobUser(node, date);
  43.     })();
  44. }
  45.  
  46. function requestRegistrationDate(node, user) {
  47.     let xhttp = new XMLHttpRequest();
  48.     xhttp.onreadystatechange = function() {
  49.         if (this.readyState === 4 && this.status === 200) {
  50.             const dateRegex = /((0[1-9]|[12]\d|3[01])-(0[1-9]|1[0-2])-[12]\d{3})/;
  51.             const date = this.responseText.match(dateRegex);
  52.             GM.setValue(user, date[0]);
  53.         }
  54.     };
  55.     xhttp.open("GET", REQUEST_URL + user, true);
  56.     xhttp.send();
  57. }
  58.  
  59. function checkIfNoobUser(node, dateStr) {
  60.     const dateArray = dateStr.toString().split('-');
  61.     const date = new Date(dateArray[2], dateArray[1] - 1, dateArray[0]);
  62.     const daysSinceRegistration = (Date.now() - date.getTime()) / 3600000 / 24;
  63.     if (daysSinceRegistration < NOOB_DAYS) {
  64.         highlightUser(node);
  65.     }
  66. }
  67.  
  68. function highlightUser(node) {
  69.     switch(STYLE) {
  70.         case "PLAIN":
  71.             node.parentNode.parentNode.style.backgroundColor = BG_PLAIN_COLOR;
  72.             break;
  73.         case "STRIPES":
  74.             {
  75.                 let stripeColor = window.getComputedStyle(node.parentNode.parentNode).getPropertyValue("background-color");
  76.                 const BGSTRIPES = "repeating-linear-gradient( 45deg, " + BG_STRIPES_COLOR + " 1%, " + stripeColor + " 2%);";
  77.                 node.parentNode.parentNode.setAttribute("style", "background-image: " + BGSTRIPES);
  78.             }
  79.             break;
  80.     }
  81. }
Add Comment
Please, Sign In to add comment