-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaobaocleaner.html
More file actions
524 lines (470 loc) · 18.3 KB
/
Copy pathtaobaocleaner.html
File metadata and controls
524 lines (470 loc) · 18.3 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Taobao Link Cleaner</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #ff5000;
text-align: center;
margin-bottom: 30px;
}
.input-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #333;
}
input, textarea {
width: 100%;
padding: 12px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 14px;
box-sizing: border-box;
}
textarea {
height: 80px;
resize: vertical;
font-family: monospace;
font-size: 12px;
}
button {
background-color: #ff5000;
color: white;
border: none;
padding: 12px 30px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
display: block;
margin: 0 auto;
transition: background-color 0.3s;
}
button:hover {
background-color: #e04800;
}
.result {
margin-top: 20px;
padding: 15px;
background-color: #f9f9f9;
border-radius: 5px;
border-left: 4px solid #ff5000;
display: none;
}
.result h3 {
margin-top: 0;
color: #333;
}
.copy-btn {
background-color: #4CAF50;
padding: 8px 15px;
font-size: 14px;
margin-top: 10px;
}
.copy-btn:hover {
background-color: #45a049;
}
.error {
color: #d32f2f;
margin-top: 10px;
display: none;
padding: 10px;
background-color: #ffebee;
border-radius: 5px;
border-left: 4px solid #d32f2f;
}
.info {
color: #666;
font-size: 12px;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Taobao Link Cleaner</h1>
<div class="input-group">
<label for="taobaoLink">Paste Taobao Share Link:</label>
<input type="text" id="taobaoLink" placeholder="https://e.tb.cn/xxxxx or https://s.click.taobao.com/xxxxx" />
<div class="info">Works with e.tb.cn, s.click.taobao.com, and other Taobao/Tmall share links</div>
</div>
<button onclick="processLink()">Clean Link</button>
<div id="error" class="error"></div>
<div id="result" class="result">
<h3>Cleaned Link:</h3>
<textarea id="cleanedLink" readonly></textarea>
<button class="copy-btn" onclick="copyToClipboard()">Copy to Clipboard</button>
</div>
<div style="margin-top: 30px; padding: 15px; background: #fff3e0; border-radius: 5px;">
<h4>How to use:</h4>
<ol>
<li>Copy the share link from Taobao app (long press on product → Share → Copy Link)</li>
<li>Paste it in the input field above</li>
<li>Click "Clean Link" to get the direct product URL</li>
</ol>
</div>
</div>
<script>
function processLink() {
const originalLink = document.getElementById('taobaoLink').value.trim();
const errorDiv = document.getElementById('error');
const resultDiv = document.getElementById('result');
// Hide previous results/errors
errorDiv.style.display = 'none';
resultDiv.style.display = 'none';
if (!originalLink) {
showError('Please enter a Taobao link');
return;
}
try {
// Extract item ID directly from the URL patterns
const cleanLink = extractItemIdFromShareLink(originalLink);
if (cleanLink) {
document.getElementById('cleanedLink').value = cleanLink;
resultDiv.style.display = 'block';
} else {
showError('Could not extract item ID from the link. Please make sure it\'s a valid Taobao/Tmall share link.');
}
} catch (error) {
showError('Error processing link: ' + error.message);
}
}
function extractItemIdFromShareLink(url) {
console.log('Processing URL:', url);
// Decode URL if it's encoded
let decodedUrl = url;
try {
decodedUrl = decodeURIComponent(url);
} catch (e) {
// If decoding fails, use original URL
console.log('URL decode failed, using original');
}
// Common Taobao/Tmall share link patterns and their parameter extraction
const patterns = [
// New e.tb.cn pattern
{
regex: /https?:\/\/e\.tb\.cn\/[^?]+\?[^&]*([^=]+)=([^&]+)/,
extractor: (match) => {
const params = new URLSearchParams(decodedUrl.split('?')[1]);
// Try common parameter names
for (let param of ['e', 'union_lens', 'ul', 'id', 'item_id']) {
const value = params.get(param);
if (value && /^\d+$/.test(value)) {
return value;
}
// Check if parameter contains id in encoded form
if (value && value.includes('id=')) {
const idMatch = value.match(/id=(\d+)/);
if (idMatch) return idMatch[1];
}
}
return null;
}
},
// s.click.taobao.com pattern
{
regex: /https?:\/\/s\.click\.taobao\.com\/[^?]+\?(.*)/,
extractor: (match) => {
const params = new URLSearchParams(decodedUrl.split('?')[1]);
for (let param of ['id', 'item_id', 'e']) {
const value = params.get(param);
if (value && /^\d+$/.test(value)) return value;
}
return null;
}
},
// Direct item.taobao.com pattern
{
regex: /https?:\/\/item\.taobao\.com\/item\.htm\?id=(\d+)/,
extractor: (match) => match[1]
},
// Direct detail.tmall.com pattern
{
regex: /https?:\/\/detail\.tmall\.com\/item\.htm\?id=(\d+)/,
extractor: (match) => match[1]
},
// m.tb.cn pattern
{
regex: /https?:\/\/m\.tb\.cn\/[^?]+\?[^&]*([^=]+)=([^&]+)/,
extractor: (match) => {
const params = new URLSearchParams(decodedUrl.split('?')[1]);
for (let param of ['e', 'id', 'item_id', 'sm', 'scm']) {
const value = params.get(param);
if (value && /^\d+$/.test(value)) return value;
if (value && value.includes('id=')) {
const idMatch = value.match(/id=(\d+)/);
if (idMatch) return idMatch[1];
}
}
return null;
}
},
// Generic pattern for any URL containing item ID
{
regex: /[?&](?:id|item_id)=(\d+)/,
extractor: (match) => match[1]
},
// Pattern for encoded URLs in parameters
{
regex: /(?:url|ul)=([^&]+)/,
extractor: (match) => {
try {
const decoded = decodeURIComponent(match[1]);
const idMatch = decoded.match(/id=(\d+)/);
return idMatch ? idMatch[1] : null;
} catch (e) {
return null;
}
}
}
];
for (let pattern of patterns) {
const match = decodedUrl.match(pattern.regex);
if (match) {
console.log('Matched pattern:', pattern.regex);
const itemId = pattern.extractor(match);
if (itemId && /^\d+$/.test(itemId)) {
console.log('Found item ID:', itemId);
return `https://item.taobao.com/item.htm?id=${itemId}`;
}
}
}
// Last resort: try to find any numeric ID in the URL
const numericMatch = decodedUrl.match(/\b(\d{8,15})\b/);
if (numericMatch) {
console.log('Found numeric ID:', numericMatch[1]);
return `https://item.taobao.com/item.htm?id=${numericMatch[1]}`;
}
return null;
}
function showError(message) {
const errorDiv = document.getElementById('error');
errorDiv.textContent = message;
errorDiv.style.display = 'block';
}
function copyToClipboard() {
const textarea = document.getElementById('cleanedLink');
textarea.select();
document.execCommand('copy');
// Show temporary feedback
const copyBtn = document.querySelector('.copy-btn');
const originalText = copyBtn.textContent;
copyBtn.textContent = 'Copied!';
copyBtn.style.backgroundColor = '#2196F3';
setTimeout(() => {
copyBtn.textContent = originalText;
copyBtn.style.backgroundColor = '#4CAF50';
}, 2000);
}
// Allow pressing Enter to process the link
document.getElementById('taobaoLink').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
processLink();
}
});
// Example links for testing
console.log('Test examples:');
console.log('e.tb.cn:', extractItemIdFromShareLink('https://e.tb.cn/h.gI9tM3gx2ZPJX0U?tk=8PQ63Wq4RfS'));
console.log('s.click.taobao.com:', extractItemIdFromShareLink('https://s.click.taobao.com/xxxxx?id=123456789'));
</script>
</body>
</html> padding: 12px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 14px;
box-sizing: border-box;
}
textarea {
height: 100px;
resize: vertical;
font-family: monospace;
}
button {
background-color: #ff5000;
color: white;
border: none;
padding: 12px 30px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
display: block;
margin: 0 auto;
transition: background-color 0.3s;
}
button:hover {
background-color: #e04800;
}
.result {
margin-top: 20px;
padding: 15px;
background-color: #f9f9f9;
border-radius: 5px;
border-left: 4px solid #ff5000;
display: none;
}
.result h3 {
margin-top: 0;
color: #333;
}
.copy-btn {
background-color: #4CAF50;
padding: 8px 15px;
font-size: 14px;
margin-top: 10px;
}
.copy-btn:hover {
background-color: #45a049;
}
.error {
color: #d32f2f;
margin-top: 10px;
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>Taobao Link Cleaner</h1>
<div class="input-group">
<label for="taobaoLink">Paste Taobao Share Link:</label>
<input type="text" id="taobaoLink" placeholder="https://e.tb.cn/xxxxx" />
</div>
<button onclick="processLink()">Clean Link</button>
<div id="error" class="error"></div>
<div id="result" class="result">
<h3>Cleaned Link:</h3>
<textarea id="cleanedLink" readonly></textarea>
<button class="copy-btn" onclick="copyToClipboard()">Copy to Clipboard</button>
</div>
</div>
<script>
async function processLink() {
const originalLink = document.getElementById('taobaoLink').value.trim();
const errorDiv = document.getElementById('error');
const resultDiv = document.getElementById('result');
// Hide previous results/errors
errorDiv.style.display = 'none';
resultDiv.style.display = 'none';
if (!originalLink) {
showError('Please enter a Taobao link');
return;
}
try {
// Extract the final URL by following redirects
const finalUrl = await getFinalUrl(originalLink);
// Extract item ID and create clean link
const cleanLink = extractItemId(finalUrl);
if (cleanLink) {
document.getElementById('cleanedLink').value = cleanLink;
resultDiv.style.display = 'block';
} else {
showError('Could not extract item ID from the link');
}
} catch (error) {
showError('Error processing link: ' + error.message);
}
}
async function getFinalUrl(url) {
try {
// Use a CORS proxy to avoid cross-origin issues
const proxyUrl = 'https://corsproxy.io/?url=';
const response = await fetch(proxyUrl + url, {
method: 'HEAD',
redirect: 'follow'
});
return response.url;
} catch (error) {
// If CORS proxy fails, try to extract from the redirect URL pattern
console.log('CORS proxy failed, trying URL pattern extraction');
return extractFromUrlPattern(url);
}
}
function extractFromUrlPattern(url) {
// Common Taobao redirect patterns
const patterns = [
/url=([^&]+)/,
/e\.(taobao|tmall)\.com\/[^?]+\?([^&]+)&?/,
/redirect\.simba\.taobao\.com\/[^?]+\?([^&]+)&?/
];
for (let pattern of patterns) {
const match = url.match(pattern);
if (match) {
try {
const decoded = decodeURIComponent(match[1] || match[2]);
if (decoded.includes('taobao.com') || decoded.includes('tmall.com')) {
return decoded;
}
} catch (e) {
console.log('URL decode failed for match:', match[1]);
}
}
}
// If no pattern matches, return original URL
return url;
}
function extractItemId(url) {
// Remove URL parameters and fragment
const cleanUrl = url.split('?')[0].split('#')[0];
// Pattern for Taobao/Tmall item IDs
const patterns = [
/(?:item|detail)\.(?:taobao|tmall)\.(?:com|hk)\/(?:item\.htm\?id=|item\/)?(\d+)/,
/id=(\d+)/,
/\/(\d+)\.html/,
/\?id=(\d+)/
];
for (let pattern of patterns) {
const match = cleanUrl.match(pattern);
if (match && match[1]) {
return `https://item.taobao.com/item.htm?id=${match[1]}`;
}
}
return null;
}
function showError(message) {
const errorDiv = document.getElementById('error');
errorDiv.textContent = message;
errorDiv.style.display = 'block';
}
function copyToClipboard() {
const textarea = document.getElementById('cleanedLink');
textarea.select();
document.execCommand('copy');
// Show temporary feedback
const copyBtn = document.querySelector('.copy-btn');
const originalText = copyBtn.textContent;
copyBtn.textContent = 'Copied!';
copyBtn.style.backgroundColor = '#2196F3';
setTimeout(() => {
copyBtn.textContent = originalText;
copyBtn.style.backgroundColor = '#4CAF50';
}, 2000);
}
// Allow pressing Enter to process the link
document.getElementById('taobaoLink').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
processLink();
}
});
</script>
</body>
</html>