Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Descarga la nueva versión en https://greasyfork.org/es/scripts/400519-meneame-net-destacar-comentarios-de-usuarios-recientes/code
- //
- // ==UserScript==
- // @name meneame.net - Destacar comentarios de usuarios recientes
- // @namespace http://tampermonkey.net/
- // @version 2.1
- // @description Destacar comentarios de usuarios con menos de 90 días.
- // @author Niko & оᴄнᴏсᴇʀоs
- // @match *://*.meneame.net/*
- // @grant GM.setValue
- // @grant GM.getValue
- // ==/UserScript==
- /*jshint esversion: 6 */
- // ---- SCRIPT CONFIG ----
- const NOOB_DAYS = 90;
- const PIC_L = " <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>"
- // ---- API values ----
- const USERNAME_CLASS = '.username';
- const SUBMITTED_NEWS_CLASS = '.news-submitted';
- const REQUEST_URL = 'https://www.meneame.net/backend/get_user_info?id=';
- window.onload = function () {
- highlightUserComments();
- highlightUserNews();
- };
- function highlightUserComments() {
- let usernames = document.querySelectorAll(USERNAME_CLASS);
- usernames.forEach( function(node) {
- processUserCommentNode(node);
- });
- usernames = "";
- }
- function highlightUserNews() {
- let newsSubmitted = document.querySelectorAll(SUBMITTED_NEWS_CLASS);
- newsSubmitted.forEach( function(node) {
- processNewsSubmittedNode(node);
- });
- newsSubmitted = "";
- }
- function processNewsSubmittedNode(node) {
- const user = node.childNodes[3].textContent;
- let date = "";
- (async() => {
- let date = await GM.getValue(user, "");
- if (date === "") {
- let date = requestRegistrationDate(node, user);
- }
- checkIfNoobUserNews(node, date);
- })();
- }
- function processUserCommentNode(node) {
- const user = node.textContent;
- let date = "";
- (async() => {
- let date = await GM.getValue(user, "");
- if (date === "") {
- let date = requestRegistrationDate(node, user);
- }
- checkIfNoobUserComment(node, date);
- })();
- }
- function requestRegistrationDate(node, user) {
- let xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if (this.readyState === 4 && this.status === 200) {
- const dateRegex = /((0[1-9]|[12]\d|3[01])-(0[1-9]|1[0-2])-[12]\d{3})/;
- const date = this.responseText.match(dateRegex);
- GM.setValue(user, date[0]);
- }
- };
- xhttp.open("GET", REQUEST_URL + user, true);
- xhttp.send();
- }
- function checkIfNoobUserComment(node, dateStr) {
- if (daysSinceRegistration(dateStr) < NOOB_DAYS) {
- node.insertAdjacentHTML('afterend',PIC_L);
- }
- }
- function checkIfNoobUserNews(node, dateStr) {
- if (daysSinceRegistration(dateStr) < NOOB_DAYS) {
- node.childNodes[3].insertAdjacentHTML('afterend',PIC_L + " ");
- }
- }
- function daysSinceRegistration(dateStr) {
- const dateArray = dateStr.toString().split('-');
- const date = new Date(dateArray[2], dateArray[1] - 1, dateArray[0]);
- return (Date.now() - date.getTime()) / 3600000 / 24;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement