-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
42 lines (42 loc) · 1.63 KB
/
content.js
File metadata and controls
42 lines (42 loc) · 1.63 KB
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
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
fetch('https://hat.f5.si/API/CREATE-V2/', {
method: 'POST',
body: JSON.stringify({
type: "PHP",
new: 1,
url: request.url,
}),
})
.then(response => response.json())
.then(data => {
if (data.response == 100, 101) {
if (request.url.toLowerCase().startsWith('https://')) {
navigator.clipboard.writeText(data.url);
} else {
const inputID = 'shortURL';
if (document.querySelector(`#${inputID}`) === null) {
const $input = document.createElement('input');
$input.setAttribute('type', 'text');
$input.setAttribute('id', inputID);
$input.setAttribute('style', 'position: absolute; left: -100vw; top: 0');
document.body.appendChild($input);
}
const $inputDom = document.querySelector(`#${inputID}`);
$inputDom.value = data.url;
$inputDom.select();
document.execCommand('copy');
}
alert("成功!!\nURLをクリップボードにコピーしました!")
} else {
if (data.code == "timeout") {
alert("タイムアウトしました\n生成頻度が高すぎます!!")
} else {
alert("失敗しました\nしばらく時間をおいて再度お試しください")
}
}
})
sendResponse({
value: request.url,
});
return true;
});