tiebaSortById

百度贴吧按发帖时间(帖子ID)排序

  1. // ==UserScript==
  2. // @name tiebaSortById
  3. // @namespace https://github.com/sakuyaa/gm_scripts
  4. // @author sakuyaa
  5. // @description 百度贴吧按发帖时间(帖子ID)排序
  6. // @include http*://tieba.baidu.com/f*
  7. // @version 2017.10.8
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11. (function() {
  12. function sortById() {
  13. var parentNode = document.getElementById('thread_list');
  14. var threads = parentNode.querySelectorAll('.j_thread_list:not(.thread_top)');
  15. var threadArray = [];
  16. for (var thread of threads) {
  17. try {
  18. threadArray.push({
  19. id: JSON.parse(thread.getAttribute('data-field')).id,
  20. thread: thread
  21. });
  22. parentNode.removeChild(thread);
  23. } catch (e) {
  24. console.log(e);
  25. }
  26. }
  27. threadArray.sort((a, b) => {
  28. return b.id - a.id;
  29. });
  30. for (var thread of threadArray) {
  31. parentNode.appendChild(thread.thread);
  32. }
  33. }
  34. var code = setInterval(() => {
  35. var node = document.getElementsByClassName('card_infoNum');
  36. if (node.length) {
  37. clearInterval(code);
  38. var a = document.createElement('a');
  39. a.textContent = '按发帖时间排序';
  40. a.setAttribute('href', 'javascript:;');
  41. a.addEventListener('click', e => {
  42. sortById();
  43. }, false);
  44. node[0].parentNode.appendChild(a);
  45. }
  46. }, 500);
  47. })();