45 lines
831 B
TypeScript
45 lines
831 B
TypeScript
const url = 'https://nhentai.net/';
|
|
|
|
const paths = {
|
|
books: 'g/',
|
|
login: 'login/',
|
|
favorites: 'favorites/',
|
|
};
|
|
|
|
// @ts-ignore
|
|
let loginPassword: string;
|
|
// @ts-ignore
|
|
let loginName: string;
|
|
|
|
function fetchNHentai(path: string): Promise<Document> {
|
|
return fetch(`${url}${path}`, {
|
|
credentials: 'include',
|
|
})
|
|
.then(res => {
|
|
console.log(res);
|
|
return res.text();
|
|
})
|
|
.then(text => {
|
|
const parser = new DOMParser();
|
|
return parser.parseFromString(text, 'text/html');
|
|
});
|
|
}
|
|
|
|
function fetchLogin(): void {
|
|
fetchNHentai(paths.login)
|
|
.then(() => true)
|
|
.catch(e => {
|
|
console.error(e);
|
|
});
|
|
}
|
|
|
|
function setLoginCredentials(name: string, password: string): void {
|
|
loginName = name;
|
|
loginPassword = password;
|
|
}
|
|
|
|
export default {
|
|
setLoginCredentials,
|
|
fetchLogin,
|
|
};
|