From b7fdcb1bb598e76b5ac7407d9c48689f69ddda91 Mon Sep 17 00:00:00 2001 From: expelledboy Anthony Jackson Date: Wed, 3 Jun 2020 13:19:35 +0200 Subject: [PATCH 1/4] feat: Add coda.io support to rows labelled as 'Task' --- src/scripts/content/coda.js | 53 +++++++++++++++++++++++++++++++++++++ src/scripts/origins.js | 4 +++ 2 files changed, 57 insertions(+) create mode 100644 src/scripts/content/coda.js diff --git a/src/scripts/content/coda.js b/src/scripts/content/coda.js new file mode 100644 index 000000000..3bc39a8b6 --- /dev/null +++ b/src/scripts/content/coda.js @@ -0,0 +1,53 @@ +'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({ + className: 'coda', + buttonType: 'minimal', + projectName: row.cells[project].text, + description: row.cells[task].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); + + // insert it just before the task description + elem.insertBefore(wrapper, row.cells[task].cell); +}); 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' From f47f5ad953193371787b9dc882d1ea4a14c5b86e Mon Sep 17 00:00:00 2001 From: expelledboy Anthony Jackson Date: Wed, 3 Jun 2020 13:34:34 +0200 Subject: [PATCH 2/4] feat: optional project name from "Project" cell --- src/scripts/content/coda.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/scripts/content/coda.js b/src/scripts/content/coda.js index 3bc39a8b6..adcbf2d14 100644 --- a/src/scripts/content/coda.js +++ b/src/scripts/content/coda.js @@ -33,12 +33,18 @@ togglbutton.render('.kr-row:not(.toggl)', { observe: true }, function (elem) { if (!isTask) return; // build the button - const link = togglbutton.createTimerLink({ - className: 'coda', - buttonType: 'minimal', - projectName: row.cells[project].text, - description: row.cells[task].text - }); + const link = togglbutton.createTimerLink( + Object.assign( + { + className: 'coda', + buttonType: 'minimal', + description: row.cells[task].text + }, + project > 0 && { + projectName: row.cells[project].text + } + ) + ); // style it for coda const wrapper = document.createElement('div'); @@ -48,6 +54,6 @@ togglbutton.render('.kr-row:not(.toggl)', { observe: true }, function (elem) { wrapper.style.justifyContent = 'center'; wrapper.appendChild(link); - // insert it just before the task description - elem.insertBefore(wrapper, row.cells[task].cell); + // add it to the end of the task + elem.appendChild(wrapper); }); From 91d25b3cef49445bf2e8ff55d21207055d86b66a Mon Sep 17 00:00:00 2001 From: expelledboy Anthony Jackson Date: Wed, 3 Jun 2020 22:37:13 +0200 Subject: [PATCH 3/4] fix: add unique reference for future two way sync --- src/scripts/content/coda.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/content/coda.js b/src/scripts/content/coda.js index adcbf2d14..d09151399 100644 --- a/src/scripts/content/coda.js +++ b/src/scripts/content/coda.js @@ -38,7 +38,7 @@ togglbutton.render('.kr-row:not(.toggl)', { observe: true }, function (elem) { { className: 'coda', buttonType: 'minimal', - description: row.cells[task].text + description: row.cells[task].text + ' - #' + row.cells[task].id }, project > 0 && { projectName: row.cells[project].text From 315b9314e992e9def52aecf2e6178afcfeaac971 Mon Sep 17 00:00:00 2001 From: expelledboy Anthony Jackson Date: Fri, 5 Jun 2020 11:57:19 +0200 Subject: [PATCH 4/4] fix: task ids can have the # symbol, remove from unique task ref --- src/scripts/content/coda.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/content/coda.js b/src/scripts/content/coda.js index d09151399..5faf14033 100644 --- a/src/scripts/content/coda.js +++ b/src/scripts/content/coda.js @@ -38,7 +38,7 @@ togglbutton.render('.kr-row:not(.toggl)', { observe: true }, function (elem) { { className: 'coda', buttonType: 'minimal', - description: row.cells[task].text + ' - #' + row.cells[task].id + description: row.cells[task].text + ' -- ' + row.cells[task].id }, project > 0 && { projectName: row.cells[project].text