Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-Hide Favorites With 0 Tasks #195

Open
jakelfreeman opened this issue Jan 19, 2022 · 1 comment
Open

Auto-Hide Favorites With 0 Tasks #195

jakelfreeman opened this issue Jan 19, 2022 · 1 comment
Labels
enhancement New feature or request help wanted Pull requests fixing this are encouraged

Comments

@jakelfreeman
Copy link

Posting this as a potential enhancement that I coded for myself a few months ago. I was tired of looking at filters in my favorites list that didn't have any tasks, so created a code snippet to auto-hide them when the last task is completed and have them show up again as soon as they contain a task. I'm a self-taught, noobie coder so I'm sure this is far from elegant, but figured I'd share the concept in case anyone wants to improve upon it and/or include it in future releases of this extension:

function initiate_hide_filters(){
	var param = "AuiqUdaGFITJcNpaWKvZFA==";
	var escapedParam = param.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g,'\\$1');
	
	
	const targetNode = document.querySelectorAll(".sidebar_expansion_panel,.expansion_panel,.expansion_panel--expanded")[0];

	const config = { attributes: false, childList: true, subtree: true };
	
	const callback = function(mutationsList, observer) {
	    var favContainer = $(".sidebar_expansion_panel.expansion_panel.expansion_panel--expanded")[0];
	    $(favContainer).find("li").each(function(){ 
			var container = $(this).find($("."+escapedParam)); 
			if(container.length==0){ $(this).hide(); }else{ $(this).show(); }
		});
		if(AUTO_HIDE_EMPTY_LABELS){
			var labelContainer = $(".sidebar_expansion_panel.expansion_panel.expansion_panel--expanded")[1];
		    $(labelContainer).find("li").not(".FilterListItemSortable").each(function(){ 
				var labelCounter = $(this).find(".counter_count"); 
				if(labelCounter.length==0){ $(this).hide(); }else{ $(this).show(); }
			});
		}
	};
	
	const observer = new MutationObserver(callback);
	
	observer.observe(targetNode, config);
	var favContainer = $(".sidebar_expansion_panel.expansion_panel.expansion_panel--expanded")[0];
	$(favContainer).find("li").not(".FilterListItemSortable").each(function(){ 
		var container = $(this).find($("."+escapedParam)); 
		if(container.length==0){ $(this).hide(); }else{ $(this).show(); }
	});
	if(AUTO_HIDE_EMPTY_LABELS){
		var labelContainer = $(".sidebar_expansion_panel.expansion_panel.expansion_panel--expanded")[1];
	    $(labelContainer).find("li").each(function(){ 
			var labelCounter = $(this).find(".counter_count"); 
			if(labelCounter.length==0){ $(this).hide(); }else{ $(this).show(); }
		});
	}
}

Then, to get it to run post-load, I just used:

$(document).ready(function(){ setTimeout(initiate_hide_filters, 3000); });
@mgsloan
Copy link
Owner

mgsloan commented Jan 31, 2022

Nice! I definitely would like to auto-hide my favorite filters that have no tasks.

One trickiness with adding such functionality is that so far todoist-shortcuts has no options. So, would need to add an options page. Which isn't /that/ hard, but still I feel a bit of hesitance to do so. Might revisit this in the future!

@mgsloan mgsloan added enhancement New feature or request help wanted Pull requests fixing this are encouraged labels Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Pull requests fixing this are encouraged
Projects
None yet
Development

No branches or pull requests

2 participants