Greasy Fork 还支持 简体中文。

Canonical links

Replace twitter redirection url (http://t.co/...) by the real URLs as to improve privacy.

目前為 2015-05-14 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Canonical links
  3. // @description Replace twitter redirection url (http://t.co/...) by the real URLs as to improve privacy.
  4. // @author Guillaume
  5. // @namespace https://greasyfork.org/fr/users/11386-guillaume
  6. // @include https://twitter.com/*
  7. // @version 1.1
  8. // @grant none
  9. // @run-at document-start
  10. // @license CC by-sa http://creativecommons.org/licenses/by-sa/3.0/
  11. // ==/UserScript==
  12.  
  13. // Credits:
  14. //
  15. // - getVisibleText, and textContentVisible
  16. // This is derived from a work by Ethan Brown.
  17. // Original license: cc-by sa
  18. // Source: http://stackoverflow.com/questions/19985306/get-the-innertext-of-an-element-but-exclude-hidden-children
  19.  
  20. function getVisibleText( node )
  21. {
  22. if ( node.nodeType === 1 ) // Element
  23. {
  24. var rect = node.getBoundingClientRect();
  25. if ( rect.width === 0 || rect.height === 0 )
  26. return '';
  27. }
  28. else if ( node.nodeType === 3 ) // Text
  29. {
  30. return node.textContent;
  31. }
  32. var text = '';
  33. for( var i = 0; i < node.childNodes.length; i++ )
  34. text += getVisibleText( node.childNodes[i] );
  35. return text;
  36. }
  37.  
  38. if ( ! Node.prototype.hasOwnProperty('textContentVisible') )
  39. {
  40. Object.defineProperty(Node.prototype, 'textContentVisible', {
  41. get: function() {
  42. return getVisibleText( this );
  43. },
  44. enumerable: true
  45. });
  46. }
  47.  
  48. var makeLinkCanonical = function(el)
  49. {
  50. var text = document.createTextNode(el.textContentVisible);
  51. var url = el.dataset.expandedUrl;
  52. var newLink = document.createElement('a');
  53. newLink.href = url;
  54. newLink.title = el.title;
  55. newLink.className = el.className;
  56. newLink.dir = el.dir;
  57. newLink.appendChild(text);
  58. el.parentNode.replaceChild(newLink, el);
  59. };
  60.  
  61. window.addEventListener("load", function(ev) {
  62. // unshadow for better debugging
  63. delete console.log;
  64. }, true);
  65.  
  66. document.addEventListener("load", function(ev) {
  67. [].slice.call(document.querySelectorAll('a[data-expanded-url]')).forEach(makeLinkCanonical);
  68. }, true);