Facebook (Insert View Post Button)

Inserts a View Post button when browsing photos on Facebook — e.g. Navigates away from the standard theater view

  1. // ==UserScript==
  2. // @name Facebook (Insert View Post Button)
  3. // @match https://www.facebook.com/*
  4. // @match http://www.facebook.com/*
  5. // @icon https://www.google.com/s2/favicons?domain=facebook.com
  6. // @run-at document-start
  7. // @grant GM_addStyle
  8. // @author JZersche (Free Release)
  9. // @require https://gf.qytechs.cn/scripts/12228/code/setMutationHandler.js
  10. // @version 1.02
  11. // @namespace https://gf.qytechs.cn/users/95175
  12. // @description
  13. // @description Inserts a View Post button when browsing photos on Facebook — e.g. Navigates away from the standard theater view
  14. // ==/UserScript==
  15.  
  16. let i = 0;
  17.  
  18. setMutationHandler({
  19. target: document,
  20. selector: '.d2edcug0.hpfvmrgz.qv66sw1b.c1et5uql.lr9zc1uh.a8c37x1j.keod5gw0.nxhoafnm.aigsh9s9.d3f4x2em.fe6kdd0r.mau55g9w.c8b282yb.iv3no6db.gfeo3gy3.a3bd9o3v.knj5qynh.oo9gr5id',
  21. handler: nodes => nodes.forEach(node => {
  22. setTimeout(function(){
  23. try{if(window.location.href.match(/facebook\.com\/photo\/\?fbid\=\d+\&set\=a\.\d+/)[0] && i == 0) {
  24. let p1 = node.children[0].children[0].children[0].children[0].children[0].href.match(/com\/\w+/)[0].substring(4);
  25. let p2 = node.children[0].children[0].children[0].children[0].children[0].href.substring(25).replace('?__tn__=-UC*F','');
  26. console.log(p1);
  27. console.log(p2);
  28.  
  29.  
  30. if(p1.length !== p2.length) {var pagename = p2}
  31. if(!pagename) {pagename = document.getElementsByClassName('aahdfvyu')[1].children[0].children[0].children[0].href.match(/facebook\.com\/\S+\?/)[0].replace('facebook.com/','').replace('?','')}
  32. let albumid = window.location.href.match(/\d+/g)[1];
  33. let postid = window.location.href.match(/\d+/g)[0];
  34. var j = 1;
  35. nodes[j].setAttribute('style','border:1px solid #f000;');
  36. if(nodes[j].parentNode.classList == 'ecm0bbzt e5nlhep0 a8c37x1j') {j = 0;}
  37.  
  38. nodes[j].insertAdjacentHTML('afterend',`
  39. <div class="viewpost" style="background: #000; width: 67px; text-align: center; border-radius: 4px; margin-top: 6px; border: 1px solid #fff; line-height: 14px;font-size: 14px; padding: 3px;">\
  40. <span style="color:#fff;font-weight:600;font-family:inherit;"><a style="text-decoration:none;" href="https://www.facebook.com/`+pagename+`/posts/`+postid+`">View Post</a></span></div>`);
  41. i = 1;
  42. }}catch(e){}
  43. try{if(window.location.href.match(/facebook\.com\/photo\/\?fbid\=\d+\&set\=pb\.\d+\.\-\d+\.\./)[0] && i == 0) {
  44. console.log('B');
  45. nodes[1].setAttribute('style','border:1px dashed #f000;');
  46. i = 1;
  47. }}catch(e){}
  48. try{if(window.location.href.match(/facebook\.com\/\d+\/photos\/a\.\d+\/\d+/)[0] && i == 0) {
  49. console.log('C');
  50. nodes[2].setAttribute('style','border:1px solid #0f00;');
  51. i = 1;
  52. }}catch(e){}
  53. try{if(window.location.href.match(/facebook\.com\/photo\.php\?fbid\=\d+\&set\=pb\.\d+\.\-\d+\.\.\&type\=3/)[0] && i == 0) {
  54. console.log('D');
  55. nodes[2].setAttribute('style','border:1px solid #00f0;');
  56. i = 1;
  57. }}catch(e){}
  58. try{if(window.location.href.match(/facebook\.com\/\w+.+\/photos\/a\.\d+\/\d+/)[0] && i == 0) {
  59. console.log('E');
  60. console.log(node);
  61.  
  62. if(window.location.href.match(/https:\/\/www\.facebook\.com\/\w+.+\/photos/)[0].replace('https://www.facebook.com/','').replace('/photos','')){
  63. var pagename = window.location.href.match(/https:\/\/www\.facebook\.com\/\w+.+\/photos/)[0].replace('https://www.facebook.com/','').replace('/photos','');
  64. }
  65.  
  66. let albumid = window.location.href.match(/\d+/g)[0];
  67. let postid = window.location.href.match(/\d+/g)[1];
  68.  
  69. node.setAttribute('style','border:1px solid #f0f0;');
  70. if(node.parentNode.classList === 'a8nywdso j7796vcc rz4wbd8a l29c1vbm' || node.parentNode.classList === 'j7796vcc') {alert(node.parentNode.classList)};
  71. node.insertAdjacentHTML('afterend',`
  72. <div class="viewpost" style="background: #000; width: 67px; text-align: center; border-radius: 4px; margin-top: 6px; border: 1px solid #fff; line-height: 14px;font-size: 14px; padding: 3px;">\
  73. <span style="color:#fff;font-weight:600;font-family:inherit;"><a style="text-decoration:none;" href="https://www.facebook.com/`+pagename+`/posts/`+postid+`">View Post</a></span></div>`);
  74. i = 1;
  75. }}catch(e){}
  76.  
  77.  
  78. },5000)
  79. })
  80. })

QingJ © 2025

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