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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script src="https://recaptcha.net/recaptcha/api.js?render=你的第一个密钥"></script> <script> function TestUrl(url) { var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; var objExp = new RegExp(Expression); if (objExp.test(url) != true) { return false; } return true; } function showNotification(message, type = "info") { const notification = document.createElement("div"); notification.className = `trm-notification trm-notification-${type}`; notification.innerHTML = ` <div class="trm-notification-content"> <i class="fas ${ type === "error" ? "fa-exclamation-circle" : "fa-check-circle" }"></i> <span>${message}</span> </div> `; document.body.appendChild(notification); setTimeout(() => { notification.classList.add("trm-notification-show"); }, 10); setTimeout(() => { notification.classList.remove("trm-notification-show"); setTimeout(() => { notification.remove(); }, 300); }, 3000); }
function showLoading(message = "处理中...") { const loading = document.createElement("div"); loading.className = "trm-loading"; loading.innerHTML = ` <div class="trm-loading-content"> <div class="trm-loading-spinner"></div> <span>${message}</span> </div> `; document.body.appendChild(loading); return loading; }
function askFriend(event) { let check = $("#friend-check").is(":checked"); let name = $("#friend-name").val(); let url = $("#friend-link").val(); let image = $("#friend-icon").val(); let des = $("#friend-des").val();
if (!check) { showNotification('请勾选"我提交的不是无意义信息"', "error"); return; } if (!(name && url && image && des)) { showNotification("信息填写不完整!", "error"); return; } if (!TestUrl(url)) { showNotification("URL格式错误! 需要包含HTTP协议头!", "error"); return; } if (!TestUrl(image)) { showNotification("图片URL格式错误! 需要包含HTTP协议头!", "error"); return; }
const loading = showLoading("正在提交申请..."); event.target.classList.add("is-loading");
grecaptcha.ready(function () { grecaptcha .execute("你的第一个密钥", { action: "submit", }) .then(function (token) { $.ajax({ type: "get", cache: false, url: url, dataType: "jsonp", async: false, processData: false, timeout: 5000, complete: function (data) { if (data.status == 200) { $.ajax({ type: "POST", dataType: "json", data: { name: name, url: url, image: image, description: des, verify: token, }, url: "https://你的qexo域名/pub/ask_friend/", success: function (data) { showNotification(data.msg, "success"); }, error: function () { showNotification("提交失败,请稍后重试", "error"); }, }); } else { let errorMsg = "URL无法连通! "; if (data.status === 0) { errorMsg += "可能原因:目标网站不支持跨域请求或网络连接失败"; } else if (data.status === 404) { errorMsg += "目标页面不存在"; } else if (data.status === 403) { errorMsg += "目标网站拒绝访问"; } else if (data.status === 500) { errorMsg += "目标网站服务器错误"; } else if (data.status === 503) { errorMsg += "目标网站暂时不可用"; } else { errorMsg += "HTTP状态码: " + data.status; } showNotification(errorMsg, "error"); } loading.remove(); event.target.classList.remove("is-loading"); }, }); }); }); } </script> <script src="https://registry.npmmirror.com/qexo-static/1.6.0/files/hexo/friends.js"></script> <script> function loadQexoFriends(id, url) { var uri = url + "/pub/friends/"; var loadStyle = '<div class="qexo_loading"><div class="qexo_part"><div style="display: flex; justify-content: center"><div class="qexo_loader"><div class="qexo_inner one"></div><div class="qexo_inner two"></div><div class="qexo_inner three"></div></div></div></div><p style="text-align: center; display: block">友链加载中...</p></div>'; document.getElementById(id).className = "qexo-friends"; document.getElementById(id).innerHTML = loadStyle; var ajax; try { // Firefox, Opera 8.0+, Safari ajax = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { ajax = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajax = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("糟糕,你的浏览器不能上传文件!"); return false; } } } ajax.open("get", uri, true); ajax.setRequestHeader("Content-Type", "text/plain"); ajax.onreadystatechange = function () { if (ajax.readyState == 4) { if (ajax.status == 200) { var res = JSON.parse(ajax.response); if (res["status"]) { var friends = res["data"]; document.getElementById(id).innerHTML = ""; for (let i = 0; i < friends.length; i++) { document.getElementById(id).innerHTML += '<p><a target="_blank" href="' + friends[i]["url"] + '" title="' + friends[i]["name"] + '" class="qexo-friendurl"></p><div class="qexo-frienddiv"><div class="qexo-frienddivleft"><img class="qexo-myfriend" src="' + friends[i]["image"] + '"></div><div class="qexo-frienddivright"><span style="font-weight: bold;">' + friends[i]["name"] + "</span><br>" + friends[i]["description"] + "</div></div></a>"; } } else { console.log(res["data"]["msg"]); } } else { console.log("友链获取失败! 网络错误"); } } }; ajax.send(null); } const iconInput = document.getElementById("friend-icon"); const nameInput = document.getElementById("friend-name"); const desInput = document.getElementById("friend-des"); const previewImg = document.querySelector(".qexo-myfriend"); const previewName = document.querySelector("#preview-name"); const previewDes = document.querySelector("#preview-des");
function updatePreview() { if (iconInput.value) { previewImg.src = iconInput.value; previewImg.style.display = "block"; document.querySelector(".qexo-default-icon").style.display = "none"; } else { previewImg.style.display = "none"; document.querySelector(".qexo-default-icon").style.display = "flex"; } previewName.textContent = nameInput.value || "您的站点名"; previewDes.textContent = desInput.value || "站点描述"; }
iconInput.addEventListener("input", updatePreview); nameInput.addEventListener("input", updatePreview); desInput.addEventListener("input", updatePreview); </script>
|