Guest User

Bring back twitter meta tags

a guest
Jul 27th, 2023
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let ids = [];
  2.  
  3. setInterval(() => {
  4.   const shareButtons = document.querySelectorAll('[aria-label="Share\ Tweet"]');
  5.  
  6.   if (!shareButtons) {
  7.     console.log("Couldn't find share buttons");
  8.     return;
  9.   }
  10.   for (const shareButton of shareButtons) {
  11.     const id = shareButton.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.attributes.getNamedItem("aria-labelledby")?.value;
  12.     if (id && ids.includes(id)) return;
  13.     ids.push(id)
  14.     shareButton.addEventListener("click", (event) => {
  15.       setTimeout(() => {
  16.         const targetButton = document.querySelector('[data-testid="Dropdown"] > :first-child');
  17.         targetButton.addEventListener('click', () => {
  18.           // Function to run when the button is pressedc
  19.           setTimeout(myFunction, 300)
  20.         });
  21.  
  22.         async function myFunction() {
  23.           const permission = await navigator.permissions.query({
  24.               name: "clipboard-read",
  25.             });
  26.             if (permission.state === "denied") {
  27.               throw new Error("Not allowed to read clipboard.");
  28.             }
  29.             const clipboardContents = await navigator.clipboard.readText();
  30.           await navigator.clipboard.writeText(clipboardContents.replace("twitter.com", "twitter-og.com"))
  31.           console.log("Wrote " + clipboardContents.replace("twitter.com", "twitter-og.com"))
  32.         }
  33.       }, 500)
  34.     })
  35.   }
  36. }, 1000)
Advertisement
Add Comment
Please, Sign In to add comment