-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
113 lines (113 loc) · 3.02 KB
/
main.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
function getParamList(){
const obj = {};
if(!location.search) return obj;
location.search.slice(1).split('&').forEach(v=>{
const a = v.split('=');
obj[a[0]] = a[1];
});
return obj;
}
function encode(v){
return encodeURIComponent(v);
}
function decode(v){
return decodeURIComponent(v);
}
var h = $("<div>").appendTo($("body").css({
"text-align": "center"
}));
$("<h1>",{text:"discord webhooker"}).appendTo(h);
var vvv = getParamList().v;
var input_webhook = addInput({
ttl: "Webhook URL",
placeholder: "https://discordapp.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaa",
val: vvv ? decode(vvv) : null
});
var input_username = addInput({
ttl: "名前",
val: ""
});
var input_avatar = addInput({
ttl: "アバター画像",
val: ""
});
var input_text = addTextarea("発言内容");
$.get("sample.txt", function(r){
input_text.val(r);
});
h.append("<br>");
var input_tts = addBtnToggle("tts(読み上げ)");
h.append("<br>");
addBtn("発言",function(){
var data = {
"username": input_username.val(),
"avatar_url": input_avatar.val(),
content: input_text.val(),
tts: input_tts()
};
var xhr = new XMLHttpRequest();
xhr.open( 'POST', input_webhook.val() );
xhr.setRequestHeader( "content-type", "application/json" );
xhr.send(JSON.stringify(data));
});
h.append("<br><br>");
addBtn("共有リンクを作成",function(){
var url = location.origin + location.pathname + '?v=' + encode(input_webhook.val())
var elm = $("<input>").appendTo(output.empty()).val(url).attr({
readonly: true
}).on("click",function(){
copy(elm.val());
elm.select();
}).css({
backgroundColor: "#e9e9e9",
tabIndex: -1,
cursor: "pointer"
});
});
var output = $("<div>").appendTo(h);
function addTextarea(placeholder){
function shape(){
var text = t.val();
t.height((text.split('\n').length + 2) + "em");
}
var t = $("<textarea>", {
placeholder: placeholder
}).appendTo(h).keyup(shape).click(shape).css({
width: "70%",
height: "3em"
});
return t;
}
function addInput({ttl, val, placeholder}){
return $("<input>").attr({
placeholder: placeholder
}).val(val).appendTo($("<div>",{text: ttl + ':'}).appendTo(h));
}
function addBtn(ttl, func){
return $("<button>",{text:ttl}).click(func).appendTo(h);
}
function addBtnToggle(ttl){
var flag = false;
var elm = addBtn(ttl,function(){
flag = !flag;
check.prop("checked", flag);
setColor();
});
var check = $("<input>",{type:"checkbox"}).prependTo(elm);
function setColor(){
elm.css("background-color", flag ? "orange" : "gray");
}
setColor();
return function(){
return flag;
}
}
function copy(str){
var e = document.createElement("textarea");
e.textContent = str;
document.body.appendChild(e);
e.select();
document.execCommand('copy');
document.body.removeChild(e);
return true;
}