Linkify Twitter Trends

Make Twitter trends links (again)

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

  1. // ==UserScript==
  2. // @name Linkify Twitter Trends
  3. // @description Make Twitter trends links (again)
  4. // @author chocolateboy
  5. // @copyright chocolateboy
  6. // @version 0.0.3
  7. // @namespace https://github.com/chocolateboy/userscripts
  8. // @license GPL: http://www.gnu.org/copyleft/gpl.html
  9. // @include https://twitter.com/
  10. // @include https://twitter.com/*
  11. // @include https://mobile.twitter.com/
  12. // @include https://mobile.twitter.com/*
  13. // @require https://code.jquery.com/jquery-3.5.1.slim.min.js
  14. // @require https://cdn.jsdelivr.net/gh/eclecto/jQuery-onMutate@79bbb2b8caccabfc9b9ade046fe63f15f593fef6/src/jquery.onmutate.min.js
  15. // @grant GM_log
  16. // @inject-into auto
  17. // ==/UserScript==
  18.  
  19. // XXX note: the unused grant is a workaround for a Greasemonkey bug:
  20. // https://github.com/greasemonkey/greasemonkey/issues/1614
  21.  
  22. function onTrends ($trends) {
  23. for (const el of $trends) {
  24. const $trend = $(el)
  25. const quoted = $trend.text().replace(/"/g, '')
  26. const query = encodeURIComponent('"' + quoted + '"')
  27. const href = `${location.origin}/search?q=${query}`
  28. const $link = $('<a></a>').attr('href', href)
  29. $trend.wrap($link)
  30. }
  31. }
  32.  
  33. $.onCreate('[data-testid="trend"] [dir="ltr"] > span', onTrends, true /* multi */)