Feat: resolveUrl, add neobook (#803)
* neobook * add qs * fix * / * fix * expandURL -> resolveUrl * fix Agitoon * Update ranobelib.ts --------- Co-authored-by: nyagami <hoangquan05112002@gmail.com>
This commit is contained in:
@@ -87,3 +87,14 @@ export const parseChapter = async (
|
||||
|
||||
export const fetchImage = async (pluginRequirePath: string, url: string) =>
|
||||
(await getPlugin(pluginRequirePath))?.fetchImage(url);
|
||||
|
||||
export const resolveUrl = async (
|
||||
pluginRequirePath: string,
|
||||
path: string,
|
||||
isNovel?: boolean,
|
||||
) => {
|
||||
const plugin = await getPlugin(pluginRequirePath);
|
||||
if (!plugin) return path;
|
||||
if (plugin.resolveUrl) return plugin.resolveUrl(path, isNovel);
|
||||
return plugin.site + path;
|
||||
};
|
||||
@@ -357,6 +357,27 @@
|
||||
<img src="" style="min-height: 300px; max-width: 450px;" alt="">
|
||||
</accordion-content>
|
||||
</accordion-box>
|
||||
<accordion-box id="resolveUrl" collapsed>
|
||||
<accordion-header>
|
||||
resolveUrl
|
||||
</accordion-header>
|
||||
<accordion-content>
|
||||
<div class="input-group">
|
||||
<select class="form-control">
|
||||
<option>novel</option>
|
||||
<option>chapter</option>
|
||||
</select>
|
||||
<input type="path" class="form-control" placeholder="path">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary resolveUrl-btn" type="button">fetch</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="spinner-border" role="status">
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
<input readonly>
|
||||
</accordion-content>
|
||||
</accordion-box>
|
||||
</main-accordion>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ class AccordionHeader extends HTMLElement {
|
||||
return this.parentElement;
|
||||
}
|
||||
connectedCallback() {
|
||||
console.log("I AM ON THE SCREEN, DO YOUR FUCKING JOB");
|
||||
const childNodes = Array.from(this.childNodes);
|
||||
this.innerHTML = "";
|
||||
this.btn.append(...childNodes);
|
||||
|
||||
@@ -58,6 +58,8 @@ const parseChapter = $("#parseChapter");
|
||||
|
||||
/** @type {JQuery<AccordionBox>} */
|
||||
const fetchImage = $("#fetchImage");
|
||||
/** @type {JQuery<AccordionBox>} */
|
||||
const resolveUrl = $("#resolveUrl");
|
||||
|
||||
/** @type {JQuery<HTMLSelectElement>}*/
|
||||
const plugin_language_selection = $("#language");
|
||||
@@ -1149,6 +1151,37 @@ class PluginWrapper {
|
||||
spinner.hide();
|
||||
}
|
||||
}
|
||||
|
||||
async resolveUrl() {
|
||||
const type = $("#resolveUrl select").val();
|
||||
const path = $("#resolveUrl input").val();
|
||||
const spinner = $("#resolveUrl .spinner-border");
|
||||
spinner.show();
|
||||
try {
|
||||
const fullURL = await (
|
||||
await fetchFromAPI("/resolveUrl/", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
pluginRequirePath: this.requirePath,
|
||||
isNovel: type === "novel",
|
||||
path,
|
||||
}),
|
||||
})
|
||||
).text();
|
||||
$("#resolveUrl input[readonly]").val(fullURL)
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
if (e)
|
||||
$("#resolveUrl").text(
|
||||
`${typeof e === "object" && "message" in e ? e.message : e}`
|
||||
);
|
||||
} finally {
|
||||
spinner.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
const currentWrapper = () => state.current_plugin || emptyPluginWrapper;
|
||||
const emptyPluginWrapper = new PluginWrapper("");
|
||||
@@ -1566,6 +1599,7 @@ $(".parsePage-btn").on("click", () =>
|
||||
|
||||
$(".parseChapter-btn").on("click", () => state.current_plugin?.getChapter());
|
||||
$(".fetchImage-btn").on("click", () => state.current_plugin?.fetchImage());
|
||||
$(".resolveUrl-btn").on("click", () => state.current_plugin?.resolveUrl());
|
||||
|
||||
// #endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user