Last active
October 24, 2016 14:10
-
-
Save yurylyt/877e6df54f3e210548a26a5a5305c20a to your computer and use it in GitHub Desktop.
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 Maxdone Hide Recurring | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Hide recurring tasks | |
// @author Yury Lytvynenko | |
// @match https://maxdone.micromiles.co/* | |
// @grant none | |
// ==/UserScript== | |
var hidden = false; | |
function initialize() { | |
$("#secMenuContent").append('<div id="toggleRecurring" class="mm-btn-simple-small marginLeft10">toggle recurring</div>'); | |
$(document).on({ | |
click: function () { | |
toggleRecurring(); | |
} | |
}, '#toggleRecurring'); | |
new MutationObserver(function(mutations){ | |
mutations.forEach(function(mutation) { | |
if (hidden) toggle(false); | |
}); | |
}).observe(document.querySelector('#taskRows'), { attributes: true, childList: true, characterData: true }); | |
} | |
function updateCount(i, box) { | |
var countId = "#" + box + "Count"; | |
var contentId = "#" + box + "Content"; | |
var count = $(contentId + " > .listItem:visible").size(); | |
$(countId).text("(" + count + ")"); | |
} | |
function openIfClosed(i, box) { | |
var headerId = "#" + box + "Header"; | |
if ($(headerId + ".open").size() == 0) { | |
$(headerId).click(); | |
return true; | |
} | |
return false; | |
} | |
function closeOpened(i, box) { | |
$("#" + box + "Header").click(); | |
} | |
function toggleRecurring() { | |
toggle(hidden); | |
hidden = !hidden; | |
} | |
function toggle(hide) { | |
var boxes = $(["today", "week", "later"]); | |
// Expand boxes to properly update counts | |
var opened = boxes.filter(openIfClosed); | |
$(".recurring-task-parent").parent().parent().toggle(hide); | |
boxes.each(updateCount); | |
// Restore the initial box expand state | |
opened.each(closeOpened); | |
} | |
(function() { | |
'use strict'; | |
setTimeout(initialize, 5000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment