-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
105 lines (99 loc) · 6.06 KB
/
index.js
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
async function auto_run(){
button_set();
await require("photoshop").core.executeAsModal(readout);
}
async function readout(){
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "kuiBrightnessLevel"
},
{
"_ref": "application",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
});
const pinned = result[0].kuiBrightnessLevel._value;
if (pinned == "kPanelBrightnessDarkGray"){
document.getElementById("btn_dark").innerHTML ='<div slot="icon" class="icon"><svg height="20" viewBox="0 0 20 20" width="20" slot="icon" focusable="false" aria-hidden="true" role="img"><rect x="0" y="0" width="20" height="20" style="fill:#353535;"/><path d="M0.763,17.985l6.95,-9.365l-6.129,-8.605l2.832,0l3.26,4.609c0.678,0.956 1.161,1.692 1.447,2.206c0.4,-0.653 0.874,-1.336 1.421,-2.047l3.616,-4.768l2.587,0l-6.313,8.47l6.803,9.5l-2.942,-0l-4.523,-6.411c-0.253,-0.368 -0.515,-0.768 -0.784,-1.201c-0.401,0.654 -0.687,1.103 -0.858,1.348l-4.511,6.264l-2.856,-0Z" style="fill:#fff;fill-rule:nonzero;"/></svg></div>';
}
if (pinned == "kPanelBrightnessMediumGray"){
document.getElementById("btn_dark-light").innerHTML ='<div slot="icon" class="icon"><svg height="20" viewBox="0 0 20 20" width="20" slot="icon" focusable="false" aria-hidden="true" role="img"><rect x="0" y="0" width="20" height="20" style="fill:#545454;"/><path d="M0.763,17.985l6.95,-9.365l-6.129,-8.605l2.832,0l3.26,4.609c0.678,0.956 1.161,1.692 1.447,2.206c0.4,-0.653 0.874,-1.336 1.421,-2.047l3.616,-4.768l2.587,0l-6.313,8.47l6.803,9.5l-2.942,-0l-4.523,-6.411c-0.253,-0.368 -0.515,-0.768 -0.784,-1.201c-0.401,0.654 -0.687,1.103 -0.858,1.348l-4.511,6.264l-2.856,-0Z" style="fill:#fff;fill-rule:nonzero;"/></svg></div>';
}
if (pinned == "kPanelBrightnessLightGray"){
document.getElementById("btn_light_dark").innerHTML ='<div slot="icon" class="icon"><svg height="20" viewBox="0 0 20 20" width="20" slot="icon" focusable="false" aria-hidden="true" role="img"><rect x="0" y="0" width="20" height="20" style="fill:#b6b7b7;"/><path d="M0.763,17.985l6.95,-9.365l-6.129,-8.605l2.832,0l3.26,4.609c0.678,0.956 1.161,1.692 1.447,2.206c0.4,-0.653 0.874,-1.336 1.421,-2.047l3.616,-4.768l2.587,0l-6.313,8.47l6.803,9.5l-2.942,-0l-4.523,-6.411c-0.253,-0.368 -0.515,-0.768 -0.784,-1.201c-0.401,0.654 -0.687,1.103 -0.858,1.348l-4.511,6.264l-2.856,-0Z" /></svg></div>';
}
if (pinned == "kPanelBrightnessOriginal"){
document.getElementById("btn_light").innerHTML ='<div slot="icon" class="icon"><svg height="20" viewBox="0 0 20 20" width="20" slot="icon" focusable="false" aria-hidden="true" role="img"><rect x="0" y="0" width="20" height="20" style="fill:#eff0ef;"/><path d="M0.763,17.985l6.95,-9.365l-6.129,-8.605l2.832,0l3.26,4.609c0.678,0.956 1.161,1.692 1.447,2.206c0.4,-0.653 0.874,-1.336 1.421,-2.047l3.616,-4.768l2.587,0l-6.313,8.47l6.803,9.5l-2.942,-0l-4.523,-6.411c-0.253,-0.368 -0.515,-0.768 -0.784,-1.201c-0.401,0.654 -0.687,1.103 -0.858,1.348l-4.511,6.264l-2.856,-0Z" /></svg></div>';
}
}
async function button_set(){
document.getElementById("btn_dark").innerHTML ='<div slot="icon" class="icon"><svg height="20" viewBox="0 0 20 20" width="20" slot="icon" focusable="false" aria-hidden="true" role="img"><rect x="0" y="0" width="20" height="20" style="fill:#353535;"/></svg></div>';
document.getElementById("btn_dark-light").innerHTML ='<div slot="icon" class="icon"><svg height="20" viewBox="0 0 20 20" width="20" slot="icon" focusable="false" aria-hidden="true" role="img"><rect x="0" y="0" width="20" height="20" style="fill:#545454;"/></svg></div>';
document.getElementById("btn_light_dark").innerHTML ='<div slot="icon" class="icon"><svg height="20" viewBox="0 0 20 20" width="20" slot="icon" focusable="false" aria-hidden="true" role="img"><rect x="0" y="0" width="20" height="20" style="fill:#b6b7b7;"/></svg></div>';
document.getElementById("btn_light").innerHTML ='<div slot="icon" class="icon"><svg height="20" viewBox="0 0 20 20" width="20" slot="icon" focusable="false" aria-hidden="true" role="img"><rect x="0" y="0" width="20" height="20" style="fill:#eff0ef;"/></svg></div>';
}
async function colorchange(theme){
await require("photoshop").core.executeAsModal(function(){colorchange_action(theme)});
button_set();
await require("photoshop").core.executeAsModal(readout);
}
async function colorchange_action(theme){
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "set",
"_target": [
{
"_ref": "property",
"_property": "interfacePrefs"
},
{
"_ref": "application",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"to": {
"_obj": "interfacePrefs",
"kuiBrightnessLevel": {
"_enum": "uiBrightnessLevelEnumType",
"_value": theme
}
},
"_isCommand": true,
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
});
}
document.addEventListener('uxpcommand', (event) => {
const { commandId } = event
if (commandId === 'uxpshowpanel') {
//console.log("panel is showing");
auto_run();
} else if (commandId === 'uxphidepanel') {
//console.log('panel is hiding');
}
})
document.addEventListener("load",auto_run);
document.getElementById("btn_dark").addEventListener("click", function(){colorchange("kPanelBrightnessDarkGray");});
document.getElementById("btn_dark-light").addEventListener("click", function(){colorchange("kPanelBrightnessMediumGray");});
document.getElementById("btn_light_dark").addEventListener("click", function(){colorchange("kPanelBrightnessLightGray");});
document.getElementById("btn_light").addEventListener("click", function(){colorchange("kPanelBrightnessOriginal");});