(update = false)
| 1138 | } |
| 1139 | // 更新外置翻页规则 |
| 1140 | function getRulesUrl(update = false) { |
| 1141 | // 如果是 旧版本的字符串时间格式(当前为数字格式)或 刚安装脚本(取不到值会返回字符串 '' 空),则需要立即更新 |
| 1142 | if (typeof(GM_getValue('menu_ruleUpdateTime', '')) == 'string') {update = true; if (scriptHandler != 'AdGuard') {alert('请点击【确定】开始首次获取【外置翻页规则】(大概几秒\n\n在此期间请不要 操作/跳转/关闭 当前网页~\n\n如果不小心没获取成功也没事,可以去脚本菜单中手动【更新外置翻页规则】即可(浏览器右上角 Tampermonkey 扩展图标内的脚本菜单\n\n\n另外,想要【临时暂停翻页】请点击左下角悬浮的【页码】按钮\n\n如果每次打开网页都会看到该提示,说明你的 油猴脚本管理器与本脚本之间 存在兼容性问题,请更换其他试试!');} else {urlArr2 = urlArr}} |
| 1143 | |
| 1144 | if (update) { // 手动更新(或安装后首次更新) |
| 1145 | GM_notification({text: '🔄 更新外置翻页规则中,请勿操作网页...', timeout: 5000}); |
| 1146 | getRulesUrl_(true); |
| 1147 | } else if (parseInt(+new Date()/1000) - GM_getValue('menu_ruleUpdateTime', 0) > 5184000) { |
| 1148 | getRulesUrl_(); |
| 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) |
no test coverage detected