Skip to content

Commit 55b59da

Browse files
feat: psturtle.com _includes/GetRandomPalette ( Fixes #203 )
1 parent 912d8fb commit 55b59da

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
<#
3+
.SYNOPSIS
4+
Includes a palette selector
5+
.DESCRIPTION
6+
Includes a palette selector in a page. This allows the page to use multiple color palettes.
7+
#>
8+
param(
9+
[uri]
10+
$PaletteListSource = 'https://4bitcss.com/Palette-List.json',
11+
12+
# The Palette CDN. This is the root URL of all palettes.
13+
[uri]
14+
$PaletteCDN = 'https://cdn.jsdelivr.net/gh/2bitdesigns/4bitcss@latest/css/',
15+
16+
# The identifier for the palette `<select>`.
17+
[string]
18+
$SelectPaletteId = 'SelectPalette',
19+
20+
# The identifier for the stylesheet. By default, palette.
21+
[string]
22+
$PaletteId = 'palette'
23+
)
24+
25+
26+
$JavaScript = @"
27+
function GetRandomPalette() {
28+
var SelectPalette = document.getElementById('$SelectPaletteId')
29+
if (SelectPalette) {
30+
var randomNumber = Math.floor(Math.random() * SelectPalette.length);
31+
SelectPalette.selectedIndex = randomNumber
32+
SetPalette()
33+
}
34+
}
35+
"@
36+
37+
$HTML = @"
38+
<script>
39+
$JavaScript
40+
</script>
41+
<button onclick='GetRandomPalette()'>Random Palette</button>
42+
"@
43+
44+
$HTML
45+

0 commit comments

Comments
 (0)