-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.html
115 lines (100 loc) · 3.1 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Material Design Palette</title>
<style>
body {
font-family: Arial, sans-serif;
}
#paletteContainer {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.color-box {
width: 150px;
height: 150px;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
text-align: center;
border-radius: 6px;
}
.color-box span {
background: rgba(0, 0, 0, 0.5);
padding: 5px;
border-radius: 6px;
}
/* Divider row style */
.divider {
width: 100%;
height: 0;
margin-bottom: 20px;
border-bottom: 1px solid #eee;
}
</style>
</head>
<body>
<h1>Material Design Color Palette</h1>
<div id="paletteContainer"></div>
<script>
// Function to parse the .gpl file
function parseGPLFile(fileContent) {
const colors = [];
const lines = fileContent.split('\n');
lines.forEach(line => {
if (line.startsWith('000 000 000 DIVIDER')) {
// Push a divider flag into the array
colors.push({ type: 'divider' });
} else if (line.trim() && !line.startsWith('#') && !line.startsWith('GIMP') && !line.startsWith('Name') && !line.startsWith('Columns')) {
const parts = line.trim().split(/\s+/);
if (parts.length >= 4) {
const r = parts[0];
const g = parts[1];
const b = parts[2];
const name = parts.slice(3).join(' ');
const hexColor = `rgb(${r},${g},${b})`;
colors.push({ type: 'color', name, hexColor });
}
}
});
return colors;
}
// Function to display the colors
function displayColors(colors) {
const paletteContainer = document.getElementById('paletteContainer');
paletteContainer.innerHTML = ''; // Clear previous content
colors.forEach(item => {
if (item.type === 'divider') {
// Create a new row when a divider is found
const divider = document.createElement('div');
divider.classList.add('divider');
paletteContainer.appendChild(divider);
} else if (item.type === 'color') {
// Create the color box
const colorBox = document.createElement('div');
colorBox.classList.add('color-box');
colorBox.style.backgroundColor = item.hexColor;
const colorLabel = document.createElement('span');
colorLabel.textContent = `${item.name} (${item.hexColor})`;
colorBox.appendChild(colorLabel);
paletteContainer.appendChild(colorBox);
}
});
}
// Fetch the .gpl file from the root directory and process it
fetch('./Material_Design.gpl')
.then(response => response.text())
.then(fileContent => {
const colors = parseGPLFile(fileContent);
displayColors(colors);
})
.catch(error => {
console.error('Error loading .gpl file:', error);
});
</script>
</body>
</html>