Skip to content

Commit

Permalink
Merge pull request #6 from kairi003/feature/support-new-html-format
Browse files Browse the repository at this point in the history
[v0.2.3] Feature/support new html format
  • Loading branch information
kairi003 authored Sep 22, 2024
2 parents 4fd6a8b + ed58633 commit 882d526
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/tmp/
/tmp2/
/.keystore
*.apk
*.apk.idsig
*.bsdiff

/setup.sh
/build.sh
/deploy.sh
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ keytool -printcert -jarfile narou-mod.apk
- keytool : JDKに含まれる
- apksigner : Android SDKに含まれる
- zipalign : Android SDKに含まれる
- apktool (2.9.3) : https://ibotpeaches.github.io/Apktool/
- apktool (2.9.3) : https://apktool.org/docs/install/
### Ubuntuでのインストール例
```bash
sudo apt update
sudo apt install openjdk-18-jdk-headless apksigner zipalign apktool
sudo apt install openjdk-18-jdk-headless apksigner zipalign imagemagick
sudo ./install-apktool.sh # apktoolのインストール
```

## 使い方
Expand Down Expand Up @@ -135,3 +136,20 @@ keytool -genkeypair -v -keystore .keystore -alias narou-mod -keyalg RSA -keysize

### okhttp3
- SSL通信でクラッシュする不具合が修正されているためバージョンアップ

### fix-html-change.diff
- 「小説家になろう」のHTML構造変更に対応
```
.index_box -> .p-eplist
.subtitle a -> a.p-eplist__subtitle
.long_update -> .p-eplist__update
.novelview_pager-next -> .c-pager__item--next
.novelview_pager-last -> .c-pager__item--last
chapter_title -> p-eplist__chapter-title
novel_sublist2 -> p-eplist__sublist
"<div id=\"novel_a\" class=\"novel_view\">\n([\\s\\S]+?)</div>" -> "<div class=\"js-novel-text p-novel__text p-novel__text--afterword\">\n([\\s\\S]+?)</div>"
"<div id=\"novel_p\" class=\"novel_view\">\n([\\s\\S]+?)</div>" -> "<div class=\"js-novel-text p-novel__text p-novel__text--preface\">\n([\\s\\S]+?)</div>"
"<p class=\"novel_subtitle\">(.+?)</p>" -> "<h1 class=\"p-novel__title p-novel__title--rensai\">(.+?)</h1>"
"<div id=\"novel_honbun\" class=\"novel_view\">\n([\\s\\S]+?)</div>" -> "<div class=\"js-novel-text p-novel__text\">\n([\\s\\S]+?)</div>"
```
7 changes: 7 additions & 0 deletions install_apktool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

VERSION=${VERSION:=2.9.3}

wget -O /usr/local/bin/apktool "https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool"
wget -O /usr/local/bin/apktool.jar "https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_${VERSION}.jar"
chmod +x /usr/local/bin/apktool
149 changes: 149 additions & 0 deletions patches/fix-html-change.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
diff -urwN -U5 tmp/dec/smali_classes2/com/tscsoft/naroureader/NovelHtmlObject$EpisodeFetcher.smali tmp/mod/smali_classes2/com/tscsoft/naroureader/NovelHtmlObject$EpisodeFetcher.smali
--- tmp/dec/smali_classes2/com/tscsoft/naroureader/NovelHtmlObject$EpisodeFetcher.smali 2024-09-22 04:13:13.726369989 +0900
+++ tmp/mod/smali_classes2/com/tscsoft/naroureader/NovelHtmlObject$EpisodeFetcher.smali 2024-09-22 04:16:49.885333720 +0900
@@ -181,11 +181,11 @@
:cond_0
invoke-static {p1}, Lorg/jsoup/Jsoup;->parse(Ljava/lang/String;)Lorg/jsoup/nodes/Document;

move-result-object p1

- const-string v0, ".index_box"
+ const-string v0, ".p-eplist"

