隐藏抖音顶左栏

2023/6/12 19:20:21

  1. // ==UserScript==
  2. // @name 隐藏抖音顶左栏
  3. // @namespace 鼠标显示隐藏抖音header搜索和左侧栏
  4. // @match https://www.douyin.com/*
  5. // @namespace 476321082
  6. // @license MIT
  7. // @grant none
  8. // @version 1.0.0.2
  9. // @author -
  10. // @description 2023/6/12 19:20:21
  11. // ==/UserScript==
  12.  
  13. // Define CSS classes for the buttons
  14. const buttonStyles = `
  15. .button {
  16. display: block;
  17. margin: 5px;
  18. width: 60px;
  19. height: 30px;
  20. background-color: black;
  21. color: gray;
  22. }
  23. .button-show:hover, .button-hide:hover {
  24. background-color: gray;
  25. color: black;
  26. }
  27. `;
  28.  
  29. // Add the CSS to the page
  30. const style = document.createElement('style');
  31. style.textContent = buttonStyles;
  32. document.head.appendChild(style);
  33.  
  34. // Get the header, target, and right container elements
  35. const header = document.getElementById("douyin-header");
  36. const target = document.getElementById("douyin-navigation");
  37. const rightContainer = document.getElementById("douyin-right-container");
  38.  
  39. // Create a container for the buttons
  40. const container = document.createElement("div");
  41. container.style.position = "fixed";
  42. container.style.right = "0px";
  43. container.style.top = "300px";
  44. container.style.zIndex = "9999";
  45.  
  46. // Create show and hide buttons
  47. const showBtn = document.createElement("button");
  48. showBtn.innerText = "显示";
  49. showBtn.classList.add('button', 'button-show');
  50.  
  51. const hideBtn = document.createElement("button");
  52. hideBtn.innerText = "隐藏";
  53. hideBtn.classList.add('button', 'button-hide');
  54.  
  55. // Add buttons to the container
  56. container.appendChild(showBtn);
  57. container.appendChild(hideBtn);
  58.  
  59. // Add the container to the page
  60. document.body.appendChild(container);
  61.  
  62. // Define show and hide functions
  63. function showElements() {
  64. header.style.display = "block";
  65. target.style.display = "block";
  66. rightContainer.style.display = "";
  67. }
  68.  
  69. function hideElements() {
  70. header.style.display = "none";
  71. target.style.display = "none";
  72. rightContainer.style.display = "contents";
  73. }
  74.  
  75. // Add a single event listener to the container and use event delegation
  76. container.addEventListener('click', (event) => {
  77. if (event.target === showBtn) {
  78. showElements();
  79. } else if (event.target === hideBtn) {
  80. hideElements();
  81. }
  82. });
  83.  
  84. container.addEventListener('mouseover', (event) => {
  85. if (event.target === showBtn) {
  86. showElements();
  87. } else if (event.target === hideBtn) {
  88. hideElements();
  89. }
  90. });
  91.  

QingJ © 2025

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