הצעת ייעול | פוסטים פופולאריים
-
@userbot סקריפט לטמפרמונקי לכפתור פופולארי בסרגל הצד בפורום. 5 דק' עם AI...
// ==UserScript== // @name הוספת 'פופולארי' לסרגל הצד במתמחים טופ // @namespace http://tampermonkey.net/ // @version 0.4 // @description מוסיף קישור "פופולארי" לסרגל הצד בפורום מתמחים טופ, עם tooltip, אחרי "נושאים שלא נפתרו" // @author לאצי&AI // @match https://mitmachim.top/* // @grant none // @run-at document-idle // ==/UserScript== (function() { 'use strict'; const LINK_ID = 'custom-popular-link-li'; // ID ייחודי לאלמנט החדש const LINK_URL = 'https://mitmachim.top/popular'; const LINK_TEXT = 'פופולארי'; const LINK_ICON_CLASS = 'fa-fire'; // אפשר לשנות ל- fa-star, fa-line-chart, fa-trophy וכו' // פונקציה לאתחול tooltip על אלמנט ספציפי function initializeTooltip(element) { if (typeof bootstrap !== 'undefined' && typeof bootstrap.Tooltip === 'function') { new bootstrap.Tooltip(element); } else { let attempts = 0; const maxAttempts = 15; const intervalId = setInterval(() => { attempts++; if (typeof bootstrap !== 'undefined' && typeof bootstrap.Tooltip === 'function') { clearInterval(intervalId); new bootstrap.Tooltip(element); } else if (attempts >= maxAttempts) { clearInterval(intervalId); console.warn('Tampermonkey: Bootstrap Tooltip function not found after ' + maxAttempts + ' attempts. Tooltip for new element might not work.'); } }, 200); } } function addPopularLink() { if (document.getElementById(LINK_ID)) { return; } const mainNav = document.getElementById('main-nav'); if (mainNav) { const listItem = document.createElement('li'); listItem.id = LINK_ID; listItem.className = 'nav-item mx-2'; listItem.setAttribute('data-bs-toggle', 'tooltip'); listItem.setAttribute('data-bs-placement', 'right'); listItem.setAttribute('title', LINK_TEXT); const linkElement = document.createElement('a'); linkElement.className = 'nav-link navigation-link d-flex gap-2 justify-content-between align-items-center'; linkElement.href = LINK_URL; linkElement.setAttribute('aria-label', LINK_TEXT); const mainSpan = document.createElement('span'); mainSpan.className = 'd-flex gap-2 align-items-center text-nowrap truncate-open'; const iconContainerSpan = document.createElement('span'); iconContainerSpan.className = 'position-relative'; const iconElement = document.createElement('i'); iconElement.className = `fa fa-fw ${LINK_ICON_CLASS}`; iconElement.setAttribute('data-content', ''); const badgeClosedSpan = document.createElement('span'); badgeClosedSpan.setAttribute('component', 'navigation/count'); badgeClosedSpan.className = 'visible-closed position-absolute top-0 start-100 translate-middle badge rounded-1 bg-primary hidden'; iconContainerSpan.appendChild(iconElement); iconContainerSpan.appendChild(badgeClosedSpan); const textSpan = document.createElement('span'); textSpan.className = 'nav-text small visible-open fw-semibold text-truncate'; textSpan.textContent = LINK_TEXT; mainSpan.appendChild(iconContainerSpan); mainSpan.appendChild(textSpan); const badgeOpenSpan = document.createElement('span'); badgeOpenSpan.setAttribute('component', 'navigation/count'); badgeOpenSpan.className = 'visible-open badge rounded-1 bg-primary hidden'; linkElement.appendChild(mainSpan); linkElement.appendChild(badgeOpenSpan); listItem.appendChild(linkElement); // ---- החלק של הוספת האלמנט למיקום הנכון ---- const unsolvedTopicsAnchor = mainNav.querySelector('a[href="/unsolved"]'); if (unsolvedTopicsAnchor) { const unsolvedTopicsLi = unsolvedTopicsAnchor.closest('li'); if (unsolvedTopicsLi && unsolvedTopicsLi.nextSibling) { mainNav.insertBefore(listItem, unsolvedTopicsLi.nextSibling); } else if (unsolvedTopicsLi) { mainNav.appendChild(listItem); // אם "נושאים שלא נפתרו" הוא האחרון } else { mainNav.appendChild(listItem); // Fallback: אם ה-li לא נמצא } } else { // Fallback: אם הקישור "נושאים שלא נפתרו" לא נמצא, הוסף בסוף הרשימה mainNav.appendChild(listItem); } // ---- סוף החלק של הוספת האלמנט ---- initializeTooltip(listItem); console.log('Tampermonkey: קישור "פופולארי" נוסף לסרגל הצד.'); } } addPopularLink(); const observer = new MutationObserver(function(mutations, obs) { if (document.getElementById('main-nav') && !document.getElementById(LINK_ID)) { addPopularLink(); } }); observer.observe(document.documentElement, { childList: true, subtree: true }); })();