From 65aeab9e75d94f3e0a1a5e16b17bed66af54463e Mon Sep 17 00:00:00 2001 From: Pacalini <141402887+Pacalini@users.noreply.github.com> Date: Tue, 21 Jan 2025 16:27:53 +0800 Subject: [PATCH] jm: support domain-updating API (#37) * jm: support domain-updating API * jm: raise minAppVersion * jm: add refresh domain callback * jm: raise minAppVersion --- index.json | 2 +- jm.js | 111 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 95 insertions(+), 18 deletions(-) diff --git a/index.json b/index.json index b160661..fcf643f 100644 --- a/index.json +++ b/index.json @@ -45,6 +45,6 @@ "name": "禁漫天堂", "fileName": "jm.js", "key": "jm", - "version": "1.0.2" + "version": "1.0.3" } ] diff --git a/jm.js b/jm.js index cf98146..165d625 100644 --- a/jm.js +++ b/jm.js @@ -7,25 +7,25 @@ class JM extends ComicSource { // unique id of the source key = "jm" - version = "1.0.2" + version = "1.0.3" - minAppVersion = "1.0.2" + minAppVersion = "1.2.1" // update url url = "https://raw.githubusercontent.com/venera-app/venera-configs/refs/heads/main/jm.js" static apiDomains = [ - "https://www.jmapiproxyxxx.vip", - "https://www.cdnblackmyth.club", - "https://www.cdnmhws.cc", - "https://www.cdnmhwscc.org" + "www.jmapiproxyxxx.vip", + "www.cdnblackmyth.club", + "www.cdnmhws.cc", + "www.cdnmhwscc.org" ]; - static imageUrls = [ - "https://cdn-msp.jmapiproxy3.cc", - "https://cdn-msp3.jmapiproxy3.cc", - "https://cdn-msp2.jmapiproxy1.cc", - "https://cdn-msp3.jmapiproxy3.cc", + static imageDomains = [ + "cdn-msp.jmapiproxy3.cc", + "cdn-msp3.jmapiproxy3.cc", + "cdn-msp2.jmapiproxy1.cc", + "cdn-msp3.jmapiproxy3.cc", ]; static apiUa = "Mozilla/5.0 (Linux; Android 10; K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/130.0.0.0 Mobile Safari/537.36" @@ -34,7 +34,11 @@ class JM extends ComicSource { get baseUrl() { let index = parseInt(this.loadSetting('apiDomain')) - 1 - return JM.apiDomains[index] + return `https://${JM.apiDomains[index]}` + } + + overwriteApiUrls(domains) { + if (domains.length != 0) JM.apiDomains = domains } isNum(str) { @@ -44,7 +48,7 @@ class JM extends ComicSource { get imageUrl() { let stream = this.loadSetting('imageStream') let index = parseInt(stream) - 1 - return JM.imageUrls[index] + return `https://${JM.imageDomains[index]}` } get apiUa() { @@ -67,6 +71,62 @@ class JM extends ComicSource { return `${this.imageUrl}/media/users/${imageName}` } + async init() { + if (this.loadSetting('refreshDomainsOnStart')) await this.refreshApiDomains(false) + } + + /** + * + * @param showConfirmDialog {boolean} + */ + async refreshApiDomains(showConfirmDialog) { + let today = new Date(); + let url = "https://jmappc01-1308024008.cos.ap-guangzhou.myqcloud.com/server-2024.txt" + let domainSecret = "diosfjckwpqpdfjkvnqQjsik" + let title = "" + let message = "" + let domains = [] + let res = await fetch( + `${url}?time=${today.getFullYear()}${today.getMonth() + 1}${today.getDate()}`, + {headers: {"User-Agent": this.imgUa}} + ) + if (res.status == 200) { + let data = this.convertData(await res.text(), domainSecret) + let json = JSON.parse(data) + if (json["Server"]) { + title = "Update Success" + message = "New domains:\n\n" + domains = json["Server"] + } + } + if (domains.length == 0) { + title = "Update Failed" + message = `Using built-in domains:\n\n` + domains = JM.apiDomains + } + for (let i = 0; i < domains.length; i++) { + message = message + `Stream ${i + 1}: ${domains[i]}\n` + } + if (showConfirmDialog) { + UI.showDialog( + title, + message, + [ + { + text: "Cancle", + callback: () => {} + }, + { + text: "Save", + callback: () => this.overwriteApiUrls(domains) + } + ] + ) + } else { + this.overwriteApiUrls(domains) + } + } + /** * * @param comic {object} @@ -114,9 +174,8 @@ class JM extends ComicSource { * @param time {number} * @returns {string} */ - convertData(input, time) { - let secret = '185Hcomic3PAPP7R' - let key = Convert.encodeUtf8(Convert.hexEncode(Convert.md5(Convert.encodeUtf8(`${time}${secret}`)))) + convertData(input, secret) { + let key = Convert.encodeUtf8(Convert.hexEncode(Convert.md5(Convert.encodeUtf8(secret)))) let data = Convert.decodeBase64(input) let decrypted = Convert.decryptAesEcb(data, key) let res = Convert.decodeUtf8(decrypted) @@ -134,6 +193,7 @@ class JM extends ComicSource { */ async get(url) { let time = Math.floor(Date.now() / 1000) + let kJmSecret = "185Hcomic3PAPP7R" let res = await Network.get(url, this.getHeaders(time)) if(res.status !== 200) { if(res.status === 401) { @@ -151,7 +211,7 @@ class JM extends ComicSource { if(typeof data !== 'string') { throw 'Invalid Data' } - return this.convertData(data, time) + return this.convertData(data, `${time}${kJmSecret}`) } // explore page list @@ -607,6 +667,17 @@ class JM extends ComicSource { ``` */ settings = { + refreshDomains: { + title: "Refresh Domain List", + type: "callback", + buttonText: "Refresh", + callback: () => this.refreshApiDomains(true) + }, + refreshDomainsOnStart: { + title: "Refresh Domain List on Startup", + type: "switch", + default: true, + }, apiDomain: { title: "Api Domain", type: "select", @@ -650,10 +721,16 @@ class JM extends ComicSource { // [Optional] translations for the strings in this config translation = { 'zh_CN': { + 'Refresh Domain List': '刷新域名列表', + 'Refresh': '刷新', + 'Refresh Domain List on Startup': '启动时刷新域名列表', 'Api Domain': 'Api域名', 'Image Stream': '图片分流', }, 'zh_TW': { + 'Refresh Domain List': '刷新域名列表', + 'Refresh': '刷新', + 'Refresh Domain List on Startup': '啟動時刷新域名列表', 'Api Domain': 'Api域名', 'Image Stream': '圖片分流', },