Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Google Lens - Czysta Galeria (V6.2 Fix Duplikatów)
- // @namespace http://tampermonkey.net/
- // @version 6.2
- // @description Tworzy nową galerię z posortowanych wyników. Naprawiono błąd ukrywania obrazków o tej samej rozdzielczości.
- // @author Ty
- // @match https://www.google.com/search?*lns_surface=*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- const BUTTON_ID = 'img-sort-btn-v6';
- const RES_REGEX = /((?:\d{1,3}[\s.]?)+)\s*[x×]\s*((?:\d{1,3}[\s.]?)+)/;
- // --- KONFIGURACJA UI ---
- function createButton() {
- if (document.getElementById(BUTTON_ID)) return;
- const btn = document.createElement('button');
- btn.id = BUTTON_ID;
- btn.innerText = "⚡ JUMP DOWN & SORT";
- Object.assign(btn.style, {
- position: 'fixed',
- bottom: '150px',
- right: '20px',
- zIndex: '9999999',
- padding: '12px 20px',
- backgroundColor: '#202124',
- color: '#8ab4f8',
- border: '2px solid #8ab4f8',
- borderRadius: '8px',
- cursor: 'pointer',
- fontWeight: 'bold',
- fontSize: '14px',
- boxShadow: '0 4px 10px rgba(0,0,0,0.5)'
- });
- btn.onclick = () => {
- btn.innerText = "⬇️ Loading Images...";
- // Skocz na dół, by wymusić ładowanie lazy-load
- window.scrollTo({
- top: document.body.scrollHeight,
- behavior: 'smooth'
- });
- // Czekaj 2 sekundy
- setTimeout(() => {
- btn.innerText = "⏳ Wait: Analizyng & Sort...";
- setTimeout(generateCleanGallery, 100);
- }, 2000);
- };
- document.body.appendChild(btn);
- }
- // --- LOGIKA CZYSZCZENIA LINKÓW ---
- function cleanGoogleUrl(url) {
- if (!url) return null;
- if (!url.includes('google.com')) return url;
- try {
- const urlObj = new URL(url);
- const q = urlObj.searchParams.get('q');
- const imgurl = urlObj.searchParams.get('imgurl');
- if (imgurl) return decodeURIComponent(imgurl);
- if (q) return decodeURIComponent(q);
- } catch (e) {}
- return url;
- }
- // --- LOGIKA EKSTRAKCJI DANYCH ---
- function generateCleanGallery() {
- const btn = document.getElementById(BUTTON_ID);
- const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
- const items = [];
- let node;
- while (node = walker.nextNode()) {
- if (RES_REGEX.test(node.nodeValue)) {
- const match = node.nodeValue.match(RES_REGEX);
- const w = parseInt(match[1].replace(/[^\d]/g, ''), 10);
- const h = parseInt(match[2].replace(/[^\d]/g, ''), 10);
- const pixels = w * h;
- // Szukanie kontenera
- let card = node.parentElement;
- let validCard = null;
- for (let i = 0; i < 15; i++) {
- if (!card) break;
- if (card.querySelector('img')) {
- validCard = card;
- if (card.parentElement.tagName === 'A') validCard = card.parentElement;
- if (card.parentElement.parentElement && card.parentElement.parentElement.tagName === 'A') validCard = card.parentElement.parentElement;
- break;
- }
- card = card.parentElement;
- }
- if (validCard) {
- const img = validCard.querySelector('img');
- // Pobieramy najlepsze dostępne źródło
- let imgSrc = img ? (img.getAttribute('data-src') || img.getAttribute('data-iurl') || img.src) : '';
- let linkUrl = '';
- if (validCard.tagName === 'A') {
- linkUrl = validCard.href;
- } else {
- const a = validCard.querySelector('a');
- if (a) linkUrl = a.href;
- }
- const cleanLink = cleanGoogleUrl(linkUrl);
- // --- POPRAWKA TUTAJ ---
- // Sprawdzamy duplikaty dokładniej.
- // Element jest duplikatem TYLKO jeśli ma ten sam obrazek ORAZ ten sam link docelowy.
- // Pozwala to na wiele obrazków z tą samą rozdzielczością, a nawet tym samym placeholderem, jeśli prowadzą gdzie indziej.
- const isDuplicate = items.some(item => item.src === imgSrc && item.link === cleanLink);
- if (imgSrc && !isDuplicate) {
- items.push({
- src: imgSrc,
- link: cleanLink,
- res: match[0],
- pixels: pixels
- });
- }
- }
- }
- }
- if (items.length === 0) {
- alert("No results found. Try scrolling the page manually.");
- btn.innerText = "⚡ JUMP DOWN & SORT";
- return;
- }
- // Sortowanie malejąco po pikselach
- items.sort((a, b) => b.pixels - a.pixels);
- renderGallery(items);
- btn.innerText = "✅ Done";
- }
- function renderGallery(items) {
- const old = document.getElementById('custom-clean-gallery');
- if (old) old.remove();
- const container = document.createElement('div');
- container.id = 'custom-clean-gallery';
- Object.assign(container.style, {
- position: 'relative',
- width: '100%',
- backgroundColor: '#121212',
- padding: '20px',
- boxSizing: 'border-box',
- borderBottom: '4px solid #8ab4f8',
- marginBottom: '20px',
- zIndex: '100'
- });
- const grid = document.createElement('div');
- Object.assign(grid.style, {
- display: 'grid',
- gridTemplateColumns: 'repeat(auto-fill, minmax(200px, 1fr))',
- gap: '15px',
- });
- const header = document.createElement('h2');
- header.innerText = `🔍 Znaleziono ${items.length} obrazów (Posortowane)`;
- header.style.color = '#fff';
- header.style.fontFamily = 'sans-serif';
- header.style.marginBottom = '15px';
- container.appendChild(header);
- items.forEach(item => {
- const card = document.createElement('div');
- Object.assign(card.style, {
- backgroundColor: '#2d2e30',
- borderRadius: '8px',
- overflow: 'hidden',
- display: 'flex',
- flexDirection: 'column',
- border: '1px solid #3c4043'
- });
- const link = document.createElement('a');
- link.href = item.link || '#';
- link.target = '_blank';
- link.style.textDecoration = 'none';
- link.style.flexGrow = '1';
- link.style.display = 'flex';
- link.style.flexDirection = 'column';
- const img = document.createElement('img');
- img.src = item.src;
- Object.assign(img.style, {
- width: '100%',
- height: '200px',
- objectFit: 'contain',
- backgroundColor: '#000',
- display: 'block'
- });
- const info = document.createElement('div');
- Object.assign(info.style, {
- padding: '10px',
- color: '#e8eaed',
- fontSize: '12px',
- fontFamily: 'monospace',
- textAlign: 'center',
- borderTop: '1px solid #3c4043'
- });
- info.innerHTML = `
- <span style="color:#8ab4f8; font-weight:bold; font-size:14px;">${item.res}</span><br>
- <span style="color:#9aa0a6;">Kliknij, aby otworzyć</span>
- `;
- link.appendChild(img);
- link.appendChild(info);
- card.appendChild(link);
- grid.appendChild(card);
- });
- container.appendChild(grid);
- const main = document.getElementById('main') || document.body;
- main.prepend(container);
- window.scrollTo({ top: 0, behavior: 'smooth' });
- }
- createButton();
- })();
Advertisement