External Link Highlighter

Tô sáng các liên kết ngoài (external links) trên trang web để bạn dễ nhận biết khi click.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         External Link Highlighter
// @namespace    https://greasyfork.org/users/your-username
// @version      1.0
// @description  Tô sáng các liên kết ngoài (external links) trên trang web để bạn dễ nhận biết khi click.
// @author       YourName
// @license      MIT
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Lấy domain hiện tại
    const currentDomain = location.hostname;

    // Chọn tất cả thẻ <a> có thuộc tính href
    const links = document.querySelectorAll('a[href]');

    links.forEach(link => {
        try {
            const url = new URL(link.href);

            // Nếu domain khác domain hiện tại -> là link ngoài
            if (url.hostname !== currentDomain) {
                link.style.backgroundColor = '#fff3cd';
                link.style.border = '1px solid #ffcc00';
                link.style.padding = '2px 4px';
                link.title = 'External link: ' + url.hostname;
            }
        } catch (e) {
            // Bỏ qua các href không hợp lệ
        }
    });
})();