nhentai-tools
Version:
A toolset to interact with the doujin site nhentai.net
43 lines (42 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeMany = exports.remove = exports.addMany = exports.add = exports.change = exports.get = void 0;
const user_1 = require("./user");
const utils_1 = require("./utils");
const client_1 = require("./client");
/** Get an array of all tags blacklisted for the current user. */
const get = () => {
const user = (0, user_1.getUser)();
if (!user_1.isLoggedIn || !user)
throw user_1.notLoggedInError;
return client_1.client.get(`/users/${user.id}/${user.slug}/blacklist`)
.then(({ data }) => {
const utf8_list = data.match(/window\._blacklist_tags = JSON\.parse\("\[.*\]"\)/)[0].split('"')[1];
return JSON.parse((0, utils_1.unescapeUTF8)(utf8_list));
});
};
exports.get = get;
/** Add and/or remove tags from the current user's blacklist. */
const change = (added, removed) => {
const user = (0, user_1.getUser)();
if (!user_1.isLoggedIn || !user)
throw user_1.notLoggedInError;
const data = {
added: added.map(({ id, name, type }) => ({ id, name, type })),
removed: removed.map(({ id, name, type }) => ({ id, name, type })),
};
return client_1.client.post(`/users/${user.id}/${user.slug}/blacklist`, data).then(({ data }) => data);
};
exports.change = change;
/** Add a tag to the current user's blacklist. */
const add = (tag) => (0, exports.change)([tag], []);
exports.add = add;
/** Add an array of tags to the current user's blacklist. */
const addMany = (tags) => (0, exports.change)(tags, []);
exports.addMany = addMany;
/** Remove a tag from the current user's blacklist. */
const remove = (tag) => (0, exports.change)([], [tag]);
exports.remove = remove;
/** Remove an array of tags from the current user's blacklist. */
const removeMany = (tags) => (0, exports.change)([], tags);
exports.removeMany = removeMany;