Take Twitter Link Preview Back

Take the link preview of Twitter back

  1. // ==UserScript==
  2. // @name Take Twitter Link Preview Back
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Take the link preview of Twitter back
  6. // @author solstice23
  7. // @match https://twitter.com/*
  8. // @match https://x.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. var node = document.createElement("style");
  17. node.type = "text/css";
  18. node.appendChild(document.createTextNode(`
  19. body[style*='background-color: rgb(255, 255, 255)'] {
  20. --link-preview-text-color: #000;
  21. }
  22. body[style*='background-color: rgb(0, 0, 0)'] {
  23. --link-preview-text-color: #fff;
  24. }
  25. body[style*='background-color: rgb(21, 32, 43)'] {
  26. --link-preview-text-color: #f7f9f9;
  27. }
  28. div[data-testid='card.layoutLarge.media'] > a::after {
  29. content: attr(aria-label);
  30. font-family: sans-serif;
  31. display: block;
  32. padding: 8px 10px;
  33. line-height: 1.3;
  34. color: var(--link-preview-text-color, #000);
  35. }
  36. div[data-testid='card.layoutLarge.media'] > a > div:last-child {
  37. bottom: unset;
  38. left: unset;
  39. top: 10px;
  40. right: 10px;
  41. }
  42. `));
  43. var heads = document.getElementsByTagName("head");
  44. if (heads.length > 0) {
  45. heads[0].appendChild(node);
  46. } else {
  47. document.documentElement.appendChild(node);
  48. }
  49. })();