Visual Search Only

redirects every pinterest pin to visual search

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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

})();