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.

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

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.

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

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

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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