Auto Expand Subtasks - Asana

Auto Expand sub-tasks of selected Task and collapse other Tasks.

目前為 2022-10-21 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Auto Expand Subtasks - Asana
  3. // @name:de Unteraufgaben Automatisch anzeigen - Asana
  4. // @namespace https://greasyfork.org/users/928242
  5. // @version 0.1
  6. // @description Auto Expand sub-tasks of selected Task and collapse other Tasks.
  7. // @description:de Klappt automatisch die Unteraufgaben der ausgewählten Aufgabe aus und schließt die anderen.
  8. // @author Kamikaze (https://github.com/Kamiikaze)
  9. // @match https://app.asana.com/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=asana.com
  11. // @grant none
  12. // @run-at document-ready
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. console.log("Started [Auto Expand Subtasks - Asana]")
  17.  
  18. let checkReadyState = setInterval( () => {
  19. if (document.readyState === 'complete') addAutoExpand()
  20. }, 1000)
  21.  
  22. function collapseTasks() {
  23. const subTaskButtons = document.querySelectorAll(".ProjectSpreadsheetGridRow-subtaskToggleButton")
  24.  
  25. for (let el = 0; el < subTaskButtons.length; el++) {
  26. const item = subTaskButtons[el]
  27. const isExpanded = item.childNodes[0].classList.contains("DownTriangleIcon")
  28.  
  29. if(isExpanded) item.click()
  30. }
  31. }
  32.  
  33. function addAutoExpand() {
  34. clearInterval(checkReadyState)
  35.  
  36. const taskItems = document.querySelectorAll(".SpreadsheetRow-stickyCell")
  37.  
  38. for (let el = 0; el < taskItems.length; el++) {
  39. const item = taskItems[el]
  40. item.addEventListener("click", () => {
  41. collapseTasks()
  42.  
  43. const toggleButton = item.querySelector(".ProjectSpreadsheetGridRow-subtaskToggleButton")
  44. toggleButton.click()
  45. })
  46. }
  47. }