-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.html
129 lines (118 loc) · 2.62 KB
/
ui.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
<svg
version="1.1"
id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px"
y="0px"
width="24px"
height="30px"
viewBox="0 0 24 30"
style="enable-background: new 0 0 50 50"
xml:space="preserve"
>
<rect x="0" y="0" width="4" height="20" fill="#333">
<animate
attributeName="opacity"
attributeType="XML"
values="1; .2; 1"
begin="0s"
dur="0.6s"
repeatCount="indefinite"
></animate>
</rect>
<rect x="7" y="0" width="4" height="20" fill="#333">
<animate
attributeName="opacity"
attributeType="XML"
values="1; .2; 1"
begin="0.2s"
dur="0.6s"
repeatCount="indefinite"
></animate>
</rect>
<rect x="14" y="0" width="4" height="20" fill="#333">
<animate
attributeName="opacity"
attributeType="XML"
values="1; .2; 1"
begin="0.4s"
dur="0.6s"
repeatCount="indefinite"
></animate>
</rect>
</svg>
<style>
* {
padding: 0;
margin: 0;
}
body {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
</style>
<script>
// 抛出错误
function reportError(msg) {
parent.postMessage(
{
pluginMessage: {
type: "error",
msg,
},
},
"*"
);
}
// 获取 Icon
function fetchIco(ico, returnData) {
fetch(`https://logo.clearbit.com/${ico}`)
.then((res) => res.arrayBuffer())
.then((buffer) => {
returnData.icoImg = new Uint8Array(buffer);
})
.catch((err) => {
// reportError("Unable to get website Icon");
});
}
function fetchData(data) {
const returnData = data;
if (!data.link || !data.characters) {
reportError("Unable to analyze text");
}
// 获取 Icon
fetchIco(data.link, returnData);
// 获取网页信息
fetch(
`https://iframe.ly/api/iframely?url=${data.characters}&api_key=5cc4e3759ecc9a2f152ed9`
)
.then((res) => res.json())
.then((json) => {
console.log(json);
returnData.iframe = json;
parent.postMessage(
{
pluginMessage: {
type: "returnData",
returnData,
},
},
"*"
);
})
.catch((err) => reportError("Unable to get website info"));
}
window.onmessage = async (event) => {
const pmsg = event.data.pluginMessage;
const currentSelected = pmsg.selection[0];
if (!currentSelected) {
reportError("Nothing selected");
} else {
fetchData(currentSelected);
}
};
</script>