Visual Search Only

redirects every pinterest pin to visual search

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Advertisement:

// ==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);

})();