-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
154 lines (145 loc) · 5.96 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Joy-Con Tool</title>
<link href="main.css" rel="stylesheet" />
<script type="module" src="index.js"></script>
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
</head>
<body>
<section x-data="{controllers: [], current: {}, modal: false, selection: false, error_msg: ''}"
x-effect="previewColor($refs.preview, current)"
@register-controller="controllers.push(current = $event.detail.controller)">
<header>
<h1>Joy-Con Tool</h1>
</header>
<main>
<ul>
<template x-for="controller in controllers" :key="controller.macAddr">
<li :class="current == controller ? 'active' : ''" @click="current = controller">
<div>
<object type="image/svg+xml" data="./icons/battery-solid.svg"
@load.once="setBatteryCapacity($event.target, controller.voltage)"></object>
<object type="image/svg+xml" :data="controller.image"
@load.once="previewColor($event.target, controller)"></object>
</div>
<div>
<span :class="current == controller ? 'active' : ''" x-text="controller.productName">
</span>
</div>
</li>
</template>
<li role="button" aria-pressed="false" @click="connectController()
.then((controller) => controller && $dispatch('register-controller', { controller }))
.catch((e) => error_msg = e)">
<span>Add</span>
</li>
</ul>
<form @submit.prevent>
<figure>
<object type="image/svg+xml" x-ref="preview" :data="current.image"
@load="previewColor($event.target, current)"></object>
</figure>
<template x-for="part in ['Body', 'Button', 'Left Grip', 'Right Grip']" :key="part">
<label :class="current.macAddr && (!part.includes('Grip') || current.type == 'procon') ? 'active' : ''">
<span x-text="`${part} Color`"></span>
<input type="color" :disabled="!current.macAddr || (part.includes('Grip') && current.type != 'procon')"
x-model="current[part.toLowerCase().replace(/ (.)/g, (_,c) => c.toUpperCase())+'Color']"
@input="previewColor($refs.preview, current)" />
</label>
</template>
<button :class="current.macAddr && current.type != 'procon' ? 'active' : ''"
:disabled="!current.macAddr || current.type == 'procon'" @click="selection = true">
Joy-Con Preset Color
</button>
<button :class="current.macAddr ? 'active' : ''" :disabled="!current.macAddr" @click="modal = true">
Apply
</button>
<aside>
<template x-for="item in [
`Serial Number: ${current.serialNumber}`,
`Mac Address: ${current.macAddr}`,
`Firmware Version: ${current.firmware}`,
]">
<span x-text="item"></span>
</template>
</aside>
</form>
</main>
<footer>
<span>
Icons are licensed under
<a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>.
Images are licensed under
<a href="https://creativecommons.org/licenses/by-sa/4.0/">
CC BY-SA 4.0 </a>.
</span>
<span>
© 2020 @mzyy94 -
<a href="https://github.com/mzyy94/joycon-toolweb">GitHub</a> -
<a href="https://mzyy94.com/blog/2020/05/27/switch-joycon-color-replace-tool/">Usage (ja)</a>
</span>
</footer>
<dialog x-cloak x-show="modal" x-transition.opacity.duration.200ms>
<div x-show="modal" x-transition.scale.90.duration.200ms>
<div>
<p>
Once new color data has been applied, the original data can not be
restored. No guarantee or warranty when your controller isn't work.
Continue?
</p>
</div>
<div>
<button @click="modal = false">Cancel</button>
<button @click="current.submitColor().catch(e => error_msg = e);modal = false">Apply</button>
</div>
</div>
</dialog>
<dialog x-cloak x-show="error_msg != ''" x-transition.opacity.duration.200ms>
<div x-show="error_msg != ''" x-transition.scale.90.duration.200ms>
<div>
<template x-if="error_msg == 'unavailable'">
<p x-show="navigator.userAgent.toLowerCase().includes('chrome')">
WebHID API is unavailable. Please use latest Google Chrome.
</p>
</template>
<template x-if="error_msg == 'unavailable'">
<p x-show="!navigator.userAgent.toLowerCase().includes('chrome')">
Your browser is not supported, please use Google Chrome.
</p>
</template>
<template x-if="error_msg != 'unavailable'">
<p x-text="error_msg"></p>
</template>
</div>
<div>
<button @click="error_msg = ''">OK</button>
</div>
</div>
</dialog>
<dialog x-cloak x-show="selection" x-transition.opacity.duration.100ms>
<section x-show="selection">
<header>
<h2>Preset Colors</h2>
<p>Please choose a body color which you want to set.</p>
</header>
<section>
<template x-for="color in presetColors">
<a
@click="current['bodyColor'] = color; current['buttonColor'] = '#222222'; selection = false; previewColor($refs.preview, current)">
<object type="image/svg+xml" :data="current.image"
@load.once="previewColor($event.target, {bodyColor: color, buttonColor:'#222222'})"></object>
</a>
</template>
</section>
<footer>
<button @click="selection = false">Back</button>
</footer>
</section>
</dialog>
</section>
</body>
</html>