Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Google Play - Image Fullscreen
- // @namespace http://tampermonkey.net/
- // @version 6.1
- // @description Powiększanie zdjęć w Google Play z obsługą strzałek i bezpieczną składnią.
- // @author marek7400
- // @match *://play.google.com/*
- // @grant none
- // @run-at document-end
- // ==/UserScript==
- (function() {
- 'use strict';
- let galleryImages = [];
- let currentIndex = 0;
- // FUNKCJA POMOCNICZA DO STYLOWANIA
- function applyStyles(el, styles) {
- Object.assign(el.style, styles);
- }
- // 1. TWORZENIE ELEMENTÓW INTERFEJSU (Bezpieczne metody)
- const overlay = document.createElement('div');
- applyStyles(overlay, {
- position: 'fixed', top: '0', left: '0', width: '100vw', height: '100vh',
- backgroundColor: 'rgba(0,0,0,0.98)', zIndex: '2147483647',
- display: 'none', justifyContent: 'center', alignItems: 'center', userSelect: 'none'
- });
- const bigImg = document.createElement('img');
- applyStyles(bigImg, {
- maxWidth: '95%', maxHeight: '95%', objectFit: 'contain', boxShadow: '0 0 30px black'
- });
- const btnPrev = document.createElement('div');
- btnPrev.textContent = '❮';
- applyStyles(btnPrev, {
- position: 'absolute', left: '20px', color: 'white', fontSize: '60px',
- cursor: 'pointer', padding: '40px 20px', zIndex: '2147483648', opacity: '0.5',
- transition: 'opacity 0.2s'
- });
- const btnNext = document.createElement('div');
- btnNext.textContent = '❯';
- applyStyles(btnNext, {
- position: 'absolute', right: '20px', color: 'white', fontSize: '60px',
- cursor: 'pointer', padding: '40px 20px', zIndex: '2147483648', opacity: '0.5',
- transition: 'opacity 0.2s'
- });
- const counter = document.createElement('div');
- applyStyles(counter, {
- position: 'absolute', bottom: '20px', color: 'white', fontSize: '16px',
- fontFamily: 'Arial', background: 'rgba(0,0,0,0.5)', padding: '5px 15px', borderRadius: '20px'
- });
- overlay.appendChild(btnPrev);
- overlay.appendChild(bigImg);
- overlay.appendChild(btnNext);
- overlay.appendChild(counter);
- document.body.appendChild(overlay);
- // 2. LOGIKA AKTUALIZACJI OBRAZU
- function updateImage(index) {
- if (galleryImages.length === 0) return;
- if (index < 0) index = galleryImages.length - 1;
- if (index >= galleryImages.length) index = 0;
- currentIndex = index;
- // Pobieranie URL i wymuszanie jakości s0
- const rawUrl = galleryImages[currentIndex];
- const highResUrl = rawUrl.split('=')[0] + "=s0";
- bigImg.src = highResUrl;
- counter.textContent = (currentIndex + 1) + " / " + galleryImages.length;
- }
- function closeOverlay() {
- overlay.style.display = 'none';
- bigImg.src = '';
- }
- // 3. OBSŁUGA ZDARZEŃ (Poprawiona składnia)
- btnPrev.addEventListener('click', (e) => {
- e.stopPropagation();
- updateImage(currentIndex - 1);
- });
- btnNext.addEventListener('click', (e) => {
- e.stopPropagation();
- updateImage(currentIndex + 1);
- });
- // Fix dla "no-return-assign" - dodane klamry {}
- btnPrev.addEventListener('mouseenter', () => { btnPrev.style.opacity = '1'; });
- btnPrev.addEventListener('mouseleave', () => { btnPrev.style.opacity = '0.5'; });
- btnNext.addEventListener('mouseenter', () => { btnNext.style.opacity = '1'; });
- btnNext.addEventListener('mouseleave', () => { btnNext.style.opacity = '0.5'; });
- overlay.addEventListener('click', (e) => {
- if (e.target === overlay || e.target === bigImg) {
- closeOverlay();
- }
- });
- window.addEventListener('keydown', (e) => {
- if (overlay.style.display === 'flex') {
- if (e.key === 'ArrowLeft') updateImage(currentIndex - 1);
- if (e.key === 'ArrowRight') updateImage(currentIndex + 1);
- if (e.key === 'Escape') closeOverlay();
- }
- });
- // 4. WYKRYWANIE KLIKNIĘĆ W SKLEPIE
- window.addEventListener('click', function(e) {
- const target = e.target.closest('img');
- if (!target) return;
- if (target.src.includes('googleusercontent.com')) {
- // Szukamy kontenera galerii (zazwyczaj role="list")
- const parent = target.closest('[role="list"]') || target.parentElement.parentElement;
- const allImgs = Array.from(parent.querySelectorAll('img[src*="googleusercontent.com"]'));
- if (allImgs.length > 0) {
- e.preventDefault();
- e.stopPropagation();
- e.stopImmediatePropagation();
- galleryImages = allImgs.map(img => img.src);
- currentIndex = allImgs.indexOf(target);
- overlay.style.display = 'flex';
- updateImage(currentIndex);
- }
- }
- }, true);
- })();
Advertisement
Add Comment
Please, Sign In to add comment