Skip to content

Commit 37ed15c

Browse files
committed
changes uuid
1 parent 35aa627 commit 37ed15c

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

web/General/uuid/index.html

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,33 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ"
9-
crossorigin="anonymous">
8+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
9+
integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ"
10+
crossorigin="anonymous">
1011
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
1112
<title>UUID Generator</title>
1213
</head>
1314

1415
<body>
15-
<div class="container">
16-
<div class="row" style="text-align: center">
17-
<div class="col-md-6 offset-md-3">
18-
<h2 class="display-4 text-center">UUID Generator</h2>
19-
<div class="jumbotron">
20-
<p style="font-size:20px;" id="uuid_p">UUID</p>
21-
<div class="span2">
22-
<button class="btn btn-primary float-right" type="button" id="btnGenerateNewUUID" style="position: inherit; right: 2%;">New UUID</button>
23-
</div>
16+
<div class="container">
17+
<div class="row" style="text-align: center">
18+
<div class="col-md-6 offset-md-3">
19+
<h2 class="display-4 text-center">UUID Generator</h2>
20+
<div class="jumbotron">
21+
<p style="font-size:20px;" id="uuid_p">UUID</p>
22+
<div class="span2" class="tooltip">
23+
<button class="float-left btn btn-outline-info btn-sm" type="button" id="btnGenerateNewUUID"
24+
style="position: inherit; right: 2%;">New UUID
25+
</button>
26+
<button class="float-right btn btn-outline-success btn-sm" type="button" id="btnCopyUUID"
27+
style="position: inherit; right: 2%;">Copy
28+
</button>
2429
</div>
2530
</div>
2631
</div>
2732
</div>
28-
<script src="main.js"></script>
33+
</div>
34+
<script src="main.js"></script>
2935
</body>
3036

3137
</html>

web/General/uuid/main.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,57 @@ $(document).ready(function () {
22

33
var UUIDPosition = document.getElementById('uuid_p');
44
var btnGenerateNewUUID = document.getElementById('btnGenerateNewUUID');
5+
var btnCopyUUID = document.getElementById('btnCopyUUID');
56

7+
//initial presentation
68
UUIDPosition.innerHTML = uuid();
79

10+
//button generate new uuid
811
btnGenerateNewUUID.addEventListener("click", function () {
912
UUIDPosition.innerHTML = uuid();
1013
});
1114

15+
//button copy uuid
16+
btnCopyUUID.addEventListener("click", function () {
17+
copyToClipboard();
18+
});
19+
1220
//generate new uuid
1321
function uuid() {
1422
var seed = Date.now();
1523
if (window.performance && typeof window.performance.now === "function") {
1624
seed += performance.now();
1725
}
1826

19-
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
27+
var uuid = 'xxxxxxxx-xxxx-xxxx-yxxx-wxxexxdxxoxx'.replace(/[xy]/g, function (c) {
2028
var r = (seed + Math.random() * 16) % 16 | 0;
2129
seed = Math.floor(seed/16);
2230

2331
return (c === 'x' ? r : r & (0x3|0x8)).toString(16);
2432
});
2533

2634
return uuid;
27-
}
35+
};
36+
37+
//copy uuid
38+
function copyToClipboard () {
39+
var el = document.createElement('textarea'); // Create a <textarea> element
40+
el.value = $(document.getElementById('uuid_p')).text(); // Set its value to the string that you want copied
41+
el.setAttribute('readonly', ''); // Make it readonly to be tamper-proof
42+
el.style.position = 'absolute';
43+
el.style.left = '-9999px'; // Move outside the screen to make it invisible
44+
document.body.appendChild(el); // Append the <textarea> element to the HTML document
45+
var selected =
46+
document.getSelection().rangeCount > 0 // Check if there is any content selected previously
47+
? document.getSelection().getRangeAt(0) // Store selection if found
48+
: false; // Mark as false to know no selection existed before
49+
el.select(); // Select the <textarea> content
50+
document.execCommand('copy'); // Copy - only works as a result of a user action (e.g. click events)
51+
document.body.removeChild(el); // Remove the <textarea> element
52+
if (selected) { // If a selection existed before copying
53+
document.getSelection().removeAllRanges(); // Unselect everything on the HTML document
54+
document.getSelection().addRange(selected); // Restore the original selection
55+
}
56+
};
2857

2958
});

0 commit comments

Comments
 (0)