-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
114 lines (107 loc) · 2.93 KB
/
preload.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
'use strict';
const {
utools
} = window;
const axios = require('axios');
const addHulu = (content) => {
const api = utools.db.get('api');
console.log(api)
if (!api) {
utools.showNotification('请先设置个人 API');
return
}
const data = JSON.stringify({
"content": content
});
const config = {
method: 'post',
// 登录葫芦笔记笔记库首页,点击头像,进入个人中心,然后点击获取API链接,即可得到API链接 https://www.hulunote.com/app
// 类似于这样的url: 'https://www.hulunote.com/myapi/quick-text-put/868253a542823a498090260f2462af3f',
url: api.api,
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
utools.showNotification('发送成功!');
})
.catch(function (error) {
console.log(error);
utools.showNotification('发送失败!');
});
}
window.exports = {
'set_api': {
mode: 'list',
args: {
enter: () => {
utools.subInputFocus();
},
search: (action, searchWord, callbackSetList) => {
callbackSetList([{
title: '确定',
description: '设置 hulu API',
icon: 'icons/logo.png',
api: searchWord,
}]);
},
select: (action, itemData, callbackSetList) => {
const api = utools.db.get('api');
const data = {
_id: 'api',
api: itemData.api,
};
//rev 属性,这是代表此文档的版本,每次对文档进行更新时,都要带上最新的版本号,否则更新将失败,版本化的意义在于解决同步时数据冲突
if (api) {
data._rev = api._rev;
}
utools.db.put(data);
utools.hideMainWindow();
utools.showNotification('设置 个人API 成功!');
utools.outPlugin();
},
placeholder: "输入"
}
},
'send_to_hulu': {
mode: 'none',
args: {
enter: (action, callbackSetList) => {
utools.hideMainWindow();
const {
payload
} = action;
addHulu(payload)
utools.outPlugin();
},
}
},
'add_to_hulu': {
mode: 'list',
args: {
// 进入插件时调用(可选)
enter: () => {
utools.subInputFocus();
},
// 子输入框内容变化时被调用 可选 (未设置则无搜索)
search: (action, searchWord, callbackSetList) => {
callbackSetList([{
title: '添加笔记到hulu',
description: '随便记点什么吧',
icon: 'icons/logo.png',
content: searchWord
}]);
},
// 用户选择列表中某个条目时被调用
select: (action, itemData, callbackSetList) => {
utools.hideMainWindow();
addHulu(itemData.content)
utools.outPlugin();
},
placeholder: "输入"
}
},
}