Created
July 15, 2012 19:52
-
-
Save fstrube/3118363 to your computer and use it in GitHub Desktop.
Bookmarklet to make Basecamp todo's better (parse priority and progress, similar to todo.txt)
This file contains hidden or 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
;(function(){ | |
var todos = $$('.item .content span .content span:first-child'); | |
todos.each(function(element) { | |
if ( element.getAttribute('data-original-text') ) element.innerText = element.getAttribute('data-original-text'); | |
parseTodo(element); | |
}); | |
function parseTodo(element) { | |
/* Original Text */ | |
if ( element.getAttribute('data-original-text') === null ) | |
element.setAttribute('data-original-text', element.innerText); | |
/* Priority */ | |
var regexPriority = /^\s*\(([a-z])\)(.*)$/i; | |
var priority = element.innerText.match(regexPriority); | |
if ( priority !== null ) { | |
element.className += ' priority-'+priority[1]; | |
element.innerText = element.innerText.replace(regexPriority, '$2'); | |
} | |
/* Progress Bars */ | |
var regexProgress = /(\[(=+[^= ]+|=+|[^= ]{1,10})\])/; | |
var progress = element.innerText.match(regexProgress); | |
if ( progress !== null ) { | |
console.log(progress); | |
var percent = progress[2].replace(/[^=]/g,'').length / progress[2].length; | |
element.innerText = element.innerText.replace(regexProgress, ''); | |
element.parentElement.innerHTML = progressBar(percent) + element.parentElement.innerHTML; | |
/* element.innerHTML = element.innerHTML.replace(progress[i], replaceProgress); */ | |
} | |
} | |
function replaceProgress(match) { | |
var percent = match.replace(/[^=]/,'').length / (match.length - 2); | |
return progress(percent); | |
} | |
function progressBar(percent) { | |
if ( percent < 1 ) percent = percent * 100; | |
var color = "#6FB1EE"; | |
if ( percent < 25 ) color = "#E73535"; | |
if ( percent > 75 ) color = "#129200"; | |
return '<span style="border: 1px solid #999; border-radius: 3px; height: 10px; width: 64px; display:inline-block;"><span style="background: '+color+'; display: inline-block; height: 100%; width: '+percent+'%"></span></span>' | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment