-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
153 lines (139 loc) · 5.57 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
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
const { Extension, type, api } = require('clipcc-extension');
class MyExtension extends Extension {
whatPlanIsUsedWhenHitError = "a";
capturedError = undefined;
logError(e) {
//错误处理相关实现借鉴自:github.com/bddjr/clipcc-extension-nhjrToolBox/blob/1fb1859cd3ac44cf9ceade46b40adde2a24153cb/index.js#L10
console.error(e);
this.capturedError = String(e);
if (this.whatPlanIsUsedWhenHitError === 'a') {
return String(e);
}
return '';
}
//用于处理用户输入的图片 URL。
imageURLcleaner() {
}
onInit() {
//分类 "mediaSession" :
//welcome:“杂项”
api.addCategory({
categoryId: 'jexjws.mediasession.category.welcome',
messageId: 'jexjws.mediasession.category.welcome',
color: '#582396'
});
//积木 "mediaSession 是否可用" :
api.addBlock({
opcode: 'jexjws.mediasession.v1.can_use_mediaSession',
messageId: 'jexjws.mediasession.block.can_use_mediaSession',
categoryId: 'jexjws.mediasession.category.welcome',
type: type.BlockType.BOOLEAN,
function: () => {
try {
return ("mediaSession" in navigator);
} catch (e) {
return this.logError(e)
}
}
})
//变量 "mediaSession 报错信息" :
api.addBlock({
opcode: 'jexjws.mediasession.v1.error_information',
type: type.BlockType.REPORTER,
messageId: 'jexjws.mediasession.block.error_information',
categoryId: 'jexjws.mediasession.category.welcome',
function: () => (this.capturedError)
});
/*积木 "当执行出错时:" :
直接通过积木块返回报错信息(易于调试)+ 记录报错信息到 "mediaSession 报错信息" 积木中 + console报错
默认:积木块仅返回空白信息 + 记录报错信息到 "mediaSession 报错信息" 积木中 + console报错
*/
api.addBlock({
opcode: 'jexjws.mediasession.v1.do_what_when_hit_error',
messageId: 'jexjws.mediasession.block.do_what_when_hit_error',
categoryId: 'jexjws.mediasession.category.welcome',
type: type.BlockType.COMMAND,
param: {
what_plan: {
field: true,
type: type.ParameterType.STRING,
menu: [{
messageId: 'jexjws.mediasession.menu.do_what_when_hit_error.planA',
value: 'a'
}, {
messageId: 'jexjws.mediasession.menu.do_what_when_hit_error.planB',
value: 'b'
}],
default: 'a'
}
},
function: (args) => {
try {
this.whatPlanIsUsedWhenHitError = args.what_plan;
}
catch (e) { return this.logError(e); }
}
})
//积木 "mediaSession 是否可用" :
//分类 "媒体元数据" :
api.addCategory({
categoryId: 'jexjws.mediasession.category.media_metadata',
messageId: 'jexjws.mediasession.category.media_metadata',
color: '#582396'
});
//积木 “初始化:媒体元数据”
api.addBlock({
opcode: 'jexjws.mediasession.v1.reset_media_metadata',
type: type.BlockType.COMMAND,
messageId: 'jexjws.mediasession.block.reset_media_metadata',
categoryId: 'jexjws.mediasession.category.media_metadata',
function: () => {
try {
navigator.mediaSession.metadata = new MediaMetadata();
} catch (e) {
return this.logError(e);
}
}
})
//积木 "设定媒体元数据中的 [key] 为 [value] " :
api.addBlock({
opcode: 'jexjws.mediasession.v1.set_media_metadata',
type: type.BlockType.COMMAND,
messageId: 'jexjws.mediasession.block.set_media_metadata',
categoryId: 'jexjws.mediasession.category.media_metadata',
param: {
key: {
type: type.ParameterType.STRING,
menu: [{
messageId: 'jexjws.mediasession.menu.title',
value: 'title'
}, {
messageId: 'jexjws.mediasession.menu.artist',
value: 'artist'
}, {
messageId: 'jexjws.mediasession.menu.album',
value: 'album'
}],
default: 'title'
},
value: {
type: type.ParameterType.STRING,
default: ' '
}
},
function: (args) => {
console.log('Hello, ClipCC!' + String(JSON.stringify(args) + this.whatPlanIsUsedWhenHitError));
try {
navigator.mediaSession.metadata[args.key] = args.value;
} catch (e) {
return this.logError(e);
}
}
});
}
onUninit() {
api.removeCategory('jexjws.mediasession.category.media_metadata');
api.removeCategory('jexjws.mediasession.category.compatibility_test');
}
}
module.exports = MyExtension;