You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用JavaScript将Facebook评论默认排序从"Most Relevant"改为"All Comments"

如何用JavaScript将Facebook评论默认排序从"Most Relevant"改为"All Comments"

嘿,我完全懂你的痛点——每次点开Facebook帖子评论,默认都是“Most Relevant”,还要手动切换到“All Comments”,真的挺麻烦的!既然你之前有过网页编程基础,用JavaScript来实现自动切换完全可行,我给你捋捋具体怎么做,甚至可以做成一键工具:

第一步:先在浏览器控制台快速测试

打开任意Facebook帖子,按F12(或者右键选“检查”)打开开发者工具的控制台,粘贴下面这段代码回车,看看能不能自动切换到所有评论:

// 定位评论排序的下拉按钮
const sortButton = document.querySelector('[aria-label="Sort comments"]');
if (sortButton) {
  // 点击展开排序菜单
  sortButton.click();
  // 给菜单加载留一点时间,再找"All Comments"选项并点击
  setTimeout(() => {
    const allCommentsOption = Array.from(document.querySelectorAll('[role="menuitem"]'))
      .find(item => item.textContent.includes('All Comments'));
    if (allCommentsOption) {
      allCommentsOption.click();
    }
  }, 500);
}

这段代码的逻辑很简单:先找到排序按钮,点击展开菜单,再定位到“All Comments”选项并点击。

第二步:做成自动触发的书签工具(更实用)

因为Facebook页面是动态加载的,有时候帖子评论不会立刻显示,上面的代码可能只运行一次不够。我们可以把代码改成自动监听页面变化,做成浏览器书签,每次打开Facebook帖子点一下书签就自动切换:

  1. 右键浏览器书签栏,选择“添加书签”
  2. 名称填“Facebook 显示所有评论”,然后在“URL”框里粘贴下面这段代码:
javascript:(function(){
  function switchToAllComments() {
    const sortButton = document.querySelector('[aria-label="Sort comments"]');
    // 加个标记避免重复点击
    if (sortButton && !sortButton.classList.contains('auto-switched')) {
      sortButton.classList.add('auto-switched');
      sortButton.click();
      setTimeout(() => {
        const allCommentsOption = Array.from(document.querySelectorAll('[role="menuitem"]'))
          .find(item => item.textContent.includes('All Comments'));
        if (allCommentsOption) {
          allCommentsOption.click();
        }
      }, 500);
    }
  }

  // 监听页面动态变化,评论区加载出来就自动切换
  const observer = new MutationObserver(() => switchToAllComments());
  observer.observe(document.body, { childList: true, subtree: true });
  
  // 先运行一次,处理已经加载好的评论区
  switchToAllComments();
})();

以后只要打开Facebook帖子,点击这个书签,就能自动帮你切换到“All Comments”了!

一些需要注意的小问题

  • Facebook偶尔会调整页面的元素属性(比如aria-label的文字),如果哪天代码失效了,你可以重新用开发者工具检查排序按钮的选择器,替换掉代码里的[aria-label="Sort comments"]就行。
  • 有些浏览器的广告拦截或者脚本拦截插件可能会阻止这段代码运行,记得允许Facebook相关的脚本执行。
  • 这只是客户端的自动操作,不会修改Facebook的官方设置,只是帮你省了手动点击的步骤~

备注:内容来源于stack exchange,提问作者Randy H Eldredge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 07:05:30