Created
February 2, 2018 08:58
-
-
Save jacrify/67f68a544f09bd83cd18a14231f1ceac 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 Dynalist Count Tags | |
// @include https://dynalist.io/* | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js | |
// @grant GM_addStyle | |
// ==/UserScript== | |
/*- The @grant directive is needed to work around a design change | |
introduced in GM 1.0. It restores the sandbox. | |
*/ | |
var current_poll_interval; | |
function startCurrentPolling() { | |
current_poll_interval = setInterval(currentPoll, 1000); | |
} | |
function replace_node_text(i,obj) { | |
} | |
function currentPoll() { | |
//cache for perormance | |
var nodetags = $("a.node-tag"); | |
//strings to look for | |
var countstring = '#count'; | |
var sumstring = '#sum'; | |
//find anchor nodes containting count function, iterate | |
nodetags.filter("[title^='Filter " + countstring + "']").each(function(i, obj) { | |
//get actual function out of title -eg #count(#test) | |
var title = $(this).attr('title'); | |
var re = /\#count\(([#@][^\)]*)\)/; | |
var found = title.match(re); | |
if (found != null) { | |
//fullString = found[0]; | |
var tagToCount = found[1]; | |
//Search for node tags with title such as "Filter #test", and count them | |
var numItems = nodetags.filter("[title='Filter " + tagToCount + "']").length; | |
//Replace into content of original (function) anchor | |
$(this).text(numItems); | |
} | |
}); | |
//find anchor nodes containting sum function, iterate | |
nodetags.filter("[title^='Filter " + sumstring + "']").each(function(i, obj) { | |
//get actual function out of title -eg #sum(#test) | |
var title = $(this).attr('title'); | |
var re = /\#sum\(([#@][^\)]*)\)/; | |
var found = title.match(re); | |
if (found != null) { | |
var tagToSum = found[1]; | |
var total = 0; | |
//Search for node tags with title such as "Filter #test=", iterate | |
nodetags.filter("[title^='Filter " + tagToSum + "=']").each(function(j, obj1) { | |
//from titles, grab the number after the equals. Eg #test=10 <- we want 10 | |
var title1 = $(this).attr('title'); | |
var re1 = /\#[^=]*=(\d+)/; | |
var found1 = title1.match(re1); | |
//total it up | |
total += parseInt(found1[1]) || 0; | |
}); | |
//Replace into content of original (function) anchor | |
$(this).text(total); | |
} | |
}); | |
} | |
function stopCurrentPolling() { | |
clearInterval(current_poll_interval); | |
} | |
startCurrentPolling(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment