// ==UserScript== // @name Yandex CleanSearch // @namespace http://tampermonkey.net/ // @version 2.9 // @description Блокировка страниц по домену и заголовкам, рекламы и прочего дерьма в яндекс. // @author Zzakhar // @match https://yandex.ru/search/* // @grant none // @license CC BY-NC-ND // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Дб локал let blockedSites = JSON.parse(localStorage.getItem('blockedSites')) || []; let blockedPropagandaCount = 0; let blockedAdsCount = 0; let blockedPropaganda = []; let isHidden = true; // Короч для плавности, т..к когда появляется иконка она сдвигает серчбар function movesearchbar() { const searchBar = document.querySelector('header.HeaderDesktop-Main .HeaderForm'); if (!searchBar) { console.error('Форма поиска не найдена'); return; } searchBar.style.cssText = ` position: relative; left: 34px; transition: left 0.7s ease; /* Плавный переход */ `; setTimeout(() => { searchBar.style.left = '0px'; }, 940.87); } movesearchbar() // счетчик function updateBlockCounter() { const resultsContainer = document.querySelector('.main__center'); let counterCard = resultsContainer.querySelector('.blocked-counter-card'); if (!counterCard) { counterCard = document.createElement('div'); counterCard.className = 'blocked-counter-card'; counterCard.style.backgroundColor = '#300'; counterCard.style.color = '#ffffff'; counterCard.style.padding = '10px'; counterCard.style.marginBottom = '10px'; counterCard.style.border = '1px solid #600'; counterCard.style.borderRadius = '5px'; counterCard.style.maxWidth = '34%'; counterCard.style.overflow = 'auto'; resultsContainer.prepend(counterCard); } const counterText = `Заблокировано: ${blockedPropagandaCount} ненужного мусора и ${blockedAdsCount} рекламы`; let textElement = counterCard.querySelector('.counter-text'); if (!textElement) { textElement = document.createElement('div'); textElement.className = 'counter-text'; counterCard.appendChild(textElement); } textElement.textContent = counterText; updateButtons(counterCard); } // смена кнопок function updateButtons(counterCard) { let showButton = counterCard.querySelector('.show-button'); let removeButton = counterCard.querySelector('.remove-button'); if (blockedPropagandaCount > 0 || blockedAdsCount > 0) { counterCard.style.display = 'flex'; counterCard.style.justifyContent = 'space-between'; counterCard.style.alignItems = 'center'; if (isHidden) { if (!showButton) { showButton = document.createElement('button'); showButton.className = 'show-button'; showButton.textContent = 'Показать'; showButton.style.backgroundColor = '#007bff'; showButton.style.color = '#ffffff'; showButton.style.border = 'none'; showButton.style.borderRadius = '5px'; showButton.style.padding = '5px 10px'; showButton.style.cursor = 'pointer'; showButton.style.marginLeft = '10px'; showButton.onclick = showBlockedPropaganda; counterCard.appendChild(showButton); } if (removeButton) { removeButton.remove(); } } else { if (!removeButton) { removeButton = document.createElement('button'); removeButton.className = 'remove-button'; removeButton.textContent = 'Убрать'; removeButton.style.backgroundColor = '#dc3545'; removeButton.style.color = '#ffffff'; removeButton.style.border = 'none'; removeButton.style.borderRadius = '5px'; removeButton.style.padding = '5px 10px'; removeButton.style.cursor = 'pointer'; removeButton.style.marginLeft = '10px'; removeButton.onclick = hideBlockedPropaganda; counterCard.appendChild(removeButton); } if (showButton) { showButton.remove(); } } } else { if (showButton) { showButton.remove(); } if (removeButton) { removeButton.remove(); } } } // Мейн функция поиска function blockLinksAndAds() { const results = document.querySelectorAll('.serp-item'); blockedPropagandaCount = 0; blockedAdsCount = 0; blockedPropaganda = []; results.forEach(result => { const isAd = checkIfAd(result); const link = result.querySelector('a.Link'); const title = result.querySelector('.OrganicTitle-LinkText'); if (link && title) { const href = link.href.toLowerCase(); const titleText = title.textContent.toLowerCase(); const isBlocked = blockedSites.some(site => href.includes(site) || titleText.includes(site)); if (isAd) { result.style.display = 'none'; blockedAdsCount++; } else if (isBlocked) { result.style.display = 'none'; blockedPropagandaCount++; blockedPropaganda.push(result); console.log("Заблокирована дичь: ", result); } } }); const containerToHide = document.querySelector("body > main > div > div.main__container > div > div > div.content__left > div.VanillaReact.RelatedBottom"); if (containerToHide) { containerToHide.style.display = 'none'; console.log("Рекомендациии скрыты."); } updateBlockCounter(); } // function checkIfAd(result) { const adTextIndicators = ['реклама', 'баннер',"ad","advertise"]; return adTextIndicators.some(text => result.textContent.toLowerCase().includes(text)); } // Показать бтн function showBlockedPropaganda() { console.log("Показать"); if (isHidden) { blockedPropaganda.forEach(prop => { prop.style.display = 'block'; }); isHidden = false; updateButtons(document.querySelector('.blocked-counter-card')); } } // Скрыть бтн function hideBlockedPropaganda() { console.log("Кнопка 'Убрать' нажата!"); if (!isHidden) { blockedPropaganda.forEach(prop => { prop.style.display = 'none'; }); isHidden = true; updateButtons(document.querySelector('.blocked-counter-card')); } } // дб function saveBlockedSites() { localStorage.setItem('blockedSites', JSON.stringify(blockedSites)); } window.addEventListener('load', () => { blockLinksAndAds(); }); //основной цикл const observer = new MutationObserver(() => { if (isHidden) { blockLinksAndAds(); } }); observer.observe(document.body, { childList: true, subtree: true }); // настройки function resetBlockedSites() { blockedSites.length = 0; saveBlockedSites(); updateBlockedSitesList(); setTimeout(() => { location.reload(); // релоад }, 2000); showNotification('Все заблокированные сайты были очищены.'); } function updateBlockedSitesList() { const list = document.getElementById('blockedSitesList'); list.innerHTML = ''; blockedSites.forEach(site => { const li = document.createElement('li'); li.textContent = site; list.appendChild(li); }); } function createPopup() { const popup = document.createElement('div'); popup.className = 'custom-popup'; popup.style.cssText = ` position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #0e1011; border: 2px solid #970e05; /* Цвет рамки */ border-radius: 10px; /* Скругленные углы */ box-shadow: 0 0 15px #4c0803, 0 0 30px #8b0903; padding: 20px; z-index: 9999; display: none; width: 300px; max-width: 90%; transition: transform 0.3s ease, opacity 0.3s ease; opacity: 0; `; popup.innerHTML = `