Skip to content

Commit

Permalink
#
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteSevs committed May 29, 2024
1 parent 984ff35 commit 34d885a
Show file tree
Hide file tree
Showing 11 changed files with 65,958 additions and 39 deletions.
4 changes: 2 additions & 2 deletions packages/小红书优化/SCRIPT_VERSION.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"time": 1716950730274,
"version": "2024.5.29"
"time": 1716960126338,
"version": "2024.5.29.13"
}
40 changes: 20 additions & 20 deletions packages/小红书优化/dist/小红书优化.min.user.js

Large diffs are not rendered by default.

54 changes: 45 additions & 9 deletions packages/小红书优化/dist/小红书优化.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name 小红书优化
// @namespace https://github.com/WhiteSevs/TamperMonkeyScript
// @version 2024.5.29
// @version 2024.5.29.13
// @author WhiteSevs
// @description 屏蔽登录弹窗、屏蔽广告、优化评论浏览、优化图片浏览、允许复制、禁止唤醒App、禁止唤醒弹窗、修复正确跳转等
// @license GPL-3.0-only
Expand Down Expand Up @@ -564,7 +564,7 @@
if (typeof key !== "string") {
throw new TypeError("key 必须是字符串");
}
if (!PopsPanel.hasValue(key)) {
if (!this.$data.data.has(key)) {
log.warn(`${key} 键不存在`);
return;
}
Expand All @@ -582,7 +582,7 @@
if (typeof key !== "string") {
throw new TypeError("key 必须是字符串");
}
if (!PopsPanel.hasValue(key)) {
if (!this.$data.data.has(key)) {
log.warn(`${key} 键不存在`);
return;
}
Expand Down Expand Up @@ -822,19 +822,28 @@
return globalThis.location.pathname.startsWith("/search_result/");
}
};
new utils.GM_Cookie();
const XHS_BASE_URL = "https://edith.xiaohongshu.com";
const XHSApi = {
/**
* 获取页信息
*/
async getPageInfo(note_id, cursor = "", top_comment_id = "", image_formats = "jpg,webp") {
const Api = `/api/sns/web/v2/comment/page?note_id=${note_id}&cursor=${cursor}&top_comment_id=${top_comment_id}&image_formats=${image_formats}`;
let getResp = await httpx.get(`https://edith.xiaohongshu.com${Api}`, {
const Api = `/api/sns/web/v2/comment/page`;
const SearchParamsData = {
note_id,
cursor,
top_comment_id,
image_formats
};
const SearchParams = Api + "?" + utils.toSearchParamsStr(SearchParamsData);
let getResp = await httpx.get(`${XHS_BASE_URL}${SearchParams}`, {
headers: {
Accept: "application/json, text/plain, */*",
"User-Agent": utils.getRandomPCUA(),
Origin: "https://www.xiaohongshu.com",
Referer: "https://www.xiaohongshu.com/"
// "X-S": signInfo.xs,
// "X-T": signInfo.xt,
}
});
if (!getResp.status) {
Expand All @@ -854,17 +863,44 @@
* 获取楼中楼页信息
*/
async getLzlPageInfo(note_id = "", root_comment_id = "", num = 10, cursor = "", image_formats = "jpg,webp,avif", top_comment_id = "") {
const Api = `/api/sns/web/v2/comment/sub/page?note_id=${note_id}&root_comment_id=${root_comment_id}&num=${num}&cursor=${cursor}&image_formats=${image_formats}&top_comment_id=${top_comment_id}`;
let getResp = await httpx.get(`https://edith.xiaohongshu.com${Api}`, {
const Api = `/api/sns/web/v2/comment/sub/page`;
let ApiData = {
note_id,
root_comment_id,
num,
cursor,
image_formats,
top_comment_id
};
Api + "?" + utils.toSearchParamsStr(ApiData);
let url = `${XHS_BASE_URL}${Api}?${utils.toSearchParamsStr(ApiData)}`;
let getResp = await httpx.get(url, {
headers: {
Accept: "application/json, text/plain, */*",
"User-Agent": utils.getRandomPCUA(),
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
Host: "edith.xiaohongshu.com",
Origin: "https://www.xiaohongshu.com",
Referer: "https://www.xiaohongshu.com/"
// "X-S": signInfo.xs,
// "X-T": signInfo.xt,
// "X-S-Common": signInfo.xsCommon,
// "X-B3-Traceid": signInfo.traceId,
},
onerror() {
}
});
if (!getResp.status) {
if (getResp.data.status === 406 && utils.isNotNull(getResp.data.responseText)) {
let errorData = utils.toJSON(getResp.data.responseText);
if (errorData["code"] == -1) {
Qmsg.error("获取楼中楼信息失败,验证x-s、x-t、x-s-common失败");
} else {
Qmsg.error("获取楼中楼信息失败");
}
} else {
Qmsg.error("请求异常");
}
log.error(["获取楼中楼信息失败", getResp]);
return;
}
let data = utils.toJSON(getResp.data.responseText);
Expand Down
55 changes: 49 additions & 6 deletions packages/小红书优化/src/api/XHSApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { httpx, log, utils } from "@/env";
import { XHS_Sign } from "@/sign/xhs_sign";
import Qmsg from "qmsg";

interface PageInfo {
Expand All @@ -10,7 +11,7 @@ interface PageInfo {
}
interface LzlPageInfo extends PageInfo {}

let cookieStore = new utils.GM_Cookie();
const XHS_BASE_URL = "https://edith.xiaohongshu.com";
const XHSApi = {
/**
* 获取页信息
Expand All @@ -21,13 +22,23 @@ const XHSApi = {
top_comment_id = "",
image_formats = "jpg,webp"
) {
const Api = `/api/sns/web/v2/comment/page?note_id=${note_id}&cursor=${cursor}&top_comment_id=${top_comment_id}&image_formats=${image_formats}`;
let getResp = await httpx.get(`https://edith.xiaohongshu.com${Api}`, {
const Api = `/api/sns/web/v2/comment/page`;
const SearchParamsData = {
note_id: note_id,
cursor: cursor,
top_comment_id: top_comment_id,
image_formats: image_formats,
};
const SearchParams = Api + "?" + utils.toSearchParamsStr(SearchParamsData);
// let signInfo = XHS_Sign(Api);
let getResp = await httpx.get(`${XHS_BASE_URL}${SearchParams}`, {
headers: {
Accept: "application/json, text/plain, */*",
"User-Agent": utils.getRandomPCUA(),
Origin: "https://www.xiaohongshu.com",
Referer: "https://www.xiaohongshu.com/",
// "X-S": signInfo.xs,
// "X-T": signInfo.xt,
},
});
if (!getResp.status) {
Expand Down Expand Up @@ -55,17 +66,49 @@ const XHSApi = {
image_formats = "jpg,webp,avif",
top_comment_id = ""
) {
const Api = `/api/sns/web/v2/comment/sub/page?note_id=${note_id}&root_comment_id=${root_comment_id}&num=${num}&cursor=${cursor}&image_formats=${image_formats}&top_comment_id=${top_comment_id}`;
let getResp = await httpx.get(`https://edith.xiaohongshu.com${Api}`, {
const Api = `/api/sns/web/v2/comment/sub/page`;
let ApiData = {
note_id: note_id,
root_comment_id: root_comment_id,
num: num,
cursor: cursor,
image_formats: image_formats,
top_comment_id: top_comment_id,
};
let searchParams = Api + "?" + utils.toSearchParamsStr(ApiData);
// let signInfo = XHS_Sign(searchParams);
// log.success(["签名信息:", signInfo]);
let url = `${XHS_BASE_URL}${Api}?${utils.toSearchParamsStr(ApiData)}`;
let getResp = await httpx.get(url, {
headers: {
Accept: "application/json, text/plain, */*",
"User-Agent": utils.getRandomPCUA(),
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
Host: "edith.xiaohongshu.com",
Origin: "https://www.xiaohongshu.com",
Referer: "https://www.xiaohongshu.com/",
// "X-S": signInfo.xs,
// "X-T": signInfo.xt,
// "X-S-Common": signInfo.xsCommon,
// "X-B3-Traceid": signInfo.traceId,
},
onerror() {},
});
if (!getResp.status) {
if (
getResp.data.status === 406 &&
utils.isNotNull(getResp.data.responseText)
) {
let errorData = utils.toJSON(getResp.data.responseText);
if (errorData["code"] == -1) {
Qmsg.error("获取楼中楼信息失败,验证x-s、x-t、x-s-common失败");
} else {
Qmsg.error("获取楼中楼信息失败");
}
} else {
Qmsg.error("请求异常");
}
log.error(["获取楼中楼信息失败", getResp]);
return;
}
let data = utils.toJSON(getResp.data.responseText);
Expand Down
4 changes: 2 additions & 2 deletions packages/小红书优化/src/setting/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const PopsPanel = {
if (typeof key !== "string") {
throw new TypeError("key 必须是字符串");
}
if (!PopsPanel.hasValue(key)) {
if (!this.$data.data.has(key)) {
log.warn(`${key} 键不存在`);
return;
}
Expand All @@ -261,7 +261,7 @@ const PopsPanel = {
if (typeof key !== "string") {
throw new TypeError("key 必须是字符串");
}
if (!PopsPanel.hasValue(key)) {
if (!this.$data.data.has(key)) {
log.warn(`${key} 键不存在`);
return;
}
Expand Down
Loading

0 comments on commit 34d885a

Please sign in to comment.