Last active
February 15, 2023 00:45
-
-
Save Lysak/5f684b9d6aa417cfbfa530ef96bd0d15 to your computer and use it in GitHub Desktop.
Automatically enable filter "Just my tasks" in Asana project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Automatically enable filter "Just my tasks" in Asana project | |
// @namespace https://github.com/Lysak | |
// @version 0.1.5 | |
// @description Automatically enable filter "Just my tasks" in Asana project (Code License: MIT License) | |
// @author Dmytrii Lysak @Lysak | |
// @match https://app.asana.com/* | |
// @icon https://www.google.com/s2/favicons?domain=asana.com | |
// @grant none | |
// @noframes | |
// ==/UserScript== | |
// Revision history | |
// 0.1 Initial implementation | |
// 0.1.2 | |
// 0.1.3 03.08.2022 - Final version | |
// 0.1.4 27.10.2022 - fixed filter menu selector name after Asana update | |
// 0.1.5 29.11.2022 - update again: fixed filter menu selector name after Asana update | |
const filterMenuClassName = '.PageToolbarStructure-rightChildren .SubtleToggleButton'; | |
document.querySelectorAll(filterMenuClassName) | |
function asana() { | |
setTimeout(function() { | |
if (document.querySelectorAll(filterMenuClassName)[0]?.textContent === 'Filter') { | |
console.log("Automatically enable filter \"Just my tasks\" in Asana project: load init"); | |
document.querySelectorAll(filterMenuClassName)[0].click(); | |
document.querySelector(".MenuPresentation .MenuItemA11y").click() | |
console.log("Automatically enable filter \"Just my tasks\" in Asana project: load complete"); | |
} | |
}, 1000); | |
} | |
// Convenience function to execute your callback only after an element matching readySelector has been added to the page. | |
// Example: runWhenReady('.search-result', augmentSearchResults); | |
// Gives up after 1 minute. | |
// https://github.com/Tampermonkey/tampermonkey/issues/1279#issuecomment-875386821 | |
function runWhenReady(readySelector, callback) { | |
var numAttempts = 0; | |
var tryNow = function() { | |
var elem = document.querySelector(readySelector); | |
if (elem) { | |
callback(elem); | |
} else { | |
numAttempts++; | |
if (numAttempts >= 34) { | |
console.warn('Giving up after 34 attempts. Could not find: ' + readySelector); | |
} else { | |
setTimeout(tryNow, 250 * Math.pow(1.1, numAttempts)); | |
} | |
} | |
}; | |
tryNow(); | |
} | |
runWhenReady(filterMenuClassName, asana); |
Hey Lysak, love the tamper monkey workaround you found for the custom view in Asana since they currently don’t have that feature. Great work!
Would it be possible to create this for a custom field instead of the my tasks filter? I'm looking to do this exact thing but for a custom people field for my team.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just test it, working correctly
Requirements:
Raw
button on gist script pageafter installation need to refresh asana page with cache Cmd+Shift+R (Ctrl+Shift+R)