Tiktok 按点击排序 优化版

点击用户主页的视频Tab按点击排序,再点一次取消排序!

  1. // ==UserScript==
  2. // @name:zh-CN Tiktok 按点击排序 优化版
  3. // @name Tiktok sort by view+
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1.0
  6. // @description Click the video tab on tiktok user page to sort video by views and click again to restore order!
  7. // @description:zh-cn 点击用户主页的视频Tab按点击排序,再点一次取消排序!
  8. // @author You
  9. // @match https://www.tiktok.com/@*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=tiktok.com
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. const multiplierMap = {
  16. k: 10 ** 3,
  17. m: 10 ** 6,
  18. b: 10 ** 9,
  19. }
  20.  
  21. const sort = () => {
  22. const box = document.querySelector('[data-e2e="user-post-item-list"]');
  23. const items = Array.from(box.children).map(v => {
  24. const viewsString = v.querySelector('[data-e2e="video-views"]').textContent.trim();
  25. const views = isNaN(viewsString) ? parseFloat(viewsString.slice(0, -1)) * multiplierMap[viewsString.at(-1).toLowerCase()] : parseFloat(viewsString)
  26. return [v, views]
  27. })
  28. .sort((a, b) => b[1] - a[1])
  29.  
  30. const sorted = items.every(v => v[0].style.order)
  31.  
  32. items.forEach((v, i) => {
  33. v[0].style.order = sorted
  34. ? ''
  35. : String(i + 1)
  36. })
  37. }
  38.  
  39. const sleep = time => new Promise(rs => setTimeout(rs, time))
  40. const main = async () => {
  41. while(true) {
  42. await sleep(500)
  43. const videoTab = document.querySelector('[data-e2e="videos-tab"]')
  44. if (!videoTab) continue
  45. videoTab.addEventListener('click', sort)
  46. break
  47. }
  48. }
  49. main()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址