本地版简易url解码小工具

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>URL 解码工具</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            padding: 20px;
            background-color: #f7f7f7;
        }
        .container {
            max-width: 800px;
            margin: auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
        }
        h2 {
            width: 100%;
            text-align: center;
        }
        .input-container {
            flex: 1 1 45%;
        }
        .textarea-container {
            flex: 1 1 100%;
        }
        textarea {
            width: 100%;
            height: 100px;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            resize: none;
        }
        button {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            color: #fff;
            background-color: #007BFF;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        #notification {
            visibility: hidden;
            min-width: 250px;
            margin-left: -125px;
            background-color: #4CAF50;
            color: white;
            text-align: center;
            border-radius: 2px;
            padding: 16px;
            position: fixed;
            z-index: 1;
            left: 50%;
            bottom: 30px;
            font-size: 17px;
        }
        #notification.show {
            visibility: visible;
            -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
            animation: fadein 0.5s, fadeout 0.5s 2.5s;
        }
        @-webkit-keyframes fadein {
            from {bottom: 0; opacity: 0;} 
            to {bottom: 30px; opacity: 1;}
        }
        @keyframes fadein {
            from {bottom: 0; opacity: 0;}
            to {bottom: 30px; opacity: 1;}
        }
        @-webkit-keyframes fadeout {
            from {bottom: 30px; opacity: 1;} 
            to {bottom: 0; opacity: 0;}
        }
        @keyframes fadeout {
            from {bottom: 30px; opacity: 1;}
            to {bottom: 0; opacity: 0;}
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>URL 解码工具</h2>
        <div class="input-container">
            <textarea id="encodedText" placeholder="在此输入 URL 编码的文本..."></textarea>
            <button onclick="decodeText()">解码</button>
        </div>
        <div class="textarea-container">
            <textarea id="decodedText" readonly placeholder="解码后的文本将在此显示..."></textarea>
            <button onclick="copyText()">复制</button>
        </div>
    </div>
    <div id="notification">已复制文本!</div>
    <script>
        function decodeText() {
            const encodedText = document.getElementById('encodedText').value;
            try {
                const decodedText = decodeURIComponent(encodedText);
                document.getElementById('decodedText').value = decodedText;
            } catch (e) {
                document.getElementById('decodedText').value = '无效的 URL 编码字符串';
            }
        }

        function copyText() {
            const decodedText = document.getElementById('decodedText');
            decodedText.select();
            decodedText.setSelectionRange(0, 99999); // 适用于移动设备
            document.execCommand('copy');
            showNotification();
        }

        function showNotification() {
            const notification = document.getElementById('notification');
            notification.className = 'show';
            setTimeout(() => {
                notification.className = notification.className.replace('show', '');
            }, 3000);
        }
    </script>
</body>
</html>

posted @ 2024-07-05 11:10  真哩迈  阅读(27)  评论(0)    收藏  举报