-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
77 lines (61 loc) · 2.98 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Text Generator</title>
<!-- External CSS -->
<link rel="stylesheet" href="stylesheet.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body onload="brython()">
<section id="TopBox"></section>
<div id="temp"></div>
<center>
<!-- Division for containing Random Text -->
<article id="RandomText" class="textBox"> <!-- [ Random Generated text will appear here ] -->
[ Your Random Generated text will appear here ]
</article>
<!-- End of Division containing Random Text -->
<!-- Buttons -->
<button class="btn" id="generateBtn">Re-Generate Text</button>
<div class="tooltip">
<button class="btn" id="copyBtn" onclick="copy();" onmouseout="outFunc()">
<span class="tooltiptext" id="myTooltip">Copy to clipboard</span> Copy Text <i class="fa fa-copy"></i>
</button>
</div>
<button class="btn" id="saveAsTxt" onclick="saveAsTxt(event)">Save as txt file</button>
</center>
<!-- Executing Python program in Browser with Brython -->
<script type="text/python" src="brython_script.bry"></script> <!-- Linking Brython (*.bry) script -->
<!-- Including Brython v3.8.9 using CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.9/brython.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.9/brython_stdlib.min.js"></script>
<!-- Custom Script -->
<script>
function copy() {
var copyText = document.getElementById("RandomText");
var copied = "<textarea id='textcopy'>" + copyText.innerText + "</textarea>";
document.getElementById("temp").innerHTML = copied;
var text = document.getElementById("textcopy");
text.select();
document.execCommand("copy");
document.getElementById("myTooltip").innerText = "Copied!";
}
function outFunc() {
document.getElementById("myTooltip").innerText = "Copy to clipboard";
}
function saveAsTxt(event) {
const TEXT = document.getElementById("RandomText").innerText
const URI = "data:application/octet-stream;charset=utf-8,"+encodeURIComponent(TEXT)
let link = document.createElement('a');
link.setAttribute("href", URI);
link.setAttribute("download", "random-text.txt");
document.getElementsByTagName('body')[0].appendChild(link);
link.click();
document.getElementsByTagName('body')[0].removeChild(link);
// Alternative to temporarily attaching <a> link to <body>: directly opening it with window.open(URI); but setting filename needs to be looked into in this case!
}
</script>
</body>
</html>