diff --git a/src/scripts/content/coda.js b/src/scripts/content/coda.js new file mode 100644 index 000000000..5faf14033 --- /dev/null +++ b/src/scripts/content/coda.js @@ -0,0 +1,59 @@ +'use strict'; + +// over all rows rendered in coda +togglbutton.render('.kr-row:not(.toggl)', { observe: true }, function (elem) { + // prevent rendering on temporary rows + if (elem.getElementsByClassName('toggl-wrapper').length > 0) return; + + // fetch the row data + const row = { + object_id: elem.getAttribute('data-object-id'), + id: elem.getAttribute('data-row-id'), + cells: Array.from(elem.childNodes).map(cell => { + const id = cell.getAttribute('data-column-id'); + const columnSelector = 'div[data-column-id=' + id + ']'; + const column = document.querySelector(columnSelector); + + return { + id, + cell, + column, + title: column && column.textContent, + text: cell.textContent + }; + }) + }; + + // look for features of a task + const task = row.cells.findIndex(cell => cell.title === 'Task'); + const project = row.cells.findIndex(cell => cell.title === 'Project'); + const isTask = task > 0; + + // ignore anything thats not a task + if (!isTask) return; + + // build the button + const link = togglbutton.createTimerLink( + Object.assign( + { + className: 'coda', + buttonType: 'minimal', + description: row.cells[task].text + ' -- ' + row.cells[task].id + }, + project > 0 && { + projectName: row.cells[project].text + } + ) + ); + + // style it for coda + const wrapper = document.createElement('div'); + wrapper.className = 'toggl-wrapper'; + wrapper.style.display = 'flex'; + wrapper.style.alignItems = 'center'; + wrapper.style.justifyContent = 'center'; + wrapper.appendChild(link); + + // add it to the end of the task + elem.appendChild(wrapper); +}); diff --git a/src/scripts/origins.js b/src/scripts/origins.js index 0a9d2a8c1..e1cf77d7f 100644 --- a/src/scripts/origins.js +++ b/src/scripts/origins.js @@ -94,6 +94,10 @@ export default { url: '*://app.clubhouse.io/*', name: 'Clubhouse' }, + 'coda.io': { + url: '*://coda.io/d/*', + name: 'Coda' + }, 'codeable.io': { url: '*://app.codeable.io/*', name: 'Codeable'