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.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

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