Guest User

Untitled

a guest
Jun 14th, 2024
2,783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         OLX Full Resolution Images
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.4
  5. // @description  Replace OLX images with full resolution versions and add a button to preview full resolution images
  6. // @author       Kordian
  7. // @match        https://www.olx.pl/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     // Function to update image URLs
  15.     function updateImageUrls() {
  16.         // Select all image elements on the page
  17.         const images = document.querySelectorAll('img[src*=";s="]');
  18.  
  19.         images.forEach(img => {
  20.             // Store the original URL in a data attribute
  21.             img.dataset.originalSrc = img.src;
  22.             // Modify the image URL to replace the size parameter with 0x0 for full resolution
  23.             img.src = img.src.replace(/;s=\d+x\d+/, ';s=0x0');
  24.         });
  25.     }
  26.  
  27.     // Create the preview button
  28.     function createPreviewButton() {
  29.         const button = document.createElement('div');
  30.         button.textContent = 'Pokaż galerię ogłoszenia';
  31.         button.style.position = 'fixed';
  32.         button.style.bottom = '10px';
  33.         button.style.left = '10px';
  34.         button.style.padding = '10px 20px';
  35.         button.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  36.         button.style.color = '#fff';
  37.         button.style.borderRadius = '10px';
  38.         button.style.cursor = 'pointer';
  39.         button.style.zIndex = '1000';
  40.         button.style.fontSize = '14px';
  41.         button.style.textAlign = 'center';
  42.         button.style.boxShadow = '0px 4px 6px rgba(0, 0, 0, 0.1)';
  43.         document.body.appendChild(button);
  44.  
  45.  
  46.         const previewContainer = document.createElement('div');
  47.         previewContainer.style.position = 'fixed';
  48.         previewContainer.style.top = '50%';
  49.         previewContainer.style.left = '50%';
  50.         previewContainer.style.transform = 'translate(-50%, -50%)';
  51.         previewContainer.style.maxHeight = '80vh';
  52.         previewContainer.style.maxWidth = '80vw';
  53.         previewContainer.style.overflow = 'auto';
  54.         previewContainer.style.display = 'none';
  55.         previewContainer.style.zIndex = '1001';
  56.         previewContainer.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
  57.         previewContainer.style.padding = '20px';
  58.         previewContainer.style.borderRadius = '10px';
  59.         document.body.appendChild(previewContainer);
  60.  
  61.         button.addEventListener('click', () => {
  62.             const images = document.querySelectorAll('img[src*=";s=0x0"]');
  63.             previewContainer.innerHTML = '';
  64.             images.forEach(img => {
  65.                 const previewImage = document.createElement('img');
  66.                 previewImage.src = img.dataset.originalSrc.replace(/;s=\d+x\d+/, ';s=0x0');
  67.                 previewImage.style.maxHeight = '80vh';
  68.                 previewImage.style.maxWidth = '80vw';
  69.                 previewImage.style.margin = '10px';
  70.                 previewContainer.appendChild(previewImage);
  71.             });
  72.             previewContainer.style.display = 'block';
  73.         });
  74.  
  75.         // Hide preview container when clicking outside of it
  76.         document.addEventListener('click', (event) => {
  77.             if (!previewContainer.contains(event.target) && event.target !== button) {
  78.                 previewContainer.style.display = 'none';
  79.             }
  80.         });
  81.     }
  82.  
  83.     // Run the update function initially
  84.     updateImageUrls();
  85.  
  86.     // Set up a mutation observer to catch dynamically loaded images
  87.     const observer = new MutationObserver(updateImageUrls);
  88.     observer.observe(document.body, { childList: true, subtree: true });
  89.  
  90.     // Create the preview button
  91.     createPreviewButton();
  92. })();
  93.  
Advertisement
Add Comment
Please, Sign In to add comment