Greasy Fork

Auto Show Decoded URL

显示解码后的 URL,方便手动复制到地址栏

目前为 2024-09-29 提交的版本。查看 最新版本

// ==UserScript==
// @name         Auto Show Decoded URL
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  显示解码后的 URL,方便手动复制到地址栏
// @author       你
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function () {
        // 解码当前 URL
        var decodedURL = decodeURIComponent(window.location.href);
        console.log('Decoded URL:', decodedURL);

        // 检查解码后的 URL 是否与原始 URL 不同
        if (decodedURL !== window.location.href) {
            // 在页面顶部显示解码后的 URL
            let displayDiv = document.createElement('div');
            displayDiv.style.position = 'fixed';
            displayDiv.style.top = '0';
            displayDiv.style.left = '0';
            displayDiv.style.width = '100%';
            displayDiv.style.backgroundColor = '#f0f0f0';
            displayDiv.style.padding = '10px';
            displayDiv.style.zIndex = '9999';
            displayDiv.style.textAlign = 'center';
            displayDiv.style.borderBottom = '2px solid #ccc';

            // 添加解码后的 URL 和提示文本
            displayDiv.innerHTML = `<strong>解码后的 URL:</strong> <input type="text" value="${decodedURL}" style="width:80%;" id="decoded-url"> <button id="copy-url">复制</button>`;

            // 将显示框添加到页面
            document.body.appendChild(displayDiv);

            // 添加复制功能
            document.getElementById('copy-url').addEventListener('click', function() {
                let urlInput = document.getElementById('decoded-url');
                urlInput.select();
                document.execCommand('copy');
                alert('解码后的 URL 已复制到剪贴板,请粘贴到地址栏中。');
            });
        }
    });
})();