Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need for external libraries. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Activate plugin on every tab update
chrome.tabs.onUpdated.addListener(() => {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
chrome.tabs.executeScript(
tabs[0].id,
{ file: 'content.js' });
});
})
tabs[0].id, {
file: 'content.js'
});
});
})
128 changes: 69 additions & 59 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,97 @@
(function(){
(function () {
// If on someone's Github profile
const activityContainer = document.querySelector('.graph-before-activity-overview')
if(activityContainer)
initColorize()
const activityContainer = document.querySelector('.graph-before-activity-overview');
if (activityContainer) {
initColorize();
}
})()

function initColorize()
{
chrome.storage.local.get('color', function(data) {
if(!data.color)
data.color = '4594A8'
let mainColorHex = `#${data.color}`

const legendItems = document.querySelectorAll('.contrib-legend ul li')
const originalColors = []
for(let li of legendItems)
originalColors.push(li.getAttribute('style').split(':')[1].trim())

colorizeActivity(mainColorHex)
colorizeLegend(mainColorHex, originalColors, legendItems)
colorizeDays(mainColorHex, originalColors)
});
function initColorize() {
chrome.storage.local.get('color', function (data) {
if (!data.color) {
data.color = '#4594A8';
}

let mainColorHex = data.color;

const legendItems = document.querySelectorAll('.contrib-legend ul li');
const originalColors = [];

for (let li of legendItems) {
originalColors.push(li.getAttribute('style').split(':')[1].trim());
}

colorizeActivity(mainColorHex);
colorizeLegend(mainColorHex, originalColors, legendItems);
colorizeDays(mainColorHex, originalColors);
})
}

function colorizeActivity(color)
{
const activity = document.querySelector('.js-highlight-blob')
if(activity)
{
const axes = document.querySelectorAll('.activity-overview-axis')
const ellipses = document.querySelectorAll('.activity-overview-point')
const blob = document.querySelector('.js-highlight-blob')
activity.setAttribute('stroke', color)
blob.style.fill = color
for(let ellipse of ellipses)
ellipse.style.stroke = color
for(let axis of axes)
axis.style.stroke = color
function colorizeActivity(color) {
const activity = document.querySelector('.js-highlight-blob');
if (!activity) {
return;
}
const axes = document.querySelectorAll('.activity-overview-axis');
const ellipses = document.querySelectorAll('.activity-overview-point');
const blob = document.querySelector('.js-highlight-blob');

activity.setAttribute('stroke', color);
blob.style.fill = color;

for (let ellipse of ellipses) {
ellipse.style.stroke = color;
}

for (let axis of axes) {
axis.style.stroke = color;
}

}

function colorizeLegend(mainColor, originalColors, legendItems)
{
legendItems[0].setAttribute('style', `background-color:${originalColors[0]}`)
legendItems[1].setAttribute('style', `background-color:${colorLuminance(mainColor, 0.9)}`)
legendItems[2].setAttribute('style', `background-color:${colorLuminance(mainColor, 0.75)}`)
legendItems[3].setAttribute('style', `background-color:${colorLuminance(mainColor, 0.5)}`)
legendItems[4].setAttribute('style', `background-color:${mainColor}`)
function colorizeLegend(mainColor, originalColors, legendItems) {
legendItems[0].setAttribute('style', `background-color:${originalColors[0]}`);
legendItems[1].setAttribute('style', `background-color:${colorLuminance(mainColor, 0.9)}`);
legendItems[2].setAttribute('style', `background-color:${colorLuminance(mainColor, 0.75)}`);
legendItems[3].setAttribute('style', `background-color:${colorLuminance(mainColor, 0.5)}`);
legendItems[4].setAttribute('style', `background-color:${mainColor}`);
}

function colorizeDays(mainColor, originalColors)
{
let days = Array.from(document.getElementsByClassName('day'))
function colorizeDays(mainColor, originalColors) {
let days = Array.from(document.getElementsByClassName('day'));

const dayGroups = {
0: days.filter( day => day.getAttribute('fill') == originalColors[0]),
1: days.filter( day => day.getAttribute('fill') == originalColors[1]),
2: days.filter( day => day.getAttribute('fill') == originalColors[2]),
3: days.filter( day => day.getAttribute('fill') == originalColors[3]),
4: days.filter( day => day.getAttribute('fill') == originalColors[4])
0: days.filter(day => day.getAttribute('fill') == originalColors[0]),
1: days.filter(day => day.getAttribute('fill') == originalColors[1]),
2: days.filter(day => day.getAttribute('fill') == originalColors[2]),
3: days.filter(day => day.getAttribute('fill') == originalColors[3]),
4: days.filter(day => day.getAttribute('fill') == originalColors[4]),
}

dayGroups[0].forEach(day => day.setAttribute('fill', originalColors[0]))
dayGroups[1].forEach(day => day.setAttribute('fill', colorLuminance(mainColor, 0.9)))
dayGroups[2].forEach(day => day.setAttribute('fill', colorLuminance(mainColor, 0.75)))
dayGroups[3].forEach(day => day.setAttribute('fill', colorLuminance(mainColor, 0.5)))
dayGroups[4].forEach(day => day.setAttribute('fill', mainColor))
dayGroups[0].forEach(day => day.setAttribute('fill', originalColors[0]));
dayGroups[1].forEach(day => day.setAttribute('fill', colorLuminance(mainColor, 0.9)));
dayGroups[2].forEach(day => day.setAttribute('fill', colorLuminance(mainColor, 0.75)));
dayGroups[3].forEach(day => day.setAttribute('fill', colorLuminance(mainColor, 0.5)));
dayGroups[4].forEach(day => day.setAttribute('fill', mainColor));
}

function colorLuminance(hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
lum = lum || 0;

// convert to decimal and change luminosity
let rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
let rgb = "#";
let c;

for (let i = 0; i < 3; i++) {
c = parseInt(hex.substr(i * 2, 2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
rgb += ("00" + c).substr(c.length);
}

return rgb;
}
2 changes: 0 additions & 2 deletions jquery.js

This file was deleted.

Loading