-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (54 loc) · 1.92 KB
/
main.py
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
import sys, re
with open(sys.argv[0], 'r') as file:
css = file.read()
css = css.upper()
colors = list(set(re.findall(r'([#][A-Fa-f0-9]{3}|[#][A-Fa-f0-9]{6})[\W]', css)))
shades = list(set(re.findall(r'\d{1,3}, *\d{1,3}, *\d{1,3}, *\d+(\.\d+)?\)', css)))
new_css = ""
new_html = ""
for i in range(len(colors)):
new_css += "\n .color" + str(i + 1) + " {\n background-color: " + colors[i] + ";\n }\n"
new_html += "\n <div class=\"colors color" + str(i + 1) + "\"><span class=\"color-text\">" + colors[
i] + "</span></div>\n"
js = " <script>\n" \
" document.addEventListener('click', function(event) {\n" \
" if (!(event.target.matches('.colors') || event.target.matches('.color-text'))) return;\n" \
" var text = event.target.innerText;\n" \
" console.log(text);\n" \
" const el = document.createElement('textarea');\n" \
" document.body.appendChild(el);\n" \
" el.value = text;\n" \
" el.select();\n" \
" document.execCommand('copy');\n" \
" document.body.removeChild(el);\n" \
" }, false);" \
" </script>"
html = '<!doctype html>\n' \
'\n' \
'<html lang="en">\n' \
' <head>\n' \
' <meta charset="utf-8">\n' \
'\n' \
' <title>The Colors</title>\n' \
'\n' \
' <style>\n' \
' body {margin: 0;}\n\n' \
' .color-text {background-color: white;}\n\n' \
' .colors {\n' \
' text-align: center;\n' \
' line-height: 2em;\n' \
' height: 2em;\n' \
' }\n\n' \
+ new_css \
+ ' </style>\n' \
'\n' \
'\n' \
+ js \
+ '\n' \
' </head>\n' \
' <body>\n' \
+ new_html \
+ ' </body>\n' \
'</html>'
with open("index.html", "w") as output:
output.write(html)