Open link in new tab in GitHub

Ensures all <a> tags on GitHub Pages open in a new tab

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Open link in new tab in GitHub
// @name:zh-CN   在新标签页中打开链接[Github]
// @namespace    http://tampermonkey.net/
// @version      0.1
// @license MIT
// @description  Ensures all <a> tags on GitHub Pages open in a new tab
// @description:zh-CN  确保 GitHub Pages 上的所有 <a> 标签在新标签页中打开
// @author       wxupjack
// @match        *://*.githubpages.com/*
// @match        *://*.github.com/*
// @grant        none

// ==/UserScript==

(function() {
    'use strict';
    function updateLinks() {
        // Select all <a> tags
        const links = document.querySelectorAll('a');
        //console.log('all modified <a> tags:', links);

        links.forEach(link => {
            link.setAttribute('target', '_blank');
        });
    }

    // Run after the page is loaded
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        updateLinks();
    } else {
        window.addEventListener('DOMContentLoaded', updateLinks);
    }

    // Optional: Also update links if DOM is dynamically changed (for SPAs or AJAX navigation)
    const observer = new MutationObserver(updateLinks);
    observer.observe(document.body, { childList: true, subtree: true });

})();

// LLM prompt
// Create a Tampermonkey script for me:
// Domain: All GitHub Pages
// Goal: Add `target="_blank"` to all `<a>` tags on the page
// 1. Get the source code after the page loads
// 2. Find all <a> tags
// 3. Add/modify the target to _blank