Twitter Timeline URL Expand

Replace t.co href of A tag with real url.

  1. // ==UserScript==
  2. // @name Twitter Timeline URL Expand
  3. // @namespace Twitter-Timeline-URL-Expand
  4. // @description Replace t.co href of A tag with real url.
  5. // @match http://twitter.com/*
  6. // @match https://twitter.com/*
  7. // @version 1.1
  8. // ==/UserScript==
  9. (function (window) {
  10. var document = window.document;
  11. var OneTimeTrigger = function (func, delay) {
  12. var timerCountdown = 0;
  13. return function() {
  14. setTimeout(function() {
  15. timerCountdown -= 1;
  16. if (timerCountdown == 0) {
  17. func();
  18. }
  19. }, delay);
  20. timerCountdown += 1;
  21. };
  22. };
  23. var expandAllLink = function () {
  24. var expandedUrl;
  25. Array.prototype.forEach.call(document.querySelectorAll("a.twitter-timeline-link:not(.timeline-link-expanded)"),
  26. function (node) {
  27. if (/^http(?:s)?:\/\/t\.co\/[0-9A-Za-z]+$/g.test(node.href)) {
  28. expandedUrl = node.getAttribute("data-expanded-url");
  29. if (expandedUrl) {
  30. node.href = expandedUrl;
  31. }
  32. node.className += " timeline-link-expanded";
  33. }
  34. });
  35. };
  36. var trigger = OneTimeTrigger(expandAllLink, 100);
  37. var MutationObserver = window.MutationObserver ? window.MutationObserver : window.WebKitMutationObserver;
  38. if (typeof MutationObserver !== "undefined") {
  39. var observer = new MutationObserver(trigger);
  40. observer.observe(document, { childList: true, subtree: true });
  41. }
  42. else {
  43. document.addEventListener("DOMNodeInserted", trigger, false);
  44. document.addEventListener("DOMSubtreeModified", trigger, false);
  45. }
  46.  
  47. })(window);

QingJ © 2025

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