-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode2pyname.html
More file actions
84 lines (66 loc) · 2.36 KB
/
leetcode2pyname.html
File metadata and controls
84 lines (66 loc) · 2.36 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
<!DOCTYPE html>
<html>
<head>
<title>LeetCode Title Converter</title>
<style>
body {
background-color: black;
color: white;
font-family: sans-serif;
}
</style>
<script>
function convertTitle() {
const inputTitle = document.getElementById("titleInput").value;
const fileExtension = document.getElementById("fileExtension").value;
const outputElement = document.getElementById("output");
// Find the index of the dot followed by a space (". ")
const dotSpaceIndex = inputTitle.indexOf(". ");
if (dotSpaceIndex === -1) {
outputElement.textContent = "Invalid format. Please include '. ' in the title.";
return;
}
// Extract the number part
const numberPart = inputTitle.substring(0, dotSpaceIndex);
// Pad the number part with leading zeros if needed
const paddedNumberPart = numberPart.padStart(4, '0');
// Extract the text part
const textPart = inputTitle.substring(dotSpaceIndex + 2);
// Format the number part
const formattedNumberPart = "_" + paddedNumberPart + "_";
// Format the text part
const formattedTextPart = textPart.replace(/\s/g, "");
// Combine the parts and add the specified file extension
const finalTitle = formattedNumberPart + formattedTextPart + "." + fileExtension;
outputElement.textContent = finalTitle;
// Enable the copy button
document.getElementById("copyButton").disabled = false;
}
function copyToClipboard() {
const outputElement = document.getElementById("output");
const textToCopy = outputElement.textContent;
// Use the Clipboard API
navigator.clipboard.writeText(textToCopy)
.then(() => {
alert("Copied to clipboard!"); // Optional: Provide feedback
// Clear the input field after copying
document.getElementById("titleInput").value = "";
})
.catch(err => {
console.error('Failed to copy: ', err);
alert("Failed to copy to clipboard. Check browser permissions.");
});
}
</script>
</head>
<body>
<h1>LeetCode Title Converter</h1>
<label for="titleInput">Enter LeetCode Title:</label>
<input type="text" id="titleInput" name="titleInput"><br><br>
<label for="fileExtension">Enter File Extension:</label>
<input type="text" id="fileExtension" name="fileExtension" value="py"><br><br>
<button onclick="convertTitle()">Convert</button>
<button id="copyButton" onclick="copyToClipboard()" disabled>Copy to Clipboard</button>
<p id="output"></p>
</body>
</html>