Advertisement
nuwcareuiu4tb67

meneame.net - Destacar comentarios de usuarios recientes

Apr 11th, 2020
269
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     2.1
  7. // @description Destacar comentarios de usuarios con menos de 90 días.
  8. // @author      Niko & оᴄнᴏсᴇʀоs
  9. // @match       *://*.meneame.net/*
  10. // @grant       GM.setValue
  11. // @grant       GM.getValue
  12. // ==/UserScript==
  13.  
  14. /*jshint esversion: 6 */
  15.  
  16. // ---- SCRIPT CONFIG ----
  17. const NOOB_DAYS = 90;
  18. const PIC_L = "&nbsp;&nbsp;<svg width='11' height='12' style='overflow: visible'> <rect style='fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.23726973;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1' height='16.553701' ry='0.88286412' rx='0.88286412' width='14.898332' id='rect858' x='-0.096365139' y='-0.096365139'></rect> <rect rx='0.55179006' ry='0.55179006' height='14.898332' x='0.73131996' y='0.73131996' width='13.242962' style='fill:#0ba800;fill-opacity:1;stroke:#000000;stroke-width:0.20416233;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1' id='rect860'></rect> <path style='fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.09538639;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1' d='M 2.7781475,1.6690757 V 14.711704 h 3.3093231 v -0.0058 H 11.927454 V 12.181045 L 5.5034726,12.161578 V 1.6496091 Z' id='rect817'></path></svg>"
  19.  
  20. // ---- API values ----
  21. const USERNAME_CLASS = '.username';
  22. const SUBMITTED_NEWS_CLASS = '.news-submitted';
  23. const REQUEST_URL = 'https://www.meneame.net/backend/get_user_info?id=';
  24.  
  25. window.onload = function () {
  26.     highlightUserComments();
  27.     highlightUserNews();
  28. };
  29.  
  30. function highlightUserComments() {
  31.     let usernames = document.querySelectorAll(USERNAME_CLASS);
  32.     usernames.forEach( function(node) {
  33.         processUserCommentNode(node);
  34.     });
  35.     usernames = "";
  36. }
  37.  
  38. function highlightUserNews() {
  39.     let newsSubmitted = document.querySelectorAll(SUBMITTED_NEWS_CLASS);
  40.     newsSubmitted.forEach( function(node) {
  41.         processNewsSubmittedNode(node);
  42.     });
  43.     newsSubmitted = "";
  44. }
  45.  
  46. function processNewsSubmittedNode(node) {
  47.     const user = node.childNodes[3].textContent;
  48.     let date = "";
  49.     (async() => {
  50.         let date = await GM.getValue(user, "");
  51.         if (date === "") {
  52.             let date = requestRegistrationDate(node, user);
  53.         }
  54.         checkIfNoobUserNews(node, date);
  55.     })();
  56. }
  57.  
  58. function processUserCommentNode(node) {
  59.     const user = node.textContent;
  60.     let date = "";
  61.     (async() => {
  62.         let date = await GM.getValue(user, "");
  63.         if (date === "") {
  64.             let date = requestRegistrationDate(node, user);
  65.         }
  66.         checkIfNoobUserComment(node, date);
  67.     })();
  68. }
  69.  
  70. function requestRegistrationDate(node, user) {
  71.     let xhttp = new XMLHttpRequest();
  72.     xhttp.onreadystatechange = function() {
  73.         if (this.readyState === 4 && this.status === 200) {
  74.             const dateRegex = /((0[1-9]|[12]\d|3[01])-(0[1-9]|1[0-2])-[12]\d{3})/;
  75.             const date = this.responseText.match(dateRegex);
  76.             GM.setValue(user, date[0]);
  77.         }
  78.     };
  79.     xhttp.open("GET", REQUEST_URL + user, true);
  80.     xhttp.send();
  81. }
  82.  
  83. function checkIfNoobUserComment(node, dateStr) {
  84.     if (daysSinceRegistration(dateStr) < NOOB_DAYS) {
  85.         node.insertAdjacentHTML('afterend',PIC_L);
  86.     }
  87. }
  88.  
  89. function checkIfNoobUserNews(node, dateStr) {
  90.     if (daysSinceRegistration(dateStr) < NOOB_DAYS) {
  91.         node.childNodes[3].insertAdjacentHTML('afterend',PIC_L + "&nbsp;&nbsp;");
  92.     }
  93. }
  94.  
  95. function daysSinceRegistration(dateStr) {
  96.     const dateArray = dateStr.toString().split('-');
  97.     const date = new Date(dateArray[2], dateArray[1] - 1, dateArray[0]);
  98.     return (Date.now() - date.getTime()) / 3600000 / 24;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement