// ==UserScript== // @name HLTV Forum Enhancements // @namespace plennhar-hltv-forum-enhancements // @version 1.1 // @description Adds a few additional features to the HLTV forums such as extended forums sidebar or sorting of the sidebar by comments or creation date. // @author Plennhar // @match https://www.hltv.org/* // @grant GM_xmlhttpRequest // @grant GM.setValue // @grant GM.getValue // @require https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js // @license GPL-3.0-or-later // @downloadURL none // ==/UserScript== // SPDX-FileCopyrightText: 2024 Plennhar // SPDX-License-Identifier: GPL-3.0-or-later (function() { 'use strict'; console.log("Initializing script"); const forums = { 'https://www.hltv.org/forums/offtopic': 'red', 'https://www.hltv.org/forums/counterstrike': '#ffae00', 'https://www.hltv.org/forums/fantasy': '#633da0', 'https://www.hltv.org/forums/betting': 'darkgreen', 'https://www.hltv.org/forums/hardware': 'silver', 'https://www.hltv.org/forums/bugs': '#3d6ea0' }; function fetchPosts(url) { console.log(`Requesting data from ${url}`); return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: 'GET', url: url, onload: function(response) { console.log(`Received response from ${url}`); const parser = new DOMParser(); const doc = parser.parseFromString(response.responseText, 'text/html'); resolve({ doc, url }); }, onerror: function(error) { console.error(`Failed to fetch data from ${url}`, error); reject(error); } }); }); } function addPostsToSidebar(doc, url) { console.log(`Processing document for ${url}`); const threads = $(doc).find('.forumthreads tr.tablerow').toArray(); console.log(`Found ${threads.length} threads on ${url}`); const boxShadowColor = forums[url] || '#ffae00'; // Default color threads.forEach(thread => { const threadLink = $(thread).find('.name a'); const threadHref = threadLink.attr('href'); const threadTitle = threadLink.text(); const threadReplies = $(thread).find('.replies').text(); const threadId = threadHref.split('/').pop(); const existingThread = $(`a[href="${threadHref}"]`); if (existingThread.length === 0) { console.log(`Adding thread ${threadId} to the sidebar`); $('.activitylist').append( `${threadTitle}${threadReplies}` ); } else { // If a match is found, change the border color to the one defined in forums console.log(`Thread ${threadId} is already in the sidebar, updating border color.`); existingThread.css('box-shadow', `inset 2px 0 0 0 ${boxShadowColor}`); } }); } function checkForSidebar() { console.log("Checking for sidebar..."); const sidebar = document.querySelector('.activitylist'); if (sidebar) { console.log("Sidebar found"); return sidebar; } else { console.log("Sidebar not found, retrying..."); return null; } } function waitForSidebar() { return new Promise((resolve) => { const interval = setInterval(() => { const sidebar = checkForSidebar(); if (sidebar) { clearInterval(interval); resolve(sidebar); } }, 300); }); } function updateCheckboxStates(checkboxes) { const selectedCount = checkboxes.find('input:checked').length; checkboxes.find('input').each(function() { if (selectedCount >= 2 && !$(this).is(':checked')) { $(this).prop('disabled', true).closest('label').css('color', '#999'); } else { $(this).prop('disabled', false).closest('label').css('color', ''); } }); } function createPreferencesModal() { const modal = $('
').addClass('preferences-modal').css({ position: 'fixed', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', backgroundColor: '#333', padding: '20px', zIndex: '10000', display: 'none', color: 'white', borderRadius: '5px' }); const title = $('

').text('Fetch extra forum threads to sidebar').css({ marginBottom: '10px', fontSize: '18px' }); const checkboxes = $('
').css({ display: 'grid', gridTemplateColumns: '1fr 1fr', gridGap: '10px' }); Object.keys(forums).forEach(url => { const label = $('