Google Image Search on Ptt

Add Google image search buttons on Ptt.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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);
})();