.line 120
invoke-virtual {p1, v0}, Lorg/jsoup/nodes/Element;->select(Ljava/lang/String;)Lorg/jsoup/select/Elements;

move-result-object p1
@@ -283,11 +283,11 @@

.line 162
:cond_0
iget-object v0, p0, Lcom/tscsoft/naroureader/NovelHtmlObject$EpisodeFetcher;->mEpisodeElement:Lorg/jsoup/nodes/Element;

- const-string v1, ".subtitle a"
+ const-string v1, ".p-eplist__subtitle a"

invoke-virtual {v0, v1}, Lorg/jsoup/nodes/Element;->select(Ljava/lang/String;)Lorg/jsoup/select/Elements;

move-result-object v0

@@ -350,11 +350,11 @@
invoke-virtual {v1, v0}, Lcom/tscsoft/naroureader/beans/NovelBean;->setNumber(I)V

.line 177
iget-object v0, p0, Lcom/tscsoft/naroureader/NovelHtmlObject$EpisodeFetcher;->mEpisodeElement:Lorg/jsoup/nodes/Element;

- const-string v1, ".long_update"
+ const-string v1, ".p-eplist__update"

invoke-virtual {v0, v1}, Lorg/jsoup/nodes/Element;->select(Ljava/lang/String;)Lorg/jsoup/select/Elements;

move-result-object v0

@@ -611,11 +611,11 @@
.line 144
invoke-virtual {v0}, Lorg/jsoup/nodes/Element;->className()Ljava/lang/String;

move-result-object v3

- const-string v4, "chapter_title"
+ const-string v4, "p-eplist__chapter-title"

