Wikipedia AI + Google Button

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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