Twitter t.co GO TO HELL

Restore t.co links, support Twitter/TweetDeck

目前为 2019-08-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter t.co GO TO HELL
  3. // @description Restore t.co links, support Twitter/TweetDeck
  4. // @icon https://abs.twimg.com/favicons/favicon.ico
  5. // @include twitter.com
  6. // @match *://*.twitter.com/*
  7. // @exclude *://twitter.com/i/cards/*
  8. // @version 1.5.1
  9. // @grant GM_addStyle
  10. // @namespace https://greasyfork.org/users/113252-garrison-baird
  11. // @run-at document-end
  12. // ==/UserScript==
  13. // @updateURL https://greasyfork.org/scripts/28506-twitter-t-co-go-to-hell/code/Twitter%20tco%20GO%20TO%20HELL.user.js
  14. // @updateURL https://github.com/GarrisonBaird/GreasyForkScripts/raw/master/Twitter%20t.co%20GO%20TO%20HELL.user.js
  15.  
  16. GM_addStyle(`.js-tweet-text-container a.u-hidden {
  17. display: inherit !important;
  18. }`)
  19.  
  20. function main () {
  21. document.querySelectorAll('a[href*="t.co"]').forEach(function (el) {
  22. if (el.dataset && el.dataset.expandedUrl) { // Twitter web
  23. el.href = removeTracker(el.dataset.expandedUrl);
  24. }
  25. if (el.dataset && el.dataset.fullUrl) { // TweetDeck
  26. el.href = removeTracker(el.dataset.fullUrl);
  27. }
  28. if (el.title && el.title.match(/^https?:\/\//i)) { // New unified Twitter UI, including mobile.twitter.com
  29. el.href = removeTracker(el.title);
  30. }
  31. if (el.children.length > 0 && el.children[0].tagName == "SPAN" && el.children[0].innerText.startsWith("(link: ")) {
  32. // el.children[0].innerText == "(link: https://www.google.com/) "
  33. var href = el.children[0].innerText.trim();
  34. href = href.substring("(link: ".length, href.length - ")".length);
  35. el.href = removeTracker(href);
  36. }
  37. if (el.href.startsWith("https://t.co/")) { // if real url is not found, remove ?amp=1 at the ending
  38. el.href = el.href.replace(/\?amp=1$/, "");
  39. }
  40. });
  41. }
  42. function removeTracker (url) {
  43. // utm_*
  44. url = url.replace(new RegExp("\\?utm_[^&#]+", "gi"), "?")
  45. url = url.replace(new RegExp("&utm_[^&#]+", "gi"), "")
  46. return url
  47. }
  48.  
  49. main();
  50.  
  51. if (MutationObserver) {
  52. console.log("Twitter t.co GO TO HELL: Using MutationObserver");
  53. var observer = new MutationObserver(function(mutationsList, observer){
  54. main();
  55. });
  56. observer.observe(document.body, {
  57. attributes: false,
  58. characterData: false,
  59. childList: true,
  60. subtree: false,
  61. attributeOldValue: false,
  62. characterDataOldValue: false
  63. });
  64. }
  65. if (true) {
  66. if (window.location.host == 'tweetdeck.twitter.com') { // TweetDeck won't trigger 'scroll' event
  67. console.log("Twitter t.co GO TO HELL: Using setInterval");
  68. setInterval(main, 1000);
  69. } else {
  70. console.log("Twitter t.co GO TO HELL: Using addEventListener 'scroll' and setInterval");
  71. window.addEventListener('scroll', main);
  72. setInterval(main, 5000); // fallback
  73. }
  74. }