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.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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