-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblitzbutton.js
33 lines (27 loc) · 1.1 KB
/
blitzbutton.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const [ owner, repository ] = location.href
.replace(/^(.+):\/\/github\.com\/([^\/]+)\/([^\/]+)\/?(.*)?$/, '$2 $3')
.split(' ');
fetch(`https://api.github.com/repos/${owner}/${repository}/contents/.angular-cli.json`)
.then(response => {
if (response.status !== 200) {
return;
}
const actions = document.querySelector('.pagehead-actions');
const newElement = document.createElement('li');
const newButton = document.createElement('a');
const newIcon = document.createElement('img');
const newSpan = document.createElement('span');
newSpan.textContent = 'StackBlitz';
newIcon.src = browser.extension.getURL('lightning.svg');
newIcon.style.width = '1.3em';
newButton.classList.add('btn', 'btn-sm');
newButton.href = `https://stackblitz.com/github/${owner}/${repository}`;
newButton.target = '_blank';
newButton.style.display = 'flex';
newButton.style.alignContent = 'center';
newButton.appendChild(newIcon);
newButton.appendChild(newSpan);
newElement.appendChild(newButton);
actions.appendChild(newElement);
})
.catch(console.error);