发布于 更新于
AI总结: 本文介绍了自动化配置的Webhook功能和Feed分享页的自动订阅脚本。Webhook通过POST请求将feed条目信息以JSON格式发送,建议自定义接口以便更好地处理这些信息。示例参数格式展示了如何构建这些数据。对于Feed分享页的自动订阅,脚本从URL中提取feed ID,查询订阅状态,并根据结果进行订阅,临时分类设定为“待定”。当前订阅数量限制为500条,超限后需停用脚本。
优化建议包括:
1. 增加对Webhook请求的错误处理机制,以便在请求失败时提供更明确的反馈。
2. 考虑引入异步处理机制,以提高脚本在处理多个订阅时的效率。
3. 提供用户界面提示,告知用户订阅成功或失败的状态,以增强用户体验。
4. 设定订阅数量的动态调整机制,允许用户根据需求修改上限。
POST 请求, 会将feed条目信息作为Json参数进行请求, 所以如果要较好处理的话, 可能需要自定义一个webhook接口进行处理
参数格式示例:
{'entry': {'id': 'xxx', 'publishedAt': '2025-02-06T06:31:29.669Z', 'insertedAt': '2025-02-06T06:42:55.467Z', 'feedId': '85248513348230144', 'title': "xxx", 'description': 'xxx', 'content': 'xxx', 'author': None, 'url': 'xxx', 'guid': 'xxx', 'media': [{'url': 'xxx', 'type': 'photo', 'width': 492, 'height': 656}]}, 'feed': {'title': 'xxx', 'description': 'xxx', 'siteUrl': 'https://xxx', 'image': 'https://xxx', 'checkedAt': '2025-02-06T06:42:55.466Z', 'ttl': 30, 'url': 'https://xxxx', 'lastModifiedHeader': 'Thu, 06 Feb 2025 06:42:54 GMT', 'etagHeader': '"ee35-WBbJJibnAIpo+80xxx/iPxbcxxx"', 'errorMessage': None, 'errorAt': None}, 'view': 5}
因为目前主要在Web端使用, 在分享页订阅时 会提示跳转下载客户端. 所以实现该脚本:
- 从链接获取feed id
- 查询feed信息接口 判断是否订阅
- 调用feed订阅接口 进行订阅, 设定临时分类
有需要再进行优化, 目前订阅数量上线为500条, 超限后可停用脚本
// ==UserScript==
// @name Follow分享页 自动订阅
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 从当前页面 URL 中提取最后一段数字 ID
// @author anaer
// @match https://app.follow.is/share/feeds/*
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// ==/UserScript==
(function () {
"use strict";
const xget = (url, type = "json") =>
new Promise((success, fail) => {
GM_xmlhttpRequest({
method: "GET",
timeout: 3000,
credentials: "include", // 携带浏览器 Cookies
url: url,
responseType: type,
onload: success,
onerror: fail,
ontimeout: fail,
});
});
const xpost = (url, data = {}) =>
new Promise((success, fail) => {
GM_xmlhttpRequest({
method: "POST",
timeout: 3000,
credentials: "include", // 携带浏览器 Cookies
headers: {
"Content-Type": "application/json", // 设置请求头
},
url: url,
data: data,
responseType: "json",
onload: success,
onerror: fail,
ontimeout: fail,
});
});
// 获取当前页面的 URL
const currentUrl = window.location.href;
// 使用正则表达式提取最后一段数字 ID
const match = currentUrl.match(/\/(\d+)\/?$/);
var id;
if (match && match[1]) {
id = match[1];
console.log("提取的数字 ID:", id);
} else {
console.log("未找到数字 ID");
}
let url = "https://api.follow.is/feeds?id=" + id;
xget(url)
.then((r) => {
const ra = r.response;
console.log(url, ra);
if (ra.data.subscription) {
console.log("已订阅");
} else {
console.log("未订阅");
let feed =
unsafeWindow.__HYDRATE__["feeds.$get,query:id=" + id]["feed"];
var data = JSON.stringify({
feedId: feed.id,
url: feed.url,
view: 0,
category: "待定",
});
xpost("https://api.follow.is/subscriptions", data)
.then((r) => {
const ra = r.response;
console.log("订阅成功", data, ra);
})
.catch((e) => {
console.log("订阅失败");
});
}
})
.catch((e) => {
console.log(url, "获取feed信息异常");
});
})();