From 685d3eba55e0334d2c4702abd6b1ecf062afed7e Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Tue, 16 Jan 2018 00:20:28 +0100 Subject: [PATCH] Initial commit --- manifest.json | 14 ++++++++++++++ project.css | 20 ++++++++++++++++++++ project.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100755 manifest.json create mode 100755 project.css create mode 100755 project.js diff --git a/manifest.json b/manifest.json new file mode 100755 index 0000000..907c067 --- /dev/null +++ b/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Pivotal Improvements", + "version": "1.0.2", + + "content_scripts": + [ + { + "matches": ["*://*.pivotaltracker.com/n/projects/*"], + "js": ["project.js"], + "css": ["project.css"] + } + ] +} diff --git a/project.css b/project.css new file mode 100755 index 0000000..1a1d301 --- /dev/null +++ b/project.css @@ -0,0 +1,20 @@ +.story.owned > .preview { + font-weight: bold; +} + +.story > .preview { + transition: background-color 0.2s; +} + +.story.highlighted.planned > .preview { + background-color: #dfdfdf; +} + +.story.highlighted.started > .preview, +.story.highlighted.finished > .preview { + background-color: #e3e3c1; +} + +.story.highlighted.accepted > .preview { + background-color: #cadbbf; +} diff --git a/project.js b/project.js new file mode 100755 index 0000000..e34213e --- /dev/null +++ b/project.js @@ -0,0 +1,49 @@ +const root = document.querySelector('#root'); + +let fullName = ''; + + +function updateFullName() { + const avatar = document.querySelector('[data-aid="Avatar__image"]'); + if (avatar) + fullName = avatar.getAttribute('alt'); +} + + +function setClassOnStoriesWithOwner(name, className) { + const owners = document.querySelectorAll('.owner'); + for (const owner of owners) { + const story = owner.parentElement.parentElement.parentElement.parentElement; + + if (owner.getAttribute('title') === name) + story.classList.add(className); + else + story.classList.remove(className); + } +} + + +function callback() { + if (!fullName) { + // Grab the full name from the avatar alt-text. + updateFullName(); + } + + setClassOnStoriesWithOwner(fullName, 'owned'); +} + +root.addEventListener('mouseover', event => { + if (event.target.className === 'owner') { + const name = event.target.getAttribute('title'); + setClassOnStoriesWithOwner(name, 'highlighted'); + } +}); + +root.addEventListener('mouseout', event => { + if (event.target.className === 'owner') + setClassOnStoriesWithOwner('', 'highlighted'); +}); + +const observer = new MutationObserver(callback); +const config = { childList: true, subtree: true }; +observer.observe(root, config);