From f5145fdbf89acb2f19531c1ac277d5e35266be9a Mon Sep 17 00:00:00 2001 From: Wendelin Keimel Date: Mon, 24 Jan 2022 16:33:45 +0100 Subject: [PATCH 1/8] add button --- content_script.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content_script.js b/content_script.js index dfe2f88..801e4b6 100644 --- a/content_script.js +++ b/content_script.js @@ -1 +1,3 @@ -//TODO: Code, der auf trello.com ausgeführt wird \ No newline at end of file +const sidebar = document.getElementsByClassName("window-sidebar")[0] +sidebar.innerHTML = "+Toggl Task" + sidebar.innerHTML +sidebar.getElementsByClassName("mod-no-top-margin")[1].classList.remove("mod-no-top-margin") \ No newline at end of file From 21ac52e8bf9cb907edde3ed974db37afcb6fd850 Mon Sep 17 00:00:00 2001 From: Wendelin Keimel Date: Mon, 24 Jan 2022 16:43:48 +0100 Subject: [PATCH 2/8] add button event handler --- content_script.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/content_script.js b/content_script.js index 801e4b6..20cba51 100644 --- a/content_script.js +++ b/content_script.js @@ -1,3 +1,10 @@ const sidebar = document.getElementsByClassName("window-sidebar")[0] -sidebar.innerHTML = "+Toggl Task" + sidebar.innerHTML -sidebar.getElementsByClassName("mod-no-top-margin")[1].classList.remove("mod-no-top-margin") \ No newline at end of file +sidebar.innerHTML = "+Toggl Task" + sidebar.innerHTML + +sidebar.getElementsByClassName("mod-no-top-margin")[1].classList.remove("mod-no-top-margin") + +document.getElementById("togglbtn").addEventListener("click", onClick) + +function onClick(){ + alert("work in progress ;)") +} \ No newline at end of file From 424b073b04ffda5f3f32f8cfd9aa27f78c99db6a Mon Sep 17 00:00:00 2001 From: Wendelin Keimel Date: Tue, 25 Jan 2022 09:38:12 +0100 Subject: [PATCH 3/8] add onload event handler --- content_script.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/content_script.js b/content_script.js index 20cba51..53a8cb7 100644 --- a/content_script.js +++ b/content_script.js @@ -1,10 +1,15 @@ const sidebar = document.getElementsByClassName("window-sidebar")[0] -sidebar.innerHTML = "+Toggl Task" + sidebar.innerHTML -sidebar.getElementsByClassName("mod-no-top-margin")[1].classList.remove("mod-no-top-margin") - -document.getElementById("togglbtn").addEventListener("click", onClick) +function addButton(){ + sidebar.innerHTML = "+Toggl Task" + sidebar.innerHTML + sidebar.getElementsByClassName("mod-no-top-margin")[1].classList.remove("mod-no-top-margin") + document.getElementById("togglbtn").addEventListener("click", onClick) +} function onClick(){ alert("work in progress ;)") -} \ No newline at end of file +} + +addButton() + +document.getElementById("board").addEventListener("click", addButton) \ No newline at end of file From b29b1232cc92db888a2524afd073344a68429830 Mon Sep 17 00:00:00 2001 From: Wendelin Keimel Date: Tue, 25 Jan 2022 09:58:44 +0100 Subject: [PATCH 4/8] fix button disappearing --- content_script.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/content_script.js b/content_script.js index 53a8cb7..0b2a861 100644 --- a/content_script.js +++ b/content_script.js @@ -1,6 +1,5 @@ -const sidebar = document.getElementsByClassName("window-sidebar")[0] - function addButton(){ + const sidebar = document.getElementsByClassName("window-sidebar")[0] sidebar.innerHTML = "+Toggl Task" + sidebar.innerHTML sidebar.getElementsByClassName("mod-no-top-margin")[1].classList.remove("mod-no-top-margin") document.getElementById("togglbtn").addEventListener("click", onClick) @@ -10,6 +9,9 @@ function onClick(){ alert("work in progress ;)") } -addButton() - -document.getElementById("board").addEventListener("click", addButton) \ No newline at end of file +window.addEventListener("pushstate", function(){ + if(window.location.pathname.startsWith("/c/")){ + addButton() + console.log("JUHUUU") + } +}) \ No newline at end of file From bdc1c077bcd935907f93cae045fd77dd23f6dc5c Mon Sep 17 00:00:00 2001 From: Wendelin Keimel Date: Tue, 25 Jan 2022 11:05:47 +0100 Subject: [PATCH 5/8] use querySelector and querySelectorAll --- content_script.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/content_script.js b/content_script.js index 0b2a861..728fa4d 100644 --- a/content_script.js +++ b/content_script.js @@ -1,8 +1,8 @@ function addButton(){ - const sidebar = document.getElementsByClassName("window-sidebar")[0] + const sidebar = document.querySelector(".window-sidebar") sidebar.innerHTML = "+Toggl Task" + sidebar.innerHTML - sidebar.getElementsByClassName("mod-no-top-margin")[1].classList.remove("mod-no-top-margin") - document.getElementById("togglbtn").addEventListener("click", onClick) + sidebar.querySelectorAll(".mod-no-top-margin")[1].classList.remove("mod-no-top-margin") + document.querySelector("#togglbtn").addEventListener("click", onClick) } function onClick(){ @@ -12,6 +12,5 @@ function onClick(){ window.addEventListener("pushstate", function(){ if(window.location.pathname.startsWith("/c/")){ addButton() - console.log("JUHUUU") } }) \ No newline at end of file From 8ee007854175afee02c1ef0923525caa45adb44b Mon Sep 17 00:00:00 2001 From: WendelinPraktikum <98315207+WendelinPraktikum@users.noreply.github.com> Date: Tue, 25 Jan 2022 12:52:48 +0100 Subject: [PATCH 6/8] use createElement instead of innerHTML --- content_script.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/content_script.js b/content_script.js index 728fa4d..37a3b78 100644 --- a/content_script.js +++ b/content_script.js @@ -1,6 +1,19 @@ function addButton(){ const sidebar = document.querySelector(".window-sidebar") - sidebar.innerHTML = "+Toggl Task" + sidebar.innerHTML + const button = document.createElement('span'); + button.classList.add('button-link'); + button.addEventListener('click', onClick); + sidebar.prepend(button); + + const buttonIcon = document.createElement('span'); + buttonIcon.classList.add('icon-sm', 'plugin-icon'); + buttonIcon.innerText = '+'; + button.append(buttonIcon); + + const buttonText = document.createElement('span'); + buttonText.innerText = 'Toggl Task'; + button.append(buttonText); + sidebar.querySelectorAll(".mod-no-top-margin")[1].classList.remove("mod-no-top-margin") document.querySelector("#togglbtn").addEventListener("click", onClick) } @@ -13,4 +26,4 @@ window.addEventListener("pushstate", function(){ if(window.location.pathname.startsWith("/c/")){ addButton() } -}) \ No newline at end of file +}) From 714d15bf61524bd68d32ef7c1f10ceb641c36214 Mon Sep 17 00:00:00 2001 From: WendelinPraktikum <98315207+WendelinPraktikum@users.noreply.github.com> Date: Tue, 25 Jan 2022 13:01:24 +0100 Subject: [PATCH 7/8] remove duplicate code --- content_script.js | 1 - 1 file changed, 1 deletion(-) diff --git a/content_script.js b/content_script.js index 37a3b78..a241b6f 100644 --- a/content_script.js +++ b/content_script.js @@ -15,7 +15,6 @@ function addButton(){ button.append(buttonText); sidebar.querySelectorAll(".mod-no-top-margin")[1].classList.remove("mod-no-top-margin") - document.querySelector("#togglbtn").addEventListener("click", onClick) } function onClick(){ From 879e0b3f2bddf2572b525d66b5986d584a63acc8 Mon Sep 17 00:00:00 2001 From: WendelinPraktikum <98315207+WendelinPraktikum@users.noreply.github.com> Date: Tue, 25 Jan 2022 13:32:06 +0100 Subject: [PATCH 8/8] fix margin of 'add to card' heading --- content_script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content_script.js b/content_script.js index a241b6f..dfe5d44 100644 --- a/content_script.js +++ b/content_script.js @@ -14,7 +14,7 @@ function addButton(){ buttonText.innerText = 'Toggl Task'; button.append(buttonText); - sidebar.querySelectorAll(".mod-no-top-margin")[1].classList.remove("mod-no-top-margin") + sidebar.querySelector(".js-sidebar-add-heading").classList.remove("mod-no-top-margin") } function onClick(){