-
Notifications
You must be signed in to change notification settings - Fork 0
/
nhentai error handler.js
60 lines (55 loc) · 2.84 KB
/
nhentai error handler.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
// ==UserScript==
// @name Nhentai.net Errors Automatically resolve
// @name:zh-TW Nhentai.net 錯誤自動排除
// @name:zh-CN Nhentai.net 错误自动排除
// @version 1.1
// @description Automatically resolves "403 - CSRF Token Invalid" or "429 Too Many Requests" or "404 - Not Found" displayed on nhentai.net web pages. (Script assisted by ChatGPT)
// @description:zh-TW 自動解決 nhentai.net 網頁上顯示 "403 – CSRF Token Invalid" 或 "429 Too Many Requests" 或 "404 – Not Found"(此腳本由ChatGPT協助撰寫)
// @description:zh-CN 自动解决 nhentai.net 网页上显示 "403 – CSRF Token Invalid" 或 "429 Too Many Requests" 或 "404 – Not Found"(此脚本由ChatGPT协助撰写)
// @author 特務E04
// @match https://nhentai.net/*
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @noframes
// @supportURL https://github.com/jmsch23280866/Nhentai-403-404-429-automate/issues
// @license MIT
// @namespace https://github.com/jmsch23280866
// ==/UserScript==
(function() {
'use strict';
// 檢查網頁是否顯示 "403 – CSRF Token Invalid" 或 "ERR_CACHE_MISS"
function checkFor403OrCacheMiss() {
if ($('body:contains("403 – CSRF Token Invalid")').length > 0 || $('body:contains("ERR_CACHE_MISS")').length > 0) {
console.log("Detected 403 – CSRF Token Invalid or ERR_CACHE_MISS, changing URL from https to http in 2 seconds...");
setTimeout(function() {
let newUrl = window.location.href.replace(/^https:/, 'http:');
window.location.href = newUrl; // 將網址中的 https 改為 http 並重新加載
}, 1000); // 1秒後修改網址並重新加載
}
}
// 檢查網頁是否顯示 "429 Too Many Requests"
function checkFor429() {
if ($('body:contains("429 Too Many Requests")').length > 0) {
console.log("Detected 429 Too Many Requests, refreshing in 2 seconds...");
setTimeout(function() {
location.reload(); // 普通重新整理
}, 1000); // 1秒後重新整理
}
}
// 檢查網頁是否顯示 "404 – Not Found"
function checkFor404() {
if ($('body:contains("404 – Not Found")').length > 0) {
console.log("Detected 404 – Not Found, redirecting to Web Archive in 2 seconds...");
setTimeout(function() {
let currentUrl = window.location.href;
let archiveUrl = 'https://web.archive.org/web/' + currentUrl;
window.location.href = archiveUrl; // 跳轉到 Web Archive 的對應頁面
}, 1000); // 1秒後跳轉
}
}
// 當頁面加載完成後檢查一次
document.addEventListener('DOMContentLoaded', function() {
checkFor403OrCacheMiss();
checkFor429();
checkFor404();
});
})();