// ==UserScript== // @name AliExpress Product Link Fixer // @namespace http://tampermonkey.net/ // @version 2.0 // @license MIT // @description Enhance your AliExpress shopping experience by converting marketing links into direct product links, ensuring each product is easily accessible with a single click. // @author NewsGuyTor // @match https://*.aliexpress.com/* // @icon https://www.aliexpress.com/favicon.ico // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Initialize the MutationObserver let observer; // Main function to fix links function fixLinks() { // Temporarily disconnect the observer to prevent infinite loops if (observer) observer.disconnect(); try { removeMarketingAnchors(); rewriteAnchorsWithProductIds(); fixOrCreateLinksForDataProducts(); } catch (err) { console.error("[AliExpress Product Link Fixer v2] Error in fixLinks():", err); } // Reconnect the observer after making changes if (observer) observer.observe(document.body, { childList: true, subtree: true }); } /** * A) Remove "marketing" anchors that have /gcp/ or /ssr/ without ?productIds=... * Then unwrap them to expose individual product blocks */ function removeMarketingAnchors() { const anchors = document.querySelectorAll('a[href*="/gcp/"]:not([data-alifix-done]), a[href*="/ssr/"]:not([data-alifix-done])'); anchors.forEach(a => { if (a.dataset.alifixDone) return; // Skip already processed anchors const url = new URL(a.href); if (!url.searchParams.has('productIds')) { // Mark the anchor as processed a.dataset.alifixDone = "1"; // Remove the anchor but keep its children in the DOM unwrapAnchor(a); } }); } /** * B) Rewrite anchors that contain ?productIds=... to direct product pages */ function rewriteAnchorsWithProductIds() { const anchors = document.querySelectorAll('a[href*="/gcp/"]:not([data-alifix-done]), a[href*="/ssr/"]:not([data-alifix-done])'); anchors.forEach(a => { if (a.dataset.alifixDone) return; // Skip already processed anchors const url = new URL(a.href); const pid = url.searchParams.get('productIds'); if (pid) { a.href = `https://${url.host}/item/${pid}.html`; a.dataset.alifixDone = "1"; // Mark as processed } }); } /** * C) Ensure each