Show Deleted Answers at head for StackExchange

Swap two divs inside a parent

当前为 2023-09-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Show Deleted Answers at head for StackExchange
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Swap two divs inside a parent
  6. // @author aspen138
  7. // @match https://*.stackexchange.com/users/*/*?tab=answers*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to swap divs
  16. function swapDivs() {
  17. let parentDiv = document.querySelector('.ba.bc-black-100.bar-md');
  18. let firstDiv = document.querySelector('#js-post-summaries');
  19. let secondDiv = document.querySelector('.bt.bc-black-075.p16');
  20.  
  21. if (parentDiv && firstDiv && secondDiv) {
  22. parentDiv.removeChild(firstDiv);
  23. parentDiv.removeChild(secondDiv);
  24. parentDiv.appendChild(secondDiv);
  25. parentDiv.appendChild(firstDiv);
  26. }
  27. }
  28.  
  29. // Swap divs on page load
  30. window.addEventListener('load', swapDivs, false);
  31.  
  32. // Refresh page when clicking on any of the sub-tabs
  33. let tabs = document.querySelectorAll('.js-user-tab-sort');
  34. tabs.forEach(tab => {
  35. tab.addEventListener('click', () => {
  36. // Timeout to allow for click processing and then reload page
  37. setTimeout(function(){ location.reload(); }, 0.3);
  38. }, false);
  39. });
  40.  
  41. })();