pull/32/head
kunfei 5 years ago
parent b5a198e887
commit 12e19d41ff
  1. 55
      app/src/main/java/io/legado/app/help/JsExtensions.java
  2. 53
      app/src/main/java/io/legado/app/help/JsExtensions.kt

@ -1,55 +0,0 @@
package io.legado.app.help;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.legado.app.model.analyzeRule.AnalyzeUrl;
import io.legado.app.utils.Encoder;
import io.legado.app.utils.StringUtils;
import retrofit2.Call;
import retrofit2.Response;
public class JsExtensions {
/**
* js实现跨域访问,不能删
*/
public String ajax(String urlStr) {
try {
AnalyzeUrl analyzeUrl = new AnalyzeUrl(urlStr, null, null, null, null, null);
Call call = analyzeUrl.getResponse();
Response response = call.execute();
if (response.body() != null) {
return response.body().toString();
}
} catch (Exception e) {
return e.getLocalizedMessage();
}
return null;
}
/**
* js实现解码,不能删
*/
public String base64Decoder(String str) {
return Encoder.INSTANCE.base64Decoder(str);
}
/**
* 章节数转数字
*/
public String toNumChapter(String s) {
if (s == null) {
return null;
}
Pattern pattern = Pattern.compile("(第)(.+?)(章)");
Matcher matcher = pattern.matcher(s);
if (matcher.find()) {
return matcher.group(1) + StringUtils.INSTANCE.stringToInt(matcher.group(2)) + matcher.group(3);
} else {
return s;
}
}
}

@ -0,0 +1,53 @@
package io.legado.app.help
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.Encoder
import io.legado.app.utils.StringUtils
import java.util.regex.Pattern
@Suppress("unused")
class JsExtensions {
/**
* js实现跨域访问,不能删
*/
fun ajax(urlStr: String): String? {
try {
val analyzeUrl = AnalyzeUrl(urlStr, null, null, null, null, null)
val call = analyzeUrl.getResponse()
val response = call.execute()
if (response.body() != null) {
return response.body()!!.toString()
}
} catch (e: Exception) {
return e.localizedMessage
}
return null
}
/**
* js实现解码,不能删
*/
fun base64Decoder(str: String): String {
return Encoder.base64Decoder(str)
}
/**
* 章节数转数字
*/
fun toNumChapter(s: String?): String? {
if (s == null) {
return null
}
val pattern = Pattern.compile("(第)(.+?)(章)")
val matcher = pattern.matcher(s)
return if (matcher.find()) {
matcher.group(1) + StringUtils.stringToInt(matcher.group(2)) + matcher.group(3)
} else {
s
}
}
}
Loading…
Cancel
Save