-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
110 lines (96 loc) · 3.74 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OneTab Scraper</title>
<link
rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>
⭐️
</text></svg>"
/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" />
</head>
<body>
<h1>OneTab Scraper</h1>
<section>
<h4>What is this?</h4>
<p>
This is a tool enables you to scrape all links from a <a href="https://www.one-tab.com/">OneTab</a> collection and store them in your clipboard.
</p>
<ol>
<li>Make your OneTab collection public</li>
<li>Request temporary proxy access here: <a href="https://cors-anywhere.herokuapp.com/corsdemo">cors-anywhere proxy</a></li>
<li>Insert your onetab collection link below and click on the "Scrape" button</li>
</ol>
</section>
<br />
<section>
<h4>Enter the URL of your collection below:</h4>
<form>
<input type="text" />
<button type="button" onclick="buttenClicked()" disabled>SCRAPE</button>
</form>
<div class="output"></div>
</section>
</body>
<script>
const validate = () => {
const inputContent = document.querySelector('input').value || ''
const validPrefix = inputContent.startsWith('https://www.one-tab.com/page/')
const validUrl = !!inputContent.match(/^(http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/)
document.querySelector('button').disabled = !(validPrefix && validUrl)
}
document.onkeydown = validate
document.onkeyup = validate
document.onkeypress = validate
const buttenClicked = () => {
document.querySelector('.output').innerHTML = ''
const inputContent = document.querySelector('input').value
console.assert(inputContent, 'inputContent is empty')
const proxy = 'https://cors-anywhere.herokuapp.com/'
const response = fetch(proxy + inputContent)
.then((response) => response.text())
.then((plaintext) => {
const html = new DOMParser().parseFromString(plaintext, 'text/html')
const hrefs = Array.from(html.querySelectorAll('a')).map((anchor) => anchor.href)
return hrefs
})
.then((hrefs) => {
hrefs = hrefs.slice(3)
hrefs.forEach((h) => (document.querySelector('.output').innerHTML += `<code>${h}</code>`))
navigator.clipboard.writeText(hrefs.join('\n'))
})
.catch((err) => console.error(err))
}
</script>
<style>
form,
input,
button {
margin: 0 !important;
display: inline-block !important;
}
form {
padding: 0 !important;
margin-left: auto;
margin-right: auto;
margin-top: 1rem !important;
width: 100% !important;
}
input {
margin-left: 10% !important;
width: 60%;
}
.output {
margin-top: 3rem !important;
}
code {
color: white;
margin-top: 0.5rem;
display: block;
}
</style>
</html>