Advertisement
Guest User

meneame.net - Destacar comentarios de usuarios recientes (2)

a guest
Apr 8th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        meneame.net - Destacar comentarios de usuarios recientes
  3. // @namespace    http://tampermonkey.net/
  4. // @version     1.0
  5. // @description Destaca los comentarios de aquellos usuarios creados hace menos de 90 días.
  6. // @author      Niko
  7. // @match       *://*.meneame.net/*
  8. // @grant       GM.setValue
  9. // @grant       GM.getValue
  10. // ==/UserScript==
  11.  
  12. /*jshint esversion: 6 */
  13.  
  14. // ---- SCRIPT CONFIG ----
  15. const NOOB_DAYS = 90;
  16. const BGPLAIN_COLOR = '#EEE';
  17. const BG_STRIPES_COLOR1 = '#fff';
  18. const BG_STRIPES_COLOR2 = '#ebeef5'; // Blue Mediat1ze XD
  19. const STYLE = "STRIPES"; // PLAIN or STRIPES
  20.  
  21. // ---- API values ----
  22. const USERNAME_CLASS = '.username';
  23. const REQUEST_URL = 'https://www.meneame.net/backend/get_user_info?id=';
  24.  
  25. let checkedUsers = [];
  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.     (async() =>
  37.         let date = await GM.getValue(user, "");
  38.     )
  39.     if (date === "") {
  40.         requestRegistrationDate(node, user);
  41.     }  
  42.     checkIfNoobUser(node, date);
  43. }
  44.  
  45. function requestRegistrationDate(node, user) {
  46.     let xhttp = new XMLHttpRequest();
  47.     xhttp.onreadystatechange = function() {
  48.         if (this.readyState === 4 && this.status === 200) {
  49.             const dateRegex = /((0[1-9]|[12]\d|3[01])-(0[1-9]|1[0-2])-[12]\d{3})/;
  50.             const date = this.responseText.match(dateRegex);
  51.             GM.setValue(user, date[0]);
  52.             checkIfNoobUser(node, 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 = BGPLAIN_COLOR;
  72.             break;
  73.         case "STRIPES":
  74.             {const BGSTRIPES = "repeating-linear-gradient( 45deg, " + BG_STRIPES_COLOR1 + ", " + BG_STRIPES_COLOR1 + " 10px, " + BG_STRIPES_COLOR2 + " 10px, " + BG_STRIPES_COLOR2 + " 20px );";
  75.             node.parentNode.parentNode.setAttribute("style", "background-image: " + BGSTRIPES);
  76.             break;}
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement