Facebook Auto "Most Recent" Stories

Change Facebook and groups feed to "Most Recent"

  1. // ==UserScript==
  2. // @name Facebook Auto "Most Recent" Stories
  3. // @version 0.1559010793
  4. // @author Hélder Ferreira
  5. // @namespace https://gf.qytechs.cn/users/89591
  6. // @homepageURL https://gf.qytechs.cn/en/scripts/382099-facebook-auto-most-recent-stories
  7. // @description Change Facebook and groups feed to "Most Recent"
  8. // @compatible chrome
  9. // @compatible firefox
  10. // @compatible opera
  11. // @compatible safari
  12. // @compatible msedge
  13. // @license MIT
  14. // @icon https://en.facebookbrand.com/wp-content/uploads/2019/04/f_logo_RGB-Hex-Blue_512.png
  15. // @match https://*.facebook.com/*
  16. // @grant none
  17. // ==/UserScript==
  18. (function(){ var arr = [
  19. "",
  20. "// ### Global vars ###",
  21. "var cur = new URL(window.location.href), spurl = cur['href'].split('/'),",
  22. "",
  23. "// ### Feed vars ###",
  24. "fd = cur['origin'] + '?sk=h_chr', elm = document.querySelectorAll(\"[data-click='bluebar_logo'] > a, ._3qcu > a, #navItem_4748854339 > a\"), grp = document.querySelectorAll(\"[data-type='type_group'] > a\"), idx = ['?sk=h_nor', '?ref=logo', '?sk=nf', '?ref=tn_tnmn'],",
  25. "",
  26. "// ### Groups vars ###",
  27. "grid = document.querySelectorAll(\"[property='al:android:url']\"), gdisc = document.querySelectorAll('._2yau'), gpop = ['CHRONOLOGICAL', 'RECENT_ACTIVITY'], gref = ['?ref=group_header', '?ref=bookmarks', '?ref=direct', '?fref=nf', '?ref=nf_target&fref=nf'];",
  28. "",
  29. "",
  30. "// ### For Feed ###",
  31. "if(cur['href'] === cur['origin'] + '/'){",
  32. "window.location.replace(fd);",
  33. "}",
  34. "idx.forEach((a) => {",
  35. "if(cur['search'].includes(a)){",
  36. "window.location.replace(fd);",
  37. "}",
  38. "});",
  39. "elm.forEach(elm => elm.addEventListener('click', () => {",
  40. "window.location.replace(fd);",
  41. "}), false);",
  42. "",
  43. "",
  44. "// ### For Groups ###",
  45. "grp.forEach(shc => shc.addEventListener('click', () => {",
  46. "shc = shc.getAttribute('href');",
  47. "window.location.replace(groupSec(shc, gpop[0]));",
  48. "}, false));",
  49. "",
  50. "if(cur['href'].includes('groups') && !cur['href'].includes('permalink') && !cur['href'].includes('comment_id')){",
  51. "if(spurl[5] === '' || spurl[5] === null || spurl[5] === gref[0] || spurl[5] === gref[1] || spurl[5] === gref[2] || spurl[5] === gref[3] || spurl[5] === gref[4] || spurl[5] !== '?sorting_setting=' + gpop[0]){",
  52. "window.location.replace(sortGrp(grid, 'content', gpop[0], cur['origin'] + '/'));",
  53. "}",
  54. "}",
  55. "",
  56. "// # Discussion link event #",
  57. "if(gdisc[1] !== undefined){",
  58. "var abpg = document.querySelectorAll('._2yaa');",
  59. "abpg = abpg[1].getAttribute('data-key');",
  60. "if(!abpg.includes('tab_about')){",
  61. "gdisc[1].addEventListener('click', () => { window.location.replace(sortGrp(grid, 'content', gpop[0], cur['origin'] + '/')) }, false);",
  62. "}",
  63. "}",
  64. "",
  65. "// # 'post time' & 'comment time' link event #",
  66. "var postime = document.querySelectorAll('._5pcq');",
  67. "postime.forEach(ptm => ptm.addEventListener('click', () => {",
  68. "ptm = ptm.getAttribute('href');",
  69. "window.location.replace(ptm);",
  70. "}, false));",
  71. "",
  72. "var comtime = document.querySelectorAll('._6qw7');",
  73. "comtime.forEach(cmt => cmt.addEventListener('click', () => {",
  74. "cmt = cmt.getAttribute('href');",
  75. "window.location.replace(cmt);",
  76. "}, false));",
  77. "",
  78. "",
  79. "// ### Required functions ###",
  80. "// # Arguments: a = element where group ID is located, b = atribute where group ID is, c = type of group disposition (CHRONOLOGICAL or RECENT_ACTIVITY), d = Facebook domain, rs = a resource variable #",
  81. "function sortGrp(a, b, c, d, rs){",
  82. "a = a[0].getAttribute(b);",
  83. "rs = a.split('/');",
  84. "return d + 'groups/' + rs[3] + '/?sorting_setting=' + c;",
  85. "}",
  86. "",
  87. "// # Arguments: a = href attribute, b = type of group disposition (CHRONOLOGICAL or RECENT_ACTIVITY), rs = a resource variable #",
  88. "function groupSec(a, b, rs){",
  89. "rs = a.toString().replace(/(.?)ref=bookmarks/gi, \"\");",
  90. "return rs + \"?sorting_setting=\" + b;",
  91. "}",
  92. "",
  93. ].join("\n");
  94. var js = document.createElement("script");
  95. js.type = "text/javascript";
  96. js.appendChild(document.createTextNode(arr));
  97. document.querySelectorAll("head")[0].appendChild(js);
  98. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址