Visual Search Only

redirects every pinterest pin to visual search

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Visual Search Only
// @version      1.0
// @description  redirects every pinterest pin to visual search
// @author       Audino
// @namespace   https://greasyfork.org/en/users/1501652-audino
// @match        *://*.pinterest.com/*
// @license MIT
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const pinUrlRegex = /(\/pin\/\d+)/;

    const modifyLink = (linkElement) => {
        if (linkElement && linkElement.href && !linkElement.dataset.vsModified) {
            const match = linkElement.href.match(pinUrlRegex);
            if (match) {
                const baseUrl = new URL(linkElement.href).origin;
                const newUrl = `${baseUrl}${match[0]}/visual-search/`;
                linkElement.href = newUrl;
                linkElement.dataset.vsModified = 'true';
            }
        }
    };

    document.addEventListener('mouseover', (event) => {
        const linkElement = event.target.closest('a[href*="/pin/"]');
        if (linkElement) {
            modifyLink(linkElement);
        }
    }, true);

    document.addEventListener('click', function(event) {
        if (event.button !== 0) return;

        const linkElement = event.target.closest('a[href*="/pin/"]');
        if (linkElement && linkElement.href && linkElement.href.includes('/pin/')) {
            event.preventDefault();
            event.stopPropagation();
            event.stopImmediatePropagation();
            window.location.href = linkElement.href;
        }
    }, true);

})();