File size: 6,323 Bytes
110d062
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>URL Parser & Screenshot Tool</title>
    <style>

        * {

            margin: 0;

            padding: 0;

            box-sizing: border-box;

        }



        body {

            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;

            line-height: 1.6;

            padding: 2rem;

            max-width: 1200px;

            margin: 0 auto;

            background-color: #f5f5f5;

        }



        .container {

            background-color: white;

            padding: 2rem;

            border-radius: 8px;

            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

        }



        h1 {

            color: #333;

            margin-bottom: 1.5rem;

            text-align: center;

        }



        .input-group {

            margin-bottom: 2rem;

        }



        #inputBox {

            width: 100%;

            padding: 0.8rem;

            font-size: 1rem;

            border: 2px solid #ddd;

            border-radius: 4px;

            transition: border-color 0.3s;

        }



        #inputBox:focus {

            outline: none;

            border-color: #007bff;

        }



        #urls {

            display: flex;

            flex-direction: column;

            gap: 0.8rem;

        }



        #urls a {

            color: #007bff;

            text-decoration: none;

            padding: 0.5rem;

            background-color: #f8f9fa;

            border-radius: 4px;

            transition: background-color 0.3s;

        }



        #urls a:hover {

            background-color: #e9ecef;

            text-decoration: underline;

        }



        .screenshot-btn {

            display: inline-block;

            padding: 0.4rem 0.8rem;

            margin-left: 0.5rem;

            background-color: #28a745;

            color: white;

            border: none;

            border-radius: 4px;

            cursor: pointer;

            font-size: 0.9rem;

            transition: background-color 0.3s;

        }



        .screenshot-btn:hover {

            background-color: #218838;

        }



        .preview-container {

            margin-top: 1rem;

            border: 1px solid #ddd;

            border-radius: 4px;

            overflow: hidden;

        }



        .preview-image {

            max-width: 100%;

            height: auto;

            display: block;

        }



        .loading {

            text-align: center;

            padding: 2rem;

            color: #666;

        }

    </style>
</head>
<body>
    <div class="container">
        <h1>URL 解析 & 截图工具</h1>
        <div class="input-group">
            <input type="text" 

                   id="inputBox" 

                   placeholder="粘贴包含URL的文本..."

                   onblur="parseUrls()" 

                   onchange="parseUrls()">
        </div>
        <div id="urls"></div>
        <div id="preview-container" class="preview-container" style="display: none;">
            <div id="loading" class="loading">加载中...</div>
            <img id="preview-image" class="preview-image" style="display: none;">
        </div>
    </div>

    <script>

        async function takeScreenshot(url) {

            const previewContainer = document.getElementById('preview-container');

            const loading = document.getElementById('loading');

            const previewImage = document.getElementById('preview-image');

            

            previewContainer.style.display = 'block';

            loading.style.display = 'block';

            previewImage.style.display = 'none';



            try {

                const response = await fetch(`/screenshot?url=${encodeURIComponent(url)}`);

                if (response.ok) {

                    const blob = await response.blob();

                    const imageUrl = URL.createObjectURL(blob);

                    previewImage.src = imageUrl;

                    previewImage.style.display = 'block';

                } else {

                    loading.textContent = '截图失败,请重试';

                }

            } catch (error) {

                loading.textContent = '截图失败,请重试';

            } finally {

                loading.style.display = 'none';

            }

        }



        function parseUrls() {

            const inputBox = document.getElementById('inputBox');

            const pastedText = inputBox.value;

            const urlPattern = /(\b(?:https?:\/\/)?(?:[\da-z\.-]+)\.(?:[a-z\.]{2,6})(?:[\/\w\.-]*)*\/?(?:\?[^\s]*)?)/gi;

            const urls = pastedText.match(urlPattern);



            if (urls) {

                const urlsContainer = document.getElementById('urls');

                urlsContainer.innerHTML = '';



                urls.forEach(url => {

                    let fullUrl = url;

                    if (!/^https?:\/\//i.test(url)) {

                        fullUrl = 'https://' + url;

                    }

                    

                    const urlContainer = document.createElement('div');

                    urlContainer.style.display = 'flex';

                    urlContainer.style.alignItems = 'center';

                    

                    const linkElement = document.createElement('a');

                    linkElement.href = fullUrl;

                    linkElement.textContent = fullUrl;

                    linkElement.target = '_blank';

                    

                    const screenshotBtn = document.createElement('button');

                    screenshotBtn.textContent = '截图';

                    screenshotBtn.className = 'screenshot-btn';

                    screenshotBtn.onclick = () => {

                        takeScreenshot(fullUrl);

                    };

                    

                    urlContainer.appendChild(linkElement);

                    urlContainer.appendChild(screenshotBtn);

                    urlsContainer.appendChild(urlContainer);

                });

            }

        }

    </script>
</body>
</html>