-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
android/app/src/main/java/com/novelscraper/NovelScraperPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.novelscraper; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class NovelScraperPackage implements ReactPackage { | ||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules( | ||
ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
|
||
modules.add(new ScraperModule(reactContext)); | ||
|
||
return modules; | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
android/app/src/main/java/com/novelscraper/ScraperModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.novelscraper; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.Callback; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReadableArray; | ||
import com.facebook.react.bridge.WritableArray; | ||
import com.facebook.react.modules.core.DeviceEventManagerModule; | ||
import com.facebook.react.bridge.WritableMap; | ||
import com.facebook.react.bridge.Arguments; | ||
|
||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
public class ScraperModule extends ReactContextBaseJavaModule { | ||
private int listenerCount = 0; | ||
|
||
ScraperModule(ReactApplicationContext context) { | ||
super(context); | ||
} | ||
|
||
@ReactMethod | ||
public void getNovelPaginationPages(String pagePrefixURL, double startPage, double totalPages, Callback callback) { | ||
try { | ||
WritableArray novelPaginationPages = Arguments.createArray(); | ||
for (int i = (int)startPage; i <= (int)totalPages; i++) { | ||
Document doc = Jsoup | ||
.connect(pagePrefixURL + i) | ||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36") | ||
.header("Accept-Language", "*") | ||
.get(); | ||
novelPaginationPages.pushString(doc.html()); | ||
} | ||
callback.invoke(null, novelPaginationPages); | ||
} catch (IOException e) { | ||
Log.d("ERROR", e.toString()); | ||
callback.invoke(e, null); | ||
} | ||
} | ||
|
||
@ReactMethod | ||
public void getNovelChapterPages(ReadableArray chapterLinks, Callback callback) { | ||
try { | ||
WritableArray novelChapterPages = Arguments.createArray(); | ||
for (int i = 0; i < chapterLinks.size(); i++) { | ||
Log.d("INFO", "Downloading: " + chapterLinks.getString(i)); | ||
Document doc = Jsoup | ||
.connect(chapterLinks.getString(i)) | ||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36") | ||
.header("Accept-Language", "*") | ||
.get(); | ||
novelChapterPages.pushString(doc.html()); | ||
} | ||
callback.invoke(null, novelChapterPages); | ||
} catch (IOException e) { | ||
Log.d("ERROR", e.toString()); | ||
callback.invoke(e, null); | ||
} | ||
} | ||
|
||
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) { | ||
reactContext | ||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) | ||
.emit(eventName, params); | ||
} | ||
|
||
@ReactMethod | ||
public void addListener(String eventName) { | ||
if (listenerCount == 0) { | ||
// Set up any upstream listeners or background tasks as necessary | ||
} | ||
|
||
listenerCount += 1; | ||
} | ||
|
||
@ReactMethod | ||
public void removeListeners(Integer count) { | ||
listenerCount -= count; | ||
if (listenerCount == 0) { | ||
// Remove upstream listeners, stop unnecessary background tasks | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "ScraperModule"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
module.exports = { | ||
presets: ["module:@react-native/babel-preset"], | ||
plugins: ["transform-remove-console"] | ||
}; | ||
module.exports = function (api) { | ||
api.cache(false); | ||
|
||
const presets = ["module:@react-native/babel-preset"]; | ||
const plugins = []; | ||
|
||
console.log("NODE_ENV", process.env["NODE_ENV"]) | ||
if (!!process.env["NODE_ENV"] && process.env["NODE_ENV"] !== "development") { | ||
console.log("NOT IN DEV") | ||
plugins.push("transform-remove-console"); | ||
} | ||
|
||
return { | ||
presets, | ||
plugins | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters