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.5
  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-100.bar-md');
  19. let firstDiv = document.querySelector('#js-post-summaries');
  20. let secondDiv = document.querySelector('.bt.bc-black-075.p16');
  21.  
  22. if (parentDiv && firstDiv && secondDiv) {
  23. parentDiv.removeChild(firstDiv);
  24. parentDiv.removeChild(secondDiv);
  25. parentDiv.appendChild(secondDiv);
  26. parentDiv.appendChild(firstDiv);
  27. }
  28. }
  29.  
  30. // Swap divs on page load
  31. window.addEventListener('load', swapDivs, false);
  32.  
  33. // Refresh page when clicking on any of the sub-tabs
  34. let tabs = document.querySelectorAll('.js-user-tab-sort');
  35. tabs.forEach(tab => {
  36. tab.addEventListener('click', () => {
  37. // Timeout to allow for click processing and then reload page
  38. setTimeout(function(){ location.reload(); }, 0.3);
  39. }, false);
  40. });
  41.  
  42. })();