Wikipedia AI + Google Button

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

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

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