Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Make Prisjakt Great Again
- // @namespace http://tampermonkey.net/
- // @version 14.0
- // @description
- // @author
- // @match *://*.prisjakt.nu/produkt.php*
- // @grant none
- // @run-at document-start
- // ==/UserScript==
- (function() {
- 'use strict';
- // ==========================================
- // 1. CLICK COST INTERCEPTOR (INJECTED)
- // ==========================================
- const injectedCode = `
- const originalFetch = window.fetch;
- window.fetch = async function(...args) {
- const response = await originalFetch.apply(this, args);
- let url = typeof args[0] === 'string' ? args[0] : (args[0] && args[0].url ? args[0].url : '');
- if (url.includes('_internal/click-data/offer/')) {
- response.clone().json().then(data => {
- if (data.segmentCostPerClick !== undefined) {
- window.postMessage({
- type: 'PRISJAKT_CLICK_COST',
- cost: data.segmentCostPerClick,
- currency: data.segmentCostCurrency,
- shopName: data.shopName
- }, '*');
- }
- }).catch(e => console.error('Tampermonkey: Could not parse click data', e));
- }
- return response;
- };
- const originalXhrOpen = XMLHttpRequest.prototype.open;
- XMLHttpRequest.prototype.open = function(method, url) {
- this.addEventListener('load', function() {
- if (typeof url === 'string' && url.includes('_internal/click-data/offer/')) {
- try {
- const data = JSON.parse(this.responseText);
- if (data.segmentCostPerClick !== undefined) {
- window.postMessage({
- type: 'PRISJAKT_CLICK_COST',
- cost: data.segmentCostPerClick,
- currency: data.segmentCostCurrency,
- shopName: data.shopName
- }, '*');
- }
- } catch(e) {}
- }
- });
- originalXhrOpen.apply(this, arguments);
- };
- `;
- const script = document.createElement('script');
- script.textContent = injectedCode;
- (document.head || document.documentElement).appendChild(script);
- script.remove();
- // ==========================================
- // 2. NOTIFICATION CONTAINER & UI
- // ==========================================
- const container = document.createElement('div');
- container.id = 'pj-cost-container';
- container.style.cssText = 'position: fixed; bottom: 30px; right: 30px; display: flex; flex-direction: column; gap: 10px; z-index: 9999999; pointer-events: none;';
- const initContainer = setInterval(() => {
- if (document.body) {
- document.body.appendChild(container);
- clearInterval(initContainer);
- }
- }, 50);
- window.addEventListener('message', function(event) {
- if (event.source === window && event.data && event.data.type === 'PRISJAKT_CLICK_COST') {
- showModal(event.data.cost, event.data.currency, event.data.shopName);
- }
- });
- function checkLinkClick(e) {
- if (e.button === 1 || (e.button === 0 && (e.ctrlKey || e.metaKey))) {
- const link = e.target.closest('a');
- if (link && link.href.includes('/go-to-shop/')) {
- const match = link.href.match(/\/go-to-shop\/(\d+)\/offer\/(\d+)/);
- if (match) {
- const shopId = match[1];
- const offerId = match[2];
- const apiUrl = `https://www.prisjakt.nu/_internal/click-data/offer/${shopId}-${offerId}`;
- fetch(apiUrl)
- .then(res => res.json())
- .then(data => {
- if (data.segmentCostPerClick !== undefined) {
- showModal(data.segmentCostPerClick, data.segmentCostCurrency, data.shopName);
- }
- }).catch(e => console.error('Tampermonkey fetch failed:', e));
- }
- }
- }
- }
- document.addEventListener('auxclick', checkLinkClick);
- document.addEventListener('click', checkLinkClick);
- function showModal(cost, currency, shopName) {
- const modal = document.createElement('div');
- modal.style.backgroundColor = 'rgba(25, 30, 36, 0.95)';
- modal.style.color = '#fff';
- modal.style.padding = '15px 25px';
- modal.style.borderRadius = '8px';
- modal.style.boxShadow = '0 10px 25px rgba(0,0,0,0.3)';
- modal.style.fontFamily = 'system-ui, -apple-system, sans-serif';
- modal.style.fontSize = '16px';
- modal.style.borderLeft = '5px solid #ff6900';
- modal.style.transition = 'opacity 0.4s ease-in-out, transform 0.4s ease-in-out';
- modal.style.opacity = '0';
- modal.style.transform = 'translateY(10px)';
- modal.innerHTML = `<strong>${shopName}</strong> paid <strong>${cost} ${currency}</strong>`;
- container.insertBefore(modal, container.firstChild);
- requestAnimationFrame(() => {
- modal.style.opacity = '1';
- modal.style.transform = 'translateY(0)';
- });
- setTimeout(() => {
- modal.style.opacity = '0';
- modal.style.transform = 'translateY(10px)';
- setTimeout(() => modal.remove(), 400);
- }, 60000);
- }
- // ==========================================
- // 3. AUTO-EXPAND & DEAD LINK FIXER
- // ==========================================
- function processDOMFixes() {
- // --- 3A. Auto-Expand ---
- const expandBtn = document.querySelector('div[role="button"][aria-label*="utan direktlänk"]:not([data-pj-auto-expanded])');
- if (expandBtn) {
- expandBtn.setAttribute('data-pj-auto-expanded', 'true');
- expandBtn.click();
- }
- // --- 3B. Fix Dead Store Links ---
- const disabledLinks = document.querySelectorAll('a[disabled]:not([data-pj-search-linked])');
- disabledLinks.forEach(link => {
- const row = link.closest('li');
- if (!row) return;
- const storeSpan = row.querySelector('span[class*="StoreInfoTitle"]');
- const storeName = storeSpan ? storeSpan.innerText.trim() : '';
- const productTitleEl = document.querySelector('[data-test="ProductTitle"] h1');
- const productName = productTitleEl ? productTitleEl.innerText.trim() : '';
- if (storeName && productName) {
- const searchQuery = `${storeName} ${productName}`;
- const searchUrl = `https://www.google.se/search?q=${encodeURIComponent(searchQuery)}&btnI=1`;
- // 1. Fix HTML attributes and re-enable pointer interactions
- link.href = searchUrl;
- link.target = '_blank';
- link.removeAttribute('disabled');
- link.style.pointerEvents = 'auto'; // CRITICAL: Allows the mouse to click the link
- link.style.cursor = 'pointer';
- // Mark as processed to avoid infinite loops
- link.setAttribute('data-pj-search-linked', 'true');
- // 2. Change the button text and enable pointer interactions
- const btn = link.querySelector('button');
- if (btn) {
- btn.removeAttribute('disabled');
- btn.style.pointerEvents = 'auto'; // CRITICAL: Allows the mouse to click the button
- btn.style.cursor = 'pointer';
- const btnText = btn.querySelector('span[class*="StyledText"], span[title=""]');
- if (btnText) {
- btnText.innerText = 'Sök butik';
- }
- }
- // 3. Brute Force Click Override to bypass React's event cancellation
- link.addEventListener('click', function(e) {
- e.preventDefault();
- e.stopPropagation();
- window.open(searchUrl, '_blank');
- }, true);
- }
- });
- }
- function setupObservers() {
- const observer = new MutationObserver((mutations) => {
- processDOMFixes();
- });
- const startObserving = setInterval(() => {
- if (document.body) {
- observer.observe(document.body, { childList: true, subtree: true });
- clearInterval(startObserving);
- }
- }, 50);
- }
- setupObservers();
- })();
Advertisement
Add Comment
Please, Sign In to add comment