Skip to content

Commit

Permalink
feat(github): Adds toggl-button to new project pane (#2099)
Browse files Browse the repository at this point in the history
* feat(github): Adds toggl-button to new project pane

Closes #2090

* Update origins.js

Co-authored-by: Alisson Oliveira Souza <[email protected]>
  • Loading branch information
Alissonsz and Alisson Oliveira Souza authored Jun 27, 2022
1 parent bc481df commit 42c5ca4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
50 changes: 50 additions & 0 deletions src/content/github.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
/**
* @name Github
* @urlAlias github.com
* @urlRegex *://github.com/*
*/
'use strict';

// We need it to get the issue name, the tag value is being changed dynamically
const getPaneTitle = async (elem) => {
return new Promise(resolve => {
const title = setInterval(() => {
const titleElem = elem.querySelector('#__primerPortalRoot__ header h2 span')
if (!!titleElem.textContent) {
clearInterval(title)
resolve(titleElem.textContent)
}
}, 100)
})
}

// Issue and Pull Request Page
togglbutton.render('#partial-discussion-sidebar', { observe: true }, function (
elem
Expand Down Expand Up @@ -38,6 +56,38 @@ togglbutton.render('#partial-discussion-sidebar', { observe: true }, function (
elem.prepend(div);
});

// Project Page side pane
togglbutton.render('div[role="dialog"]:not(.toggl)', { observe: true }, async function (
elem
) {
const numElem = elem.querySelector('#__primerPortalRoot__ header a')
const projectElem = document.querySelector('#memexTitleInput')

const parent = document.querySelector('dl')
const title = await getPaneTitle(elem)

let description = title;
if (numElem !== null) {
description = numElem.textContent + ' ' + description.trim();
}

const div = document.createElement('div');
div.classList = parent.children[0].classList.value;
div.style.paddingLeft = '16px'

let projectName = ''
if (projectElem) projectName = projectElem.value

const link = togglbutton.createTimerLink({
className: 'github',
description: description,
projectName: projectName
});

div.appendChild(link);
parent.prepend(div)
});

// Project Page
togglbutton.render('.js-project-card-details .js-comment:not(.toggl)', { observe: true }, function (
elem
Expand Down
3 changes: 2 additions & 1 deletion src/origins.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ export default {
},
'github.com': {
url: '*://github.com/*',
name: 'Github'
name: 'Github',
file: 'github.js'
},
'gitlab.com': {
url: '*://*.gitlab.com/*',
Expand Down

0 comments on commit 42c5ca4

Please sign in to comment.