Guest User

Untitled

a guest
Mar 12th, 2026
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.86 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Make Prisjakt Great Again
  3. // @namespace http://tampermonkey.net/
  4. // @version 14.0
  5. // @description
  6. // @author
  7. // @match *://*.prisjakt.nu/produkt.php*
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // ==========================================
  16. // 1. CLICK COST INTERCEPTOR (INJECTED)
  17. // ==========================================
  18. const injectedCode = `
  19. const originalFetch = window.fetch;
  20. window.fetch = async function(...args) {
  21. const response = await originalFetch.apply(this, args);
  22. let url = typeof args[0] === 'string' ? args[0] : (args[0] && args[0].url ? args[0].url : '');
  23.  
  24. if (url.includes('_internal/click-data/offer/')) {
  25. response.clone().json().then(data => {
  26. if (data.segmentCostPerClick !== undefined) {
  27. window.postMessage({
  28. type: 'PRISJAKT_CLICK_COST',
  29. cost: data.segmentCostPerClick,
  30. currency: data.segmentCostCurrency,
  31. shopName: data.shopName
  32. }, '*');
  33. }
  34. }).catch(e => console.error('Tampermonkey: Could not parse click data', e));
  35. }
  36. return response;
  37. };
  38.  
  39. const originalXhrOpen = XMLHttpRequest.prototype.open;
  40. XMLHttpRequest.prototype.open = function(method, url) {
  41. this.addEventListener('load', function() {
  42. if (typeof url === 'string' && url.includes('_internal/click-data/offer/')) {
  43. try {
  44. const data = JSON.parse(this.responseText);
  45. if (data.segmentCostPerClick !== undefined) {
  46. window.postMessage({
  47. type: 'PRISJAKT_CLICK_COST',
  48. cost: data.segmentCostPerClick,
  49. currency: data.segmentCostCurrency,
  50. shopName: data.shopName
  51. }, '*');
  52. }
  53. } catch(e) {}
  54. }
  55. });
  56. originalXhrOpen.apply(this, arguments);
  57. };
  58. `;
  59.  
  60. const script = document.createElement('script');
  61. script.textContent = injectedCode;
  62. (document.head || document.documentElement).appendChild(script);
  63. script.remove();
  64.  
  65. // ==========================================
  66. // 2. NOTIFICATION CONTAINER & UI
  67. // ==========================================
  68. const container = document.createElement('div');
  69. container.id = 'pj-cost-container';
  70. container.style.cssText = 'position: fixed; bottom: 30px; right: 30px; display: flex; flex-direction: column; gap: 10px; z-index: 9999999; pointer-events: none;';
  71.  
  72. const initContainer = setInterval(() => {
  73. if (document.body) {
  74. document.body.appendChild(container);
  75. clearInterval(initContainer);
  76. }
  77. }, 50);
  78.  
  79. window.addEventListener('message', function(event) {
  80. if (event.source === window && event.data && event.data.type === 'PRISJAKT_CLICK_COST') {
  81. showModal(event.data.cost, event.data.currency, event.data.shopName);
  82. }
  83. });
  84.  
  85. function checkLinkClick(e) {
  86. if (e.button === 1 || (e.button === 0 && (e.ctrlKey || e.metaKey))) {
  87. const link = e.target.closest('a');
  88. if (link && link.href.includes('/go-to-shop/')) {
  89. const match = link.href.match(/\/go-to-shop\/(\d+)\/offer\/(\d+)/);
  90. if (match) {
  91. const shopId = match[1];
  92. const offerId = match[2];
  93. const apiUrl = `https://www.prisjakt.nu/_internal/click-data/offer/${shopId}-${offerId}`;
  94.  
  95. fetch(apiUrl)
  96. .then(res => res.json())
  97. .then(data => {
  98. if (data.segmentCostPerClick !== undefined) {
  99. showModal(data.segmentCostPerClick, data.segmentCostCurrency, data.shopName);
  100. }
  101. }).catch(e => console.error('Tampermonkey fetch failed:', e));
  102. }
  103. }
  104. }
  105. }
  106.  
  107. document.addEventListener('auxclick', checkLinkClick);
  108. document.addEventListener('click', checkLinkClick);
  109.  
  110. function showModal(cost, currency, shopName) {
  111. const modal = document.createElement('div');
  112. modal.style.backgroundColor = 'rgba(25, 30, 36, 0.95)';
  113. modal.style.color = '#fff';
  114. modal.style.padding = '15px 25px';
  115. modal.style.borderRadius = '8px';
  116. modal.style.boxShadow = '0 10px 25px rgba(0,0,0,0.3)';
  117. modal.style.fontFamily = 'system-ui, -apple-system, sans-serif';
  118. modal.style.fontSize = '16px';
  119. modal.style.borderLeft = '5px solid #ff6900';
  120. modal.style.transition = 'opacity 0.4s ease-in-out, transform 0.4s ease-in-out';
  121. modal.style.opacity = '0';
  122. modal.style.transform = 'translateY(10px)';
  123.  
  124. modal.innerHTML = `<strong>${shopName}</strong> paid <strong>${cost} ${currency}</strong>`;
  125.  
  126. container.insertBefore(modal, container.firstChild);
  127.  
  128. requestAnimationFrame(() => {
  129. modal.style.opacity = '1';
  130. modal.style.transform = 'translateY(0)';
  131. });
  132.  
  133. setTimeout(() => {
  134. modal.style.opacity = '0';
  135. modal.style.transform = 'translateY(10px)';
  136. setTimeout(() => modal.remove(), 400);
  137. }, 60000);
  138. }
  139.  
  140. // ==========================================
  141. // 3. AUTO-EXPAND & DEAD LINK FIXER
  142. // ==========================================
  143. function processDOMFixes() {
  144. // --- 3A. Auto-Expand ---
  145. const expandBtn = document.querySelector('div[role="button"][aria-label*="utan direktlänk"]:not([data-pj-auto-expanded])');
  146. if (expandBtn) {
  147. expandBtn.setAttribute('data-pj-auto-expanded', 'true');
  148. expandBtn.click();
  149. }
  150.  
  151. // --- 3B. Fix Dead Store Links ---
  152. const disabledLinks = document.querySelectorAll('a[disabled]:not([data-pj-search-linked])');
  153.  
  154. disabledLinks.forEach(link => {
  155. const row = link.closest('li');
  156. if (!row) return;
  157.  
  158. const storeSpan = row.querySelector('span[class*="StoreInfoTitle"]');
  159. const storeName = storeSpan ? storeSpan.innerText.trim() : '';
  160.  
  161. const productTitleEl = document.querySelector('[data-test="ProductTitle"] h1');
  162. const productName = productTitleEl ? productTitleEl.innerText.trim() : '';
  163.  
  164. if (storeName && productName) {
  165. const searchQuery = `${storeName} ${productName}`;
  166. const searchUrl = `https://www.google.se/search?q=${encodeURIComponent(searchQuery)}&btnI=1`;
  167.  
  168. // 1. Fix HTML attributes and re-enable pointer interactions
  169. link.href = searchUrl;
  170. link.target = '_blank';
  171. link.removeAttribute('disabled');
  172. link.style.pointerEvents = 'auto'; // CRITICAL: Allows the mouse to click the link
  173. link.style.cursor = 'pointer';
  174.  
  175. // Mark as processed to avoid infinite loops
  176. link.setAttribute('data-pj-search-linked', 'true');
  177.  
  178. // 2. Change the button text and enable pointer interactions
  179. const btn = link.querySelector('button');
  180. if (btn) {
  181. btn.removeAttribute('disabled');
  182. btn.style.pointerEvents = 'auto'; // CRITICAL: Allows the mouse to click the button
  183. btn.style.cursor = 'pointer';
  184. const btnText = btn.querySelector('span[class*="StyledText"], span[title=""]');
  185. if (btnText) {
  186. btnText.innerText = 'Sök butik';
  187. }
  188. }
  189.  
  190. // 3. Brute Force Click Override to bypass React's event cancellation
  191. link.addEventListener('click', function(e) {
  192. e.preventDefault();
  193. e.stopPropagation();
  194. window.open(searchUrl, '_blank');
  195. }, true);
  196. }
  197. });
  198. }
  199.  
  200. function setupObservers() {
  201. const observer = new MutationObserver((mutations) => {
  202. processDOMFixes();
  203. });
  204.  
  205. const startObserving = setInterval(() => {
  206. if (document.body) {
  207. observer.observe(document.body, { childList: true, subtree: true });
  208. clearInterval(startObserving);
  209. }
  210. }, 50);
  211. }
  212.  
  213. setupObservers();
  214.  
  215. })();
Advertisement
Add Comment
Please, Sign In to add comment