philipmwhiteside / Better Moo.do

// ==UserScript==
// @name         Better Moo.do
// @description  Automatically create different tags
// @author       Philiphlop
// @match        https://www.moo.do/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
// @run-at       document-load
// @version      0.2
// @license      MIT
// ==/UserScript==

function updateTag (taskTag) {
    var tag = taskTag[0].innerHTML.substring(1);
    taskTag[0].className += " "+tag;
}

function autoHeader (taskItem) {
    console.log("------");
    if (taskItem[0].innerHTML.indexOf("!!") != -1){
        console.log("--");
        console.log(taskItem[0]);
        taskItem[0].className += " taskHeader";
        console.log(taskItem[0]);
        taskItem[0].innerHTML = taskItem[0].innerHTML.replace(/class="line first last"/g,'class="line first last listHeader"');
    }
}

function createTag (taskLine) {
    var newLine = taskLine[0].innerHTML
    if (taskLine[0].innerHTML.substring().indexOf('+') > -1) {
        newLine = newLine.replace(/(\+\S+)/g,'<span class="tagPlus">$1</span>')
    }
    if (taskLine[0].innerHTML.substring().indexOf('~') > -1) {
        newLine = newLine.replace(/(\~\S+)/g,'<span class="tagTildle">$1</span>')
    }
    if (taskLine[0].innerHTML.substring().indexOf('£') > -1) {
        newLine = newLine.replace(/(\£\S+)/g,'<span class="tagPound">$1</span>')
    }
    if (taskLine[0].innerHTML.substring().indexOf('$') > -1) {
        newLine = newLine.replace(/(\$\S+)/g,'<span class="tagDollar">$1</span>')
    }
    if (taskLine[0].innerHTML.substring().indexOf('?') > -1) {
        newLine = newLine.replace(/(\?\S+)/g,'<span class="tagQuestion">$1</span>')
    }
    taskLine[0].innerHTML = newLine
}

function main(){
    console.log("--------------------------------------------------------------");
    console.log("Better Moo.do script");
    waitForKeyElements ("div.paneRoot span.line span.tag", updateTag);
    waitForKeyElements ("div.paneRoot li.pHeader", autoHeader);
    waitForKeyElements ("div.paneRoot span.line", createTag);
}

main();