-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
71 lines (65 loc) · 1.76 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG Path Extractor</title>
<style>
body {
font-family: Arial, sans-serif;
}
textarea {
width: 100%;
height: 200px;
margin-bottom: 10px;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<h1>SVG Path Extractor</h1>
<textarea id="svgInput" placeholder="Paste your SVG here..." onkeydown="handleKeyDown(event)"></textarea>
<button onclick="extractPath()">Extract Path</button>
<script>
function extractPath() {
// Get the input element
var input = document.getElementById('svgInput');
// Extracting the 'd' attribute from the input value
var regex = /<path.*?d="(.*?)"/;
var match = regex.exec(input.value);
// If a match is found, copy the 'd' attribute value to clipboard
if (match && match[1]) {
var pathData = match[1];
copyToClipboard(pathData);
alert('Path copied to clipboard:\n' + pathData);
} else {
alert('No path found in the SVG input.');
}
// Clear the input for next use
input.value = '';
}
function copyToClipboard(text) {
var textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
}
function handleKeyDown(event) {
if (event.key === 'Enter') {
extractPath();
}
}
</script>
</body>
</html>