invoke-virtual {v4, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v3

@@ -640,11 +640,11 @@
:cond_2
invoke-virtual {v0}, Lorg/jsoup/nodes/Element;->className()Ljava/lang/String;

move-result-object v3

- const-string v4, "novel_sublist2"
+ const-string v4, "p-eplist__sublist"

invoke-virtual {v4, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v3

diff -urwN -U5 tmp/dec/smali_classes2/com/tscsoft/naroureader/utils/CacheManager$H2CPatterns.smali tmp/mod/smali_classes2/com/tscsoft/naroureader/utils/CacheManager$H2CPatterns.smali
--- tmp/dec/smali_classes2/com/tscsoft/naroureader/utils/CacheManager$H2CPatterns.smali 2024-09-22 14:26:56.262148680 +0900
+++ tmp/mod/smali_classes2/com/tscsoft/naroureader/utils/CacheManager$H2CPatterns.smali 2024-09-22 18:38:29.871621561 +0900
@@ -36,38 +36,38 @@

# direct methods
.method static constructor <clinit>()V
.locals 1

- const-string v0, "<p class=\"novel_subtitle\">(.+?)</p>"
+ const-string v0, "<h1 class=\"p-novel__title p-novel__title--rensai\">(.+?)</h1>"

.line 117
invoke-static {v0}, Ljava/util/regex/Pattern;->compile(Ljava/lang/String;)Ljava/util/regex/Pattern;

move-result-object v0

sput-object v0, Lcom/tscsoft/naroureader/utils/CacheManager$H2CPatterns;->Subtitle:Ljava/util/regex/Pattern;

- const-string v0, "<div id=\"novel_p\" class=\"novel_view\">\n([\\s\\S]+?)</div>"
+ const-string v0, "<div class=\"js-novel-text p-novel__text p-novel__text--preface\">\n([\\s\\S]+?)</div>"

.line 118
invoke-static {v0}, Ljava/util/regex/Pattern;->compile(Ljava/lang/String;)Ljava/util/regex/Pattern;

move-result-object v0

sput-object v0, Lcom/tscsoft/naroureader/utils/CacheManager$H2CPatterns;->Foreword:Ljava/util/regex/Pattern;

- const-string v0, "<div id=\"novel_a\" class=\"novel_view\">\n([\\s\\S]+?)</div>"
+ const-string v0, "<div class=\"js-novel-text p-novel__text p-novel__text--afterword\">\n([\\s\\S]+?)</div>"

.line 119
invoke-static {v0}, Ljava/util/regex/Pattern;->compile(Ljava/lang/String;)Ljava/util/regex/Pattern;

move-result-object v0

sput-object v0, Lcom/tscsoft/naroureader/utils/CacheManager$H2CPatterns;->Afterword:Ljava/util/regex/Pattern;

- const-string v0, "<div id=\"novel_honbun\" class=\"novel_view\">\n([\\s\\S]+?)</div>"
+ const-string v0, "<div class=\"js-novel-text p-novel__text\">\n([\\s\\S]+?)</div>"

.line 120
invoke-static {v0}, Ljava/util/regex/Pattern;->compile(Ljava/lang/String;)Ljava/util/regex/Pattern;

move-result-object v0
diff -urwN -U5 tmp/dec/smali_classes2/com/tscsoft/naroureader/utils/CacheManager.smali tmp/mod/smali_classes2/com/tscsoft/naroureader/utils/CacheManager.smali
--- tmp/dec/smali_classes2/com/tscsoft/naroureader/utils/CacheManager.smali 2024-09-22 17:50:39.631651001 +0900
+++ tmp/mod/smali_classes2/com/tscsoft/naroureader/utils/CacheManager.smali 2024-09-22 18:38:29.871621561 +0900
@@ -21,13 +21,13 @@

.field public static final EXT_TXT:Ljava/lang/String; = ".txt"

.field private static final KANA:Ljava/lang/String; = "[\\p{InHiragana}\\p{InKatakana}\u2026\u30fb]"

-.field private static final RE_H2C_AFTERWORD:Ljava/lang/String; = "<div id=\"novel_a\" class=\"novel_view\">\n([\\s\\S]+?)</div>"
+.field private static final RE_H2C_AFTERWORD:Ljava/lang/String; = "<div class=\"js-novel-text p-novel__text p-novel__text--afterword\">\n([\\s\\S]+?)</div>"

-.field private static final RE_H2C_FOREWORD:Ljava/lang/String; = "<div id=\"novel_p\" class=\"novel_view\">\n([\\s\\S]+?)</div>"
+.field private static final RE_H2C_FOREWORD:Ljava/lang/String; = "<div class=\"js-novel-text p-novel__text p-novel__text--preface\">\n([\\s\\S]+?)</div>"

.field private static final RE_H2C_IMAGE_MITEMIN:Ljava/lang/String; = "<a href=\"\\w*:?//([0-9]+?)\\.mitemin\\.net/(i[0-9]+?)/\".*?>"

.field private static final RE_H2C_NO_RUBY:Ljava/lang/String; = "([|\uff5c])([\u300a(\uff08]([^|\uff5c\\t]{1,10}|([\\p{InHiragana}\\p{InKatakana}\u2026\u30fb]{1,10})([ \u3000]?)([\\p{InHiragana}\\p{InKatakana}\u2026\u30fb]{0,10}))[\u300b)\uff09])"

@@ -35,13 +35,13 @@

.field private static final RE_H2C_NO_RUBY2:Ljava/lang/String; = "(([\\p{InCJKUnifiedIdeographs}a-zA-Z\uff41-\uff5a\uff21-\uff3a]{1,10})|([\\p{InCJKUnifiedIdeographs}a-zA-Z\uff41-\uff5a\uff21-\uff3a]{1,10})([ \u3000])([\\p{InCJKUnifiedIdeographs}a-zA-Z\uff41-\uff5a\uff21-\uff3a]{1,10}))([(\uff08\u300a]([\\p{InHiragana}\\p{InKatakana}\u2026\u30fb]{1,10})([ \u3000]?)([\\p{InHiragana}\\p{InKatakana}\u2026\u30fb]{0,10})[)\uff09\u300b])"

.field private static final RE_H2C_RUBY:Ljava/lang/String; = "<ruby><rb>(.+?)</rb><rp>.+?</rp><rt>(.+?)</rt><rp>.+?</rp></ruby>"

-.field private static final RE_H2C_SUBTITLE:Ljava/lang/String; = "<p class=\"novel_subtitle\">(.+?)</p>"
+.field private static final RE_H2C_SUBTITLE:Ljava/lang/String; = "<h1 class=\"p-novel__title p-novel__title--rensai\">(.+?)</h1>"

-.field private static final RE_H2C_TEXT:Ljava/lang/String; = "<div id=\"novel_honbun\" class=\"novel_view\">\n([\\s\\S]+?)</div>"
+.field private static final RE_H2C_TEXT:Ljava/lang/String; = "<div class=\"js-novel-text p-novel__text\">\n([\\s\\S]+?)</div>"

.field private static final RE_IMAGE:Ljava/lang/String; = "&lt;(i[0-9]+?)\\|([0-9]+?)&gt;"

.field private static final RE_IMAGE_CODE:Ljava/lang/String; = "[0-9]+?"

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.method static constructor <clinit>()V
.locals 3

.line 89
.line 90
invoke-static {}, Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;->values()[Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;

move-result-object v0
Expand Down
32 changes: 16 additions & 16 deletions patches/smali/com/tscsoft/naroureader/utils/Modding.smali
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}
.end annotation

.line 101
.line 102
invoke-static {p0}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

move-result v0
Expand All @@ -49,15 +49,15 @@

return-object p0

.line 102
.line 103
:cond_0
invoke-static {p0}, Lorg/jsoup/Jsoup;->parse(Ljava/lang/String;)Lorg/jsoup/nodes/Document;

move-result-object v0

const-string v1, "a.novelview_pager-last[href]"
const-string v1, "a.c-pager__item--last[href]"

.line 103
.line 104
invoke-virtual {v0, v1}, Lorg/jsoup/nodes/Document;->selectFirst(Ljava/lang/String;)Lorg/jsoup/nodes/Element;

move-result-object v0
Expand All @@ -66,7 +66,7 @@

return-object p0

.line 105
.line 106
:cond_1
new-instance p0, Ljava/net/URL;

Expand All @@ -82,7 +82,7 @@

invoke-direct {p0, v1, v0}, Ljava/net/URL;-><init>(Ljava/net/URL;Ljava/lang/String;)V

.line 106
.line 107
new-instance v0, Ljava/lang/StringBuilder;

const-string v1, "Fetch: "
Expand All @@ -101,7 +101,7 @@

invoke-static {v1, v0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

.line 107
.line 108
invoke-virtual {p0}, Ljava/net/URL;->toExternalForm()Ljava/lang/String;

move-result-object p0
Expand All @@ -116,7 +116,7 @@
.method private static getUpdateStartNo(Lorg/jsoup/nodes/Document;)I
.locals 2

const-string v0, ".index_box .subtitle a[href]"
const-string v0, ".p-eplist .p-eplist__subtitle a[href]"

.line 26
invoke-virtual {p0, v0}, Lorg/jsoup/nodes/Document;->selectFirst(Ljava/lang/String;)Lorg/jsoup/nodes/Element;
Expand Down Expand Up @@ -293,7 +293,7 @@

move-result-object v0

const-string v3, ".index_box"
const-string v3, ".p-eplist"

.line 43
invoke-virtual {v0, v3}, Lorg/jsoup/nodes/Document;->selectFirst(Ljava/lang/String;)Lorg/jsoup/nodes/Element;
Expand Down Expand Up @@ -460,7 +460,7 @@
invoke-static {v1, p0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

:cond_2
const-string p0, "a.novelview_pager-next[href]"
const-string p0, "a.c-pager__item--next[href]"

.line 60
invoke-virtual {v0, p0}, Lorg/jsoup/nodes/Document;->selectFirst(Ljava/lang/String;)Lorg/jsoup/nodes/Element;
Expand Down Expand Up @@ -597,7 +597,7 @@
.line 72
throw p0

.line 84
.line 85
:cond_5
:goto_1
invoke-virtual {v0}, Lorg/jsoup/nodes/Document;->outerHtml()Ljava/lang/String;
Expand All @@ -612,12 +612,12 @@
.method public static switchViewerMode(Lcom/tscsoft/naroureader/presenters/ViewerActivityPresenter;)V
.locals 3

.line 88
.line 89
invoke-static {}, Lcom/tscsoft/naroureader/settings/GS;->gs()Lcom/tscsoft/naroureader/settings/GS;

move-result-object v0

.line 89
.line 90
sget-object v1, Lcom/tscsoft/naroureader/utils/Modding$1;->$SwitchMap$com$tscsoft$naroureader$settings$ViewerSetting$ViewMode:[I

invoke-virtual {v0}, Lcom/tscsoft/naroureader/settings/GS;->getViewerMode()Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;
Expand All @@ -640,21 +640,21 @@

goto :goto_0

.line 94
.line 95
:cond_0
sget-object v1, Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;->HorizontalScroll:Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;

invoke-virtual {v0, v1}, Lcom/tscsoft/naroureader/settings/GS;->setViewerMode(Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;)V

goto :goto_0

.line 91
.line 92
:cond_1
sget-object v1, Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;->VerticalPaging:Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;

invoke-virtual {v0, v1}, Lcom/tscsoft/naroureader/settings/GS;->setViewerMode(Lcom/tscsoft/naroureader/settings/ViewerSetting$ViewMode;)V

.line 97
.line 98
:goto_0
invoke-virtual {p0}, Lcom/tscsoft/naroureader/presenters/ViewerActivityPresenter;->onViewerPreferenceReload()V

Expand Down
2 changes: 1 addition & 1 deletion patches/version.diff
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ diff -urN tmp/dec/apktool.yml tmp/mod/apktool.yml
- versionCode: 180
+ versionCode: 181
- versionName: 1.35.6
+ versionName: 1.35.6+0.2.2
+ versionName: 1.35.6+0.2.3
resourcesAreCompressed: false
sharedLibrary: false
sparseResources: false
16 changes: 13 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
#!/bin/bash

set -o errexit
set -e

echo Cleaning up
rm -rf tmp
mkdir tmp

echo Decoding original APK
apktool decode -f -o tmp/dec original.apk

# overwite smali files
echo Overwriting smali files
rm -rf tmp/dec/smali_classes2/okhttp3 \
tmp/dec/smali_classes2/org/jsoup
cp -r patches/smali/* tmp/dec/smali_classes2/

# apply patches
echo Applying patches
patch -u -p0 < patches/fix-update-100.diff
patch -u -p0 < patches/min-index-update.diff
patch -u -p0 < patches/fix-last-page-evaluation.diff
# patch -u -p0 < patches/switch-page-view.diff
patch -u -p0 < patches/switch-page-view.diff
patch -u -p0 < patches/fix-min-update-chapter.diff
patch -u -p0 < patches/fix-html-change.diff
patch -u -p0 < patches/version.diff

# change package name to com.tscsoft.naroureader_mod_mod_mod
echo Changing package name
DIR=tmp/dec bash patches/rename.sh

# build APK
echo Building APK
apktool build -f -o tmp/mod-unaligned.apk tmp/dec

# sign APK
echo Signing APK
zipalign -f -v 4 tmp/mod-unaligned.apk tmp/mod-unsigned.apk

KEY_PASS=${KEY_PASS:=stdin}
apksigner sign --ks .keystore -v --v2-signing-enabled true --ks-key-alias narou-mod --out narou-mod.apk --ks-pass $KEY_PASS tmp/mod-unsigned.apk
apksigner sign --ks .keystore -v --v2-signing-enabled true --ks-key-alias narou-mod --out narou-mod.apk --ks-pass "$KEY_PASS" tmp/mod-unsigned.apk
Loading

0 comments on commit 882d526

Please sign in to comment.