Twitter: Hide Retweet

Support 2019 new UI Twitter only.

目前为 2020-04-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter: Hide Retweet
  3. // @version 1.0.9
  4. // @description Support 2019 new UI Twitter only.
  5. // @author Hayao-Gai
  6. // @namespace https://github.com/HayaoGai
  7. // @icon https://i.imgur.com/M9oO8K9.png
  8. // @include https://twitter.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. /* jshint esversion: 6 */
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const retweet = 'path[d="M23.615 15.477c-.47-.47-1.23-.47-1.697 0l-1.326 1.326V7.4c0-2.178-1.772-3.95-3.95-3.95h-5.2c-.663 0-1.2.538-1.2 1.2s.537 1.2 1.2 1.2h5.2c.854 0 1.55.695 1.55 1.55v9.403l-1.326-1.326c-.47-.47-1.23-.47-1.697 0s-.47 1.23 0 1.697l3.374 3.375c.234.233.542.35.85.35s.613-.116.848-.35l3.375-3.376c.467-.47.467-1.23-.002-1.697zM12.562 18.5h-5.2c-.854 0-1.55-.695-1.55-1.55V7.547l1.326 1.326c.234.235.542.352.848.352s.614-.117.85-.352c.468-.47.468-1.23 0-1.697L5.46 3.8c-.47-.468-1.23-.468-1.697 0L.388 7.177c-.47.47-.47 1.23 0 1.697s1.23.47 1.697 0L3.41 7.547v9.403c0 2.178 1.773 3.95 3.95 3.95h5.2c.664 0 1.2-.538 1.2-1.2s-.535-1.2-1.198-1.2z"]:not(.hide)';
  18. const like = 'path[d="M12 21.638h-.014C9.403 21.59 1.95 14.856 1.95 8.478c0-3.064 2.525-5.754 5.403-5.754 2.29 0 3.83 1.58 4.646 2.73.814-1.148 2.354-2.73 4.645-2.73 2.88 0 5.404 2.69 5.404 5.755 0 6.376-7.454 13.11-10.037 13.157H12z"]';
  19. const reply = 'path[d="M14.046 2.242l-4.148-.01h-.002c-4.374 0-7.8 3.427-7.8 7.802 0 4.098 3.186 7.206 7.465 7.37v3.828c0 .108.044.286.12.403.142.225.384.347.632.347.138 0 .277-.038.402-.118.264-.168 6.473-4.14 8.088-5.506 1.902-1.61 3.04-3.97 3.043-6.312v-.017c-.006-4.367-3.43-7.787-7.8-7.788z"]';
  20. const follow = 'path[d="M12.225 12.165c-1.356 0-2.872-.15-3.84-1.256-.814-.93-1.077-2.368-.805-4.392.38-2.826 2.116-4.513 4.646-4.513s4.267 1.687 4.646 4.513c.272 2.024.008 3.46-.806 4.392-.97 1.106-2.485 1.255-3.84 1.255zm5.849 9.85H6.376c-.663 0-1.25-.28-1.65-.786-.422-.534-.576-1.27-.41-1.968.834-3.53 4.086-5.997 7.908-5.997s7.074 2.466 7.91 5.997c.164.698.01 1.434-.412 1.967-.4.505-.985.785-1.648.785z"]';
  21. let scrolling = false;
  22.  
  23. locationChange();
  24. window.addEventListener("load", init);
  25. window.addEventListener("scroll", scroll);
  26.  
  27. function init() {
  28. for (let i = 0; i < 10; i++) {
  29. setTimeout(getTarget, 500 * (i + 1));
  30. }
  31. }
  32.  
  33. function scroll() {
  34. if (scrolling) return;
  35. scrolling = true;
  36. init();
  37. setTimeout(() => {
  38. scrolling = false;
  39. }, 1000);
  40. }
  41.  
  42. function getTarget() {
  43. setTarget(retweet);
  44. setTarget(like);
  45. setTarget(reply);
  46. setTarget(follow);
  47. }
  48.  
  49. function setTarget(target) {
  50. document.querySelectorAll(target).forEach(t => {
  51. t.classList.add("hide");
  52. t.closest(".css-1dbjc4n.r-1ila09b.r-qklmqi.r-1adg3ll").parentElement.style.display = "none";
  53. });
  54. }
  55.  
  56. function locationChange() {
  57. window.addEventListener('locationchange', init);
  58. // situation 1
  59. history.pushState = ( f => function pushState(){
  60. var ret = f.apply(this, arguments);
  61. window.dispatchEvent(new Event('pushState'));
  62. window.dispatchEvent(new Event('locationchange'));
  63. return ret;
  64. })(history.pushState);
  65. // situation 2
  66. history.replaceState = ( f => function replaceState(){
  67. var ret = f.apply(this, arguments);
  68. window.dispatchEvent(new Event('replaceState'));
  69. window.dispatchEvent(new Event('locationchange'));
  70. return ret;
  71. })(history.replaceState);
  72. // situation 3
  73. window.addEventListener('popstate', () => {
  74. window.dispatchEvent(new Event('locationchange'));
  75. });
  76. }
  77.  
  78. })();