Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name meneame.net - Destacar comentarios de usuarios recientes
- // @namespace http://tampermonkey.net/
- // @version 1.0
- // @description Destaca los comentarios de aquellos usuarios creados hace menos de 90 días.
- // @author Niko
- // @match *://*.meneame.net/*
- // @grant GM.setValue
- // @grant GM.getValue
- // ==/UserScript==
- /*jshint esversion: 6 */
- // ---- SCRIPT CONFIG ----
- const NOOB_DAYS = 90;
- const BGPLAIN_COLOR = '#EEE';
- const BG_STRIPES_COLOR1 = '#fff';
- const BG_STRIPES_COLOR2 = '#ebeef5'; // Blue Mediat1ze XD
- const STYLE = "STRIPES"; // PLAIN or STRIPES
- // ---- API values ----
- const USERNAME_CLASS = '.username';
- const REQUEST_URL = 'https://www.meneame.net/backend/get_user_info?id=';
- let checkedUsers = [];
- window.onload = function () {
- let usernames = document.querySelectorAll(USERNAME_CLASS);
- usernames.forEach( function(node) {
- processUserNode(node);
- });
- };
- function processUserNode(node) {
- const user = node.textContent;
- (async() =>
- let date = await GM.getValue(user, "");
- )
- if (date === "") {
- requestRegistrationDate(node, user);
- }
- checkIfNoobUser(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]);
- checkIfNoobUser(node, date[0]);
- }
- };
- xhttp.open("GET", REQUEST_URL + user, true);
- xhttp.send();
- }
- function checkIfNoobUser(node, dateStr) {
- const dateArray = dateStr.toString().split('-');
- const date = new Date(dateArray[2], dateArray[1] - 1, dateArray[0]);
- const daysSinceRegistration = (Date.now() - date.getTime()) / 3600000 / 24;
- if (daysSinceRegistration < NOOB_DAYS) {
- highlightUser(node);
- }
- }
- function highlightUser(node) {
- switch(STYLE) {
- case "PLAIN":
- node.parentNode.parentNode.style.backgroundColor = BGPLAIN_COLOR;
- break;
- case "STRIPES":
- {const BGSTRIPES = "repeating-linear-gradient( 45deg, " + BG_STRIPES_COLOR1 + ", " + BG_STRIPES_COLOR1 + " 10px, " + BG_STRIPES_COLOR2 + " 10px, " + BG_STRIPES_COLOR2 + " 20px );";
- node.parentNode.parentNode.setAttribute("style", "background-image: " + BGSTRIPES);
- break;}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement