Show Deleted Answers at head for StackExchange

Swap two divs inside a parent

当前为 2023-11-12 提交的版本,查看 最新版本

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