Greasy Fork is available in English.
一键下载对方 Instagram 帖子中的相片、视频甚至是他们的快拍、Reels及头像图片!
這裡代碼會跑掉,你有DISCORD或是能直接在github建立issue嗎?
這裡代碼會跑掉,你有DISCORD或是能直接在github建立issue嗎?
好的,我已经在github上建立issue了
已更新。
😳我之前还发现了一个bug,如果不打开“通过media API强制获取资源”,自动命名时就无法正确获得stories图片的%SHORTCODE%。试了一下最新版本里还是会出现。
大佬,关于之前的那个问题,在“新选项卡中打开”和打开“直接下载帖子中的可见资源”的下载按钮,第二张图片之后都会下载到第一张图片的问题,我找到解决方法了。
原有的判断第几张图的逻辑应该是根据页面下方的点来判断,它在首页和帖子详情页都没问题,但在主页和探索页都会下载成第一张图。
现在我把判断方式整个重构了。
只要把整个function getVisibleNodeIndex函数替换成下面的版本就行了。
```
function getVisibleNodeIndex($main) {
// --- 优化:提前处理单资源帖子 ---
// 如果帖子内找不到轮播图结构,或轮播图只有一项,那么索引永远是0。
const resource_count = $main.find('._acay ._acaz').length;
if (resource_count <= 1) {
return 0;
}
var index = 0;
// --- 方法 3:融合“返回按钮”与“通用几何定位”的最终统一算法 ---
// 仅当方法1和方法-2都返回 0 时才尝试
if (index === 0) {
try {
// 1. 优先使用最高效的规则:检查“返回”按钮是否存在。
const hasBackButton = $main.find('button._afxv._al46._al47').length > 0;
// 2. 如果“返回”按钮不存在,则确定是第一张图,立即返回结果。
if (!hasBackButton) {
return 0;
}
// 3. 如果代码执行到这里,说明不是第一张图,启用最终的几何算法。
// a. 定位“视窗”元素:它是 ul._acay 的祖父级元素
const $viewport = $main.find('ul._acay').parent().parent();
if ($viewport.length > 0) {
const viewportRect = $viewport.get(0).getBoundingClientRect();
// b. 获取 itemWidth:直接使用视窗的宽度,此方法通用性最强
const itemWidth = viewportRect.width;
// 必须成功获取到宽度才能继续,防止除以0的错误
if (itemWidth > 0) {
// STAGE 1: 视觉定位,找到当前显示的
const viewportRight = viewportRect.right;
let closestSlideElement = null;
let minDistance = Infinity;
$main.find('li._acaz').each(function() {
if (this.getBoundingClientRect().width === 0) return;
const slideRect = this.getBoundingClientRect();
const distance = Math.abs(slideRect.right - viewportRight);
if (distance < minDistance) {
minDistance = distance;
closestSlideElement = this;
}
});
// STAGE 2: 索引计算,利用找到的
if (closestSlideElement) {
const style = $(closestSlideElement).attr('style');
if (style && style.includes('translateX')) {
const offsetMatch = style.match(/translateX\(([^p]+)px\)/);
if (offsetMatch && offsetMatch[1]) {
const totalOffset = parseFloat(offsetMatch[1]);
// c. 执行最终的计算公式
index = Math.round(totalOffset / itemWidth);
}
}
}
}
}
} catch (e) {
console.error("IG Helper (Method 3 Error):", e);
}
}
return index;
}
```