// ==UserScript== // @name EOL+ // @namespace EOL+ // @description Mejoras y nuevas funciones para ElOtroLado.net. // @author Saikuro // @copyright 2018+, Saikuro // @version 0.4.2 // @license MIT // @homepageURL https://github.com/saikusan/eolplus // @supportURL https://github.com/saikusan/eolplus/issues // @updateURL https://raw.githubusercontent.com/saikusan/eolplus/master/eolplus.meta.js // @downloadURL https://raw.githubusercontent.com/saikusan/eolplus/master/eolplus.user.js // @icon https://raw.githubusercontent.com/saikusan/eolplus/master/resources/img/eol.png // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM.getValue // @grant GM.setValue // @grant GM.deleteValue // @run-at document-end // @match https://www.elotrolado.net/* // ==/UserScript== (function () { 'use strict'; class EOL { constructor() { // C/V forums IDs this.cv_ids = ['212', '97', '164', '98', '99', '100']; // Settings this.loadSettings(); // Start this.init(); } init() { // General info this.getData(); // Debug console.log('User ID', this.user_id); console.log('Section ID', this.section_id); console.log('Thread ID', this.thread_id); // Settings this.injectCSS(); this.cvSettingsHtml(); // Features this.userPostsInSection(); this.userPostsInThread(); this.usersPostsInThread(); this.highlightCVThreads(); } // Features userPostsInSection() { if (this.user_id && this.section_id && !this.thread_id) { let user_posts_url = 'https://www.elotrolado.net/search.php?author_id=' + this.user_id + '&fid[]=' + this.section_id; document.querySelector('.forum-actions .nogutter').insertAdjacentHTML("afterbegin", 'Mis mensajes'); } } userPostsInThread() { if (this.user_id && this.thread_id) { let user_posts_url = '/search.php?author_id=' + this.user_id + '&t=' + this.thread_id; document.querySelector('.topic-actions .nogutter').insertAdjacentHTML("afterbegin", 'Mis mensajes'); } } usersPostsInThread() { if (this.thread_id) { let self = this; let posts = document.querySelectorAll('.post'); posts.forEach(function (post, index) { let about = post.querySelector('.about'); if (about) { let author_url = new URL(post.querySelector('.author').getAttribute('href'), window.location.origin); let author_id = author_url.searchParams.get('u'); let author_posts_url = '/search.php?author_id=' + author_id + '&t=' + self.thread_id; about.insertAdjacentHTML("beforeend", '
'); } }); } } highlightCVThreads() { if (this.cv_ids.includes(this.section_id) && this.cv_highlights) { let self = this; let html = ''; let terms = new RegExp(this.cv_highlights.replace(/,/g, '|'), 'gi'); let threads = document.querySelectorAll('.topic:not(.wikir):not(.announcement)'); console.log('Buscando los siguientes términos', this.cv_highlights); threads.forEach(function (thread, index) { let title = thread.querySelector('.title').textContent.trim(); let alert = thread.querySelector('.cv-alert'); if (title.match(terms)) { thread.querySelector('.lastpost').style.zIndex = '2'; thread.style.backgroundColor = '#d1ecd1'; if (!alert) { thread.insertAdjacentHTML("beforeend", html); } } else { if (alert) { thread.style.backgroundColor = '#eaf5ea'; thread.removeChild(alert); } if (self.cv_hide > 0) { thread.style.display = 'none'; } else { thread.style.display = 'block'; } } }); } } // HTML injectCSS() { let css = ``; document.querySelector('head').insertAdjacentHTML("beforeend", css); } cvSettingsHtml() { if (this.cv_ids.includes(this.section_id)) { let self = this; let html = `Separa cada término con una coma, p.e.: ps4,switch,xbox one,pokemon