From 812aa0addcb4c4f451352e58ff0fc5fb7143abc7 Mon Sep 17 00:00:00 2001 From: Pacalini <141402887+Pacalini@users.noreply.github.com> Date: Wed, 12 Feb 2025 13:54:04 +0800 Subject: [PATCH] jm: fetch img url through setting api (#44) --- jm.js | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/jm.js b/jm.js index 91b03a2..94b8dd1 100644 --- a/jm.js +++ b/jm.js @@ -21,12 +21,7 @@ class JM extends ComicSource { "www.cdnmhwscc.org" ]; - static imageDomains = [ - "cdn-msp.jmapiproxy3.cc", - "cdn-msp3.jmapiproxy3.cc", - "cdn-msp2.jmapiproxy1.cc", - "cdn-msp3.jmapiproxy3.cc", - ]; + static imageUrl = "https://cdn-msp.jmapinodeudzn.net" 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" @@ -37,20 +32,22 @@ class JM extends ComicSource { return `https://${JM.apiDomains[index]}` } - overwriteApiUrls(domains) { - if (domains.length !== 0) JM.apiDomains = domains + get imageUrl() { + return JM.imageUrl + } + + overwriteApiDomains(domains) { + if (domains.length != 0) JM.apiDomains = domains + } + + overwriteImgUrl(url) { + if (url.length != 0) JM.imageUrl = url } isNum(str) { return /^\d+$/.test(str) } - get imageUrl() { - let stream = this.loadSetting('imageStream') - let index = parseInt(stream) - 1 - return `https://${JM.imageDomains[index]}` - } - get apiUa() { return JM.apiUa; } @@ -73,6 +70,7 @@ class JM extends ComicSource { async init() { if (this.loadSetting('refreshDomainsOnStart')) await this.refreshApiDomains(false) + this.refreshImgUrl(false) } /** @@ -117,13 +115,34 @@ class JM extends ComicSource { callback: () => {} }, { - text: "Save", - callback: () => this.overwriteApiUrls(domains) + text: "Apply", + callback: () => { + this.overwriteApiDomains(domains) + this.refreshImgUrl(true) + } } ] ) } else { - this.overwriteApiUrls(domains) + this.overwriteApiDomains(domains) + } + } + + /** + * + * @param showMessage {boolean} + */ + async refreshImgUrl(showMessage) { + let index = this.loadSetting('imageStream') + let res = await this.get( + `${this.baseUrl}/setting?app_img_shunt=${index}` + ) + let setting = JSON.parse(res) + if (setting["img_host"]) { + if (showMessage) { + UI.showMessage(`Image Stream ${index}:\n${setting["img_host"]}`) + } + this.overwriteImgUrl(setting["img_host"]) } }