Google Image Search on Ptt

Add Google image search buttons on Ptt.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Google Image Search on Ptt
// @namespace    https://wiki.gslin.org/wiki/GoogleImageSearchOnPtt
// @version      0.20231226.0
// @description  Add Google image search buttons on Ptt.
// @author       Gea-Suan Lin <[email protected]>
// @match        https://www.ptt.cc/bbs/*/*.html
// @grant        GM_openInTab
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function ev() {
        let img_re = new RegExp('\.(gif|jpeg|jpg|png|webp)$');
        let timeout = 0;

        document.querySelectorAll('#main-content img').forEach(function(el) {
            const img_url = el.getAttribute('href') || el.getAttribute('src');
            if (!img_url.match(img_re)) {
                return;
            }

            let url = 'https://lens.google.com/uploadbyurl?url=' + encodeURIComponent(img_url);
            setTimeout(function() {
                GM_openInTab(url, true);
            }, timeout);
            timeout += 1500;
        });
    };

    let btn = document.createElement('button');
    btn.addEventListener('click', ev);
    btn.innerHTML = 'Google Image Search';
    btn.setAttribute('style', 'height: 1.5em; margin-bottom: 3px; vertical-align: text-bottom;');
    document.querySelectorAll('.article-metaline')[2].appendChild(btn);
})();