function qexo_friend_api(id, url, reCaptcha = '') { qexo_url = url; Qexo_reCaptcha_Key = reCaptcha var loadStyle = '

友链申请加载中...

'; document.getElementById(id).className = "friend-api"; document.getElementById(id).innerHTML = loadStyle; document.getElementById(id).innerHTML = '

请正确填写友链,然后点击申请等待核实,请先添加本站友链






'; } function friend_api() { document.getElementById('qexo-friend-btn').style.color = '#000'; document.getElementById('qexo-friend-btn').style.backgroundColor = '#fff'; document.getElementById('qexo-friend-btn').innerHTML = '…'; let ask = function (token = '') { var name = document.getElementById('qexo_friend_name').value; var introduction = document.getElementById('qexo_friend_brief introduction').value; var website = document.getElementById('qexo_friend_website').value; var logo = document.getElementById('qexo_friend_logo').value; var uri = qexo_url + '/pub/ask_friend/'; if (!name || !website || !logo) { document.getElementById('qexo-friend-btn').style.backgroundColor = '#f5365c'; document.getElementById('qexo-friend-btn').innerHTML = "请先填写内容"; return 0; } if (!/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/.test(website) || !/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/.test(logo)) { document.getElementById('qexo-friend-btn').style.backgroundColor = '#f5365c'; document.getElementById('qexo-friend-btn').innerHTML = "请填写正确的网址"; return 0; } let body = { name: name, url: website, image: logo, description: introduction } if (token) { body["verify"] = token; } data = '' for (i in body) { data += `&${i}=${encodeURIComponent(body[i])}` } data = data.slice(1) fetch(uri, { method: 'post', body: data, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).then(function (data) { if (data.ok) { data.json().then(function (res) { document.getElementById('qexo-friend-btn').style.color = '#fff'; if (res["status"]) { document.getElementById('qexo-friend-btn').style.backgroundColor = '#2dce89'; document.getElementById('qexo-friend-btn').innerHTML = '提交成功!请等待确认!'; } else { document.getElementById('qexo-friend-btn').style.backgroundColor = '#f5365c'; document.getElementById('qexo-friend-btn').innerHTML = "友链申请失败 提示:" + res["msg"]; } }); } else { document.getElementById('qexo-friend-btn').style.color = '#fff'; document.getElementById('qexo-friend-btn').style.backgroundColor = '#f5365c'; document.getElementById('qexo-friend-btn').innerHTML = "网络异常!"; } }); } if (Qexo_reCaptcha_Key) { grecaptcha.ready(function () { grecaptcha.execute(reCaptcha, {action: 'submit'}).then(function (token) { ask(token) }); }); } else { ask() } }