Add FB Download Button

Add a download button to dynamically change the URL to mbasic and open it in a new tab.

  1. // ==UserScript==
  2. // @name Add FB Download Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Add a download button to dynamically change the URL to mbasic and open it in a new tab.
  6. // @author You
  7. // @match *://*.facebook.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // Function to create and append the button
  16. function addDownloadButton() {
  17. const buttonId = "customDownloadButton";
  18. const buttonClasses = "x9f619 x1n2onr6 x1ja2u2z x78zum5 xdt5ytf x2lah0s x193iq5w x1xmf6yo x1e56ztr xzboxd6 x14l7nz5";
  19. const targetSelectors = [
  20. ".xygnafs > div:nth-child(1) > div:nth-child(1)", // Original target element
  21. ".xtp0wl1 > div:nth-child(2) > div:nth-child(2)" // New target element for video links
  22. ];
  23.  
  24. targetSelectors.forEach((selector) => {
  25. const targetElement = document.querySelector(selector);
  26.  
  27. if (targetElement && !targetElement.querySelector(`#${buttonId}`)) {
  28. // Create a button
  29. const button = document.createElement("button");
  30. button.id = buttonId;
  31. button.style.display = "flex";
  32. button.style.alignItems = "center";
  33. button.style.justifyContent = "center";
  34. button.style.border = "none";
  35. button.style.padding = "5px 5px";
  36. button.style.borderRadius = "100%";
  37. button.style.backgroundColor = "#663DA2";
  38. button.style.cursor = "pointer";
  39. button.style.position = "relative";
  40. button.style.marginLeft = "10px";
  41. button.style.width = "40px";
  42. button.style.height = "40px";
  43.  
  44. // Add an SVG icon inside the button
  45. button.innerHTML = `
  46. <svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" fill="#fff" viewBox="0 0 24 24">
  47. <path d="M5 20v-2h14v2H5Zm7-3-5-5 1.4-1.4 2.6 2.575V4h2v9.175L15.6 10.6 17 12l-5 5Z"/>
  48. </svg>
  49. `;
  50.  
  51. // Add click event to the button
  52. button.addEventListener("click", () => {
  53. const currentUrl = window.location.href;
  54. const modifiedUrl = currentUrl.replace("www.", "mbasic.");
  55. window.open(modifiedUrl, "_blank");
  56. });
  57.  
  58. // Create a wrapper div for button with the desired classes
  59. const div = document.createElement("div");
  60. div.style.display = "flex";
  61. div.style.alignItems = "center";
  62. div.classList.add(...buttonClasses.split(" "));
  63.  
  64. div.appendChild(button);
  65. targetElement.appendChild(div);
  66. }
  67. });
  68. }
  69.  
  70. // Observe for changes in the DOM
  71. const observer = new MutationObserver(() => {
  72. addDownloadButton();
  73. });
  74.  
  75. observer.observe(document.body, { childList: true, subtree: true });
  76.  
  77. // Try to add the button immediately if the elements already exist
  78. addDownloadButton();
  79. })();

QingJ © 2025

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