Twitter - own tweets

Adds a link to users' pages to search for tweets only from them (no retweets without comment).

当前为 2020-06-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter - own tweets
  3. // @version 1
  4. // @grant none
  5. // @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js
  6. // @match https://twitter.com/*
  7. // @author monnef
  8. // @description Adds a link to users' pages to search for tweets only from them (no retweets without comment).
  9. // @namespace monnef.eu
  10. // ==/UserScript==
  11.  
  12. const linkMarker = 'monnef--no-retweets';
  13.  
  14. const work = () => {
  15. // fragile as fuck bc all twitter's css classes are obfuscated >:(
  16. const primEl = $('main > div > div > div > div:first-child');
  17. const followEl = $('[role=button]:contains(Follow)', primEl);
  18. const userInfoEl = followEl.parent().parent().parent().parent().parent();
  19. const uiPos = userInfoEl.offset()
  20. const nameEl = $(document.elementFromPoint(uiPos.left + 20, uiPos.top + 90));
  21. const handle = nameEl.text();
  22. if (!nameEl.length || !handle.startsWith('@')) return;
  23. if (nameEl.parent().find(`.${linkMarker}`).length) return;
  24. const linkEl = $("<a/>")
  25. .attr('href', `/search?q=from%3A%40${handle.slice(1)}&src=typed_query`)
  26. .text('own tweets')
  27. .addClass(linkMarker)
  28. .css('color', 'rgb(29, 161, 242)')
  29. .css('margin-left', '0.5em')
  30. ;
  31. nameEl.after(linkEl);
  32. }
  33.  
  34. $(() => setInterval(work, 2000))