Wikipedia AI + Google Button

Adds "AI" and "Google" buttons next to Wikipedia article titles for quick searches.

スクリプトをインストールするには、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         Wikipedia AI + Google Button
// @namespace    http://tampermonkey.net/
// @version      1.31
// @description  Adds "AI" and "Google" buttons next to Wikipedia article titles for quick searches.
// @author       DoctorEye
// @match        https://*.wikipedia.org/wiki/*
// @license MIT
// @grant        none
// ==/UserScript==
 
(function() {
    'use strict';
 
    // Βρίσκουμε το container του τίτλου
    const firstHeading = document.querySelector('#firstHeading');
    if (!firstHeading) return;
 
    // Προσπαθούμε πρώτα το span (νέος τρόπος)
    let titleElement = firstHeading.querySelector('.mw-page-title-main');
 
    // Αν δεν βρεθεί → παίρνουμε όλο το κείμενο του h1 και το καθαρίζουμε
    let pageTitle;
    if (titleElement) {
        pageTitle = titleElement.textContent.trim();
    } else {
        // Αφαίρεση edit link text αν υπάρχει (συχνά "[edit]" ή κενά)
        pageTitle = firstHeading.textContent
            .replace(/\s*\[edit\]\s*/gi, '')   // αφαιρεί [edit] links
            .replace(/\s+/g, ' ')              // πολλαπλά κενά → ένα
            .trim();
    }
 
    if (!pageTitle) return; // safety check
 
    // Προαιρετικό: αφαίρεση (parenthetical disambiguation) από το query
    // π.χ. "The Sixth Sense (film)" → "The Sixth Sense"
    // Αφαίρεσε τα // μπροστά από τις γραμμές αν το θες
    // const cleanTitle = pageTitle.replace(/\s*\([^)]+\)$/, '').trim();
    // const query = encodeURIComponent(cleanTitle);
 
    const query = encodeURIComponent(pageTitle);
 
    // Δημιουργία κουμπιού AI
    const aiButton = document.createElement('button');
    aiButton.textContent = 'AI';
    aiButton.style.backgroundColor = '#4CAF50';
    aiButton.style.color = 'white';
    aiButton.style.border = 'none';
    aiButton.style.padding = '2px 6px';
    aiButton.style.marginLeft = '10px';
    aiButton.style.fontSize = '14px';
    aiButton.style.cursor = 'pointer';
    aiButton.style.borderRadius = '3px';
    aiButton.addEventListener('click', () => {
        window.open(`https://google.com/ai?q=${query}`, '_blank');
    });
 
    // Δημιουργία κουμπιού Google (με hl=el όπως είχες)
    const googleButton = document.createElement('button');
    googleButton.textContent = 'G';
    googleButton.style.backgroundColor = '#4285F4';
    googleButton.style.color = 'white';
    googleButton.style.border = 'none';
    googleButton.style.padding = '2px 6px';
    googleButton.style.marginLeft = '5px';
    googleButton.style.fontSize = '14px';
    googleButton.style.cursor = 'pointer';
    googleButton.style.borderRadius = '3px';
    googleButton.addEventListener('click', () => {
        window.open(`http://www.google.com/search?hl=el&safe=off&q=${query}`, '_blank');
    });
 
    // Εισαγωγή κουμπιών **μετά** τον τίτλο (στο τέλος του firstHeading)
    firstHeading.appendChild(aiButton);
    firstHeading.appendChild(googleButton);
 
    // Προαιρετικό: μικρή βελτίωση εμφάνισης (τα κουμπιά να είναι inline με τον τίτλο)
    firstHeading.style.display = 'flex';
    firstHeading.style.alignItems = 'center';
    firstHeading.style.flexWrap = 'wrap';
})();