MCPcopy Index your code
hub / github.com/XIU2/UserScript / getRulesUrl_

Function getRulesUrl_

Autopage.user.js:1151–1202  ·  view source on GitHub ↗
(n = false, url)

Source from the content-addressed store, hash-verified

1149 }
1150
1151 function getRulesUrl_(n = false, url) {
1152 if (n) {url = urlArr2[Math.floor(Math.random()*urlArr2.length)];} else {url = urlArr[Math.floor(Math.random()*urlArr.length)];}
1153 if (url === undefined) {GM_notification({text: '❌ 所有更新地址均以试过,已无可用地址,请联系作者解决...', timeout: 5000}); return}
1154 //console.log(url); return
1155 GM_xmlhttpRequest({
1156 url: url,
1157 method: 'GET',
1158 responseType: 'json',
1159 overrideMimeType: 'application/json; charset=utf-8',
1160 timeout: 4000,
1161 onload: function (response) {
1162 try {
1163 //console.log('最终 URL:' + response.finalUrl, '返回内容:',response.status,response.response,response.responseText, response.responseHeaders)
1164 if (response.status === 200 && response.response && Object.prototype.toString.call(response.response) === '[object Object]' && Object.keys(response.response).length > 100) {
1165 GM_setValue('menu_rules', response.response); // 写入最新规则
1166 GM_setValue('menu_ruleUpdateTime', parseInt(+new Date()/1000)); // 写入当前时间戳
1167
1168 curSite = {SiteTypeID: 0}; pageNum.now = 1; // 重置规则+页码
1169 registerMenuCommand(); // 重新判断规则
1170
1171 webTypeIf(); // 判断网站类型
1172 if (!GM_getValue('menu_thread')) {if (curSite.thread) {curSite = {SiteTypeID: 0}; pageNum.now = 1;}} // 帖子内自动翻页判断
1173 if (GM_getValue('menu_page_number')) {pageNumber('add');} else {pageNumber('set');} // 显示页码
1174 if (curSite.blank != undefined) setTimeout(forceTarget, 1000); // 强制新标签页打开链接
1175 if (curSite.style) {insStyle(curSite.style)} // 插入 Style CSS 样式
1176 pausePageEvent(); // 左键双击网页空白处暂停翻页
1177 pageLoading(); // 自动无缝翻页
1178
1179 if (n) GM_notification({text: '✅ 已更新外置翻页规则!\n如果依然无法翻页,说明还不支持当前网页,点击此处提交申请~', timeout: 5000, onclick: function(){GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});GM_openInTab('https://greasyfork.org/zh-CN/scripts/419215/feedback', {active: true,insert: true,setParent: true});}});
1180 } else {
1181 console.log('URL:' + url, response);
1182 GM_notification({text: '❌ 为空!更新失败,请再试几次...\n如果依然更新失败,请联系作者解决...', timeout: 5000});
1183 if (n) {urlArr2.splice(urlArr2.indexOf(url), 1)} else {urlArr.splice(urlArr.indexOf(url), 1)}
1184 }
1185 } catch (e) {
1186 console.log('URL:' + url, e);
1187 GM_notification({text: '❌ 报错!更新失败,请再试几次...\n如果依然更新失败,请联系作者解决...', timeout: 5000});
1188 if (n) {urlArr2.splice(urlArr2.indexOf(url), 1)} else {urlArr.splice(urlArr.indexOf(url), 1)}
1189 }
1190 },
1191 onerror: function (response) {
1192 console.log('URL:' + url, response)
1193 GM_notification({text: '❌ 错误!更新失败,请再试几次...\n如果依然更新失败,请联系作者解决...', timeout: 5000});
1194 if (n) {urlArr2.splice(urlArr2.indexOf(url), 1)} else {urlArr.splice(urlArr.indexOf(url), 1)}
1195 },
1196 ontimeout: function (response) {
1197 console.log('URL:' + url, response)
1198 GM_notification({text: '❌ 超时!更新失败,请再试几次...\n如果依然更新失败,请联系作者解决...', timeout: 5000});
1199 if (n) {urlArr2.splice(urlArr2.indexOf(url), 1)} else {urlArr.splice(urlArr.indexOf(url), 1)}
1200 }
1201 })
1202 }
1203 }
1204
1205

Callers 1

getRulesUrlFunction · 0.85

Calls 6

webTypeIfFunction · 0.85
pageNumberFunction · 0.85
insStyleFunction · 0.85
pausePageEventFunction · 0.85
registerMenuCommandFunction · 0.70
pageLoadingFunction · 0.70

Tested by

no test coverage detected