Wikipedia AI + Google Button

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

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

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

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.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

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!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

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

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