-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CoroCoro connector #7472
base: master
Are you sure you want to change the base?
Add CoroCoro connector #7472
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work but
-
Dont assume the script you want is the nth script in all the page scripts. Perform checks on the script content instead.
-
I dont like those eval at all. If you want to use eval perhaps you should use them in browser context i.e injecting a script using
Engine.Request.fetchUI
. Perhaps is event easier this way, if you are able to parse next_f array idk.
async _getMangas() { | ||
/** @type {HTMLScriptElement[]} */ | ||
const scripts = await this.fetchDOM(this.url + '/rensai', 'script'); | ||
for (const scriptElem of scripts.reverse()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to loop by yourself if you can identify the script by content
const scripts = [...document.querySelectorAll('script')];
const script = scripts.find(script=> script.innerText.indexOf('totalChapterLikes') > 0)?.innerText;
const json = JSON.parse(script.substring(22, script.length - 2));
const data = JSON.parse(json.substring(json.indexOf(':') + 1))[3]['children'][3]['weekdays'];
/** @type {string} */ | ||
const json = JSON.parse(script.substring(22, script.length - 2)); | ||
/** @type {Object<string, {id: number, title: string}[]>} */ | ||
const data = JSON.parse(json.substring(json.indexOf(':') + 1))[3]['children'][0][3]['children'][1][3]['section']['chapters']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hum... Thats a lot of fixed indexes :/
Since the position of "chapters" in the json object may vary, why not trying to locate it dynamically?
function locate(obj, keyname)
{
if (!obj) return null;
if (obj[keyname]) {
return (obj[keyname]);
}
let result = null;
for (i in obj) {
if (typeof obj[i] === 'object')
result = result ?? locate(obj[i], keyname);
}
return result;
}
const scripts = [...document.querySelectorAll('script')];
const script = scripts.find(script=> script.innerText.indexOf('omittedMiddleChapters') > 0)?.innerText;
const json = JSON.parse(script.substring(22, script.length - 2));
const data = JSON.parse(json.substring(json.indexOf(':') + 1));
const chapters = locate(data, 'chapters');
Or if you fear that "chapters" wont be unique you may want to "locate" 'earlyChapters', 'omittedMiddleChapters' and 'latestChapters'. I doubt there will be duplicates.
And maybe, do that for the other JSON parsing, idk?
const script = scriptElem.innerText; | ||
try { | ||
/** @type {string} */ | ||
const json = JSON.parse(script.substring(22, script.length - 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposition :
function locate(obj, keyname)
{
if (!obj) return null;
if (obj[keyname]) {
return (obj[keyname]);
}
let result = null;
for (i in obj) {
if (typeof obj[i] === 'object')
result = result ?? locate(obj[i], keyname);
}
return result;
}
const scripts = [...document.querySelectorAll('script')];
const script = scripts.find(script=> script.innerText.indexOf('viewerSection') > 0)?.innerText;
const json = JSON.parse(script.substring(22, script.length - 2));
const data = JSON.parse(json.substring(json.indexOf(':') + 1));
const pages = locate(data, 'viewerSection')?.pages;
const script = scriptElem.innerText; | ||
try { | ||
/** @type {string} */ | ||
const json = JSON.parse(script.substring(22, script.length - 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, since JSON parsing first steps are the same perhaps we should make a function?
function findAndParseJSON(scripts, textToFind) {
const script = scripts.find(script=> script.innerText.indexOf(textToFind) > 0)?.innerText;
const json = JSON.parse(script.substring(22, script.length - 2));
return JSON.parse(json.substring(json.indexOf(':') + 1))
}
const scripts = [...document.querySelectorAll('script')];
const data = findAndParseJSON( scripts, 'weekdays');
The "allow edits by maintainers" checkbox is checked, since you're already writing full snippets of fixed code in your comments you might as well commit them. |
I have no time to spare and no intention to add such complex website to Hakuneko anymore. Its better for the team and for everyone to spend time on Haruneko where this website was added and working until its last update. |
Suggestion to close PR after Thursday, 2 January 2025 (12 weeks) if not approved by a reviewer. |
No description provided.