From 4886cce11fe28a5c920bc095f69bdc7fe9e3f51e Mon Sep 17 00:00:00 2001 From: joelazwar Date: Mon, 19 Oct 2020 21:54:57 +0700 Subject: [PATCH 1/7] added github js and css template --- css/templates/github.css | 95 ++++++++++++++++++++++++++++ js/core.js | 2 + js/templates/github.js | 130 +++++++++++++++++++++++++++++++++++++++ manifest.json | 4 +- 4 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 css/templates/github.css create mode 100644 js/templates/github.js diff --git a/css/templates/github.css b/css/templates/github.css new file mode 100644 index 0000000..feb3a63 --- /dev/null +++ b/css/templates/github.css @@ -0,0 +1,95 @@ +.survol-github-container { + border: 1px solid #e1e4e8; + padding: 15px; + border-radius: 5px; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, + sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; + width: auto; + height: auto; +} + +.survol-github-container > #survol-github-profile { + position: relative; +} + +.survol-github-container > #survol-github-profile > #survol-github-avatar{ + user-select: none; + display: inline-block; + vertical-align: top; + width: 80px; + border-radius: 5px; +} + +.survol-github-container > #survol-github-profile > #survol-github-user-info { + width: auto; + max-width:300; + display: inline-block; + overflow: auto; + margin-left: 10px; + display: block; + text-decoration: inherit; + color: inherit; + } + + .survol-github-container > #survol-github-profile > #survol-github-user-info > .survol-github-name { + font-weight: 600; + font-size: 20px; + } + + .survol-github-container > #survol-github-profile > #survol-github-user-info > .survol-github-at { + display: block; + font-size: 16px; + color: #666; + font-style: normal; + font-weight: 400; + margin-bottom: 5px; + } + + .survol-github-container > #survol-github-profile > #survol-github-user-info > .survol-github-bio { + font-size: 13px; + color: #6a737d; + } + + .survol-github-container > #survol-github-profile > .survol-github-profile-stats { + display: block; + margin-top: 8px; + } + + .survol-github-container > #survol-github-profile >.survol-github-profile-stats > .survol-github-profile-stat { + text-decoration: none; + width: 70px; + border-right: 1px solid #eaecef; + color: #586069; + display: inline-block; + padding: 0 6px; + margin-top: 5px; + } + + .survol-github-container > #survol-github-profile > .survol-github-profile-stats >.survol-github-profile-stat:last-of-type { + border-right: none; + } + + + .survol-github-container > #survol-github-profile > .survol-github-profile-stats >.survol-github-profile-stat >.survol-github-prof-stat-val { + color: #586069; + font-size: 19px; + text-align: center; + display: block; + } + .survol-github-container > #survol-github-profile > .survol-github-profile-stats >.survol-github-profile-stat >.survol-github-prof-stat-name { + color: #7b828a; + font-size: 11px; + text-align: center; + display: block; + } + + .survol-github-container > #survol-github-profile >.survol-github-profile-stats > .survol-github-links{ + display: inline-block; + } + + .survol-github-container > #survol-github-profile >.survol-github-profile-stats > .survol-github-links > .survol-github-link{ + display: block; + position: relative; + font-size: 15; + font-weight : 100; +} \ No newline at end of file diff --git a/js/core.js b/js/core.js index 5ab240b..a842654 100644 --- a/js/core.js +++ b/js/core.js @@ -161,6 +161,8 @@ document.addEventListener('DOMContentLoaded', () => { return new StackExchangeHover(node, getDomain(CURRENT_TAB)); case 'soundcloud.com': return new SoundCloudHover(node, getDomain(CURRENT_TAB)); + case 'github.com': + return new GitHubHover(node, getDomain(CURRENT_TAB)); // If the site has no custom template, it should be previewed using meta-data parsing default: diff --git a/js/templates/github.js b/js/templates/github.js new file mode 100644 index 0000000..29e7c95 --- /dev/null +++ b/js/templates/github.js @@ -0,0 +1,130 @@ +/* Hover classes bound themselves to a node + */ +class GitHubHover { + constructor(node, CURRENT_TAB) { + this.boundNode = node; + this.redirectLink = node.href; + this.CURRENT_TAB = CURRENT_TAB; + this.linkType = this.checkLinkType(); + this.parser = new DOMParser(); + } + + checkLinkType() { + if (this.CURRENT_TAB == 'github.com' || this.redirectLink.match(/(github.com)\/[\w]{1,256}\/[\w]{1,256}\/[\w]/g)) return 'unknown'; + else if (this.redirectLink.match(/(github.com)\/[\w]{1,256}\/[\w]{1,256}/g)) return 'repo'; + else return 'profile'; + } + + /* bindToContainer + * Parameters : + * node - {HTMLNodeElement} - An anchor link element + * domain - {String} - The domain of the current webpage + * container - {HTMLNodeElement} - The survol container + * + * This function is called to get the data from the link we + * want to preview and then attach it to the container + * Note: data is always inserted into textNodes to avoid + * malicious script injections. + */ + bindToContainer(node, domain, container) { + if (this.linkType == 'profile') { + + const username = this.redirectLink.split('github.com/')[1]; + + window + .survolBackgroundRequest(`https://api.github.com/users/${username}`) + .then(({ data }) => { + + let githubContainer = document.createElement('div'); + githubContainer.className = 'survol-github-container'; + + let githubProfileContainer = document.createElement('div'); + githubProfileContainer.id = 'survol-github-profile'; + + let profilePic = document.createElement('img'); + profilePic.id = 'survol-github-avatar'; + profilePic.src = data.avatar_url; + profilePic.style.width = '80px'; + githubProfileContainer.appendChild(profilePic); + + let profInfo = document.createElement('div'); + profInfo.id = 'survol-github-user-info'; + + profInfo.style = 'display: inline-block'; + + let name = document.createElement('span'); + name.className = 'survol-github-name'; + name.appendChild(document.createTextNode(data.name)); + + let githubAt = document.createElement('span'); + githubAt.className = 'survol-github-at'; + githubAt.appendChild(document.createTextNode(` @${data.login}`)); + + let bio = document.createElement('span'); + bio.className = 'survol-github-bio'; + bio.appendChild(document.createTextNode(data.bio)); + + profInfo.appendChild(name); + profInfo.appendChild(githubAt); + profInfo.appendChild(bio); + + githubProfileContainer.appendChild(profInfo); + + let profStats = document.createElement('div'); + profStats.className = "survol-github-profile-stats"; + + let statdata = [{'name' : 'Repos', 'stat': data.public_repos}, + {'name' : 'Followers', 'stat': data.followers}, + {'name' : 'Following', 'stat': data.following}]; + + statdata.forEach((x)=>{ + let stat = document.createElement('a'); + stat.className = 'survol-github-profile-stat'; + + let statNumber = document.createElement('b'); + statNumber.className = 'survol-github-prof-stat-val'; + statNumber.appendChild(document.createTextNode(x.stat)); + let statName = document.createElement('span'); + statName.className = 'survol-github-prof-stat-name'; + statName.appendChild(document.createTextNode(x.name)); + + stat.appendChild(statNumber); + stat.appendChild(statName); + + profStats.appendChild(stat); + }); + + let githubLinksContainer = document.createElement('div'); + githubLinksContainer.className = 'survol-github-links'; + + let links = [data.company? '🗄️ ' + data.company : '🗄️ not available', + data.twitter_username ? '🐦 @' + data.twitter_username : '🐦 not available', + data.blog? '🌐 ' + data.blog : '🌐 not available']; + + links.forEach((link)=>{ + let linkContainer = document.createElement('span'); + linkContainer.className = 'survol-github-link'; + linkContainer.appendChild(document.createTextNode(link)); + + if (link.includes('not available')) + linkContainer.style.color= '#586069'; + + githubLinksContainer.appendChild(linkContainer); + }) + + profStats.appendChild(githubLinksContainer); + + githubProfileContainer.appendChild(profStats); + + githubContainer.appendChild(githubProfileContainer); + + + if (window.lastHovered == node && container.innerHTML == '') { + container.appendChild(githubContainer); + } + }) + .catch(console.error); + + } + } +} \ No newline at end of file diff --git a/manifest.json b/manifest.json index e139ee0..e73a46d 100644 --- a/manifest.json +++ b/manifest.json @@ -33,6 +33,7 @@ "js/templates/youtube.js", "js/templates/stackexchange.js", "js/templates/soundcloud.js", + "js/templates/github.js", "js/core.js" ], @@ -43,7 +44,8 @@ "css/templates/twitter.css", "css/templates/youtube.css", "css/templates/stackexchange.css", - "css/templates/soundcloud.css" + "css/templates/soundcloud.css", + "css/templates/github.css" ], "run_at": "document_start" From 2956dd8d36b05227bdf153ed301b44782fb7a9d9 Mon Sep 17 00:00:00 2001 From: joelazwar Date: Tue, 20 Oct 2020 09:43:58 +0700 Subject: [PATCH 2/7] fixed styling issue and no bio logic --- css/templates/github.css | 50 +++++++++++++++++++++++++--------------- js/templates/github.js | 5 ++-- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/css/templates/github.css b/css/templates/github.css index feb3a63..1e6b931 100644 --- a/css/templates/github.css +++ b/css/templates/github.css @@ -8,35 +8,36 @@ height: auto; } -.survol-github-container > #survol-github-profile { +#survol-github-profile { position: relative; } -.survol-github-container > #survol-github-profile > #survol-github-avatar{ +#survol-github-avatar{ user-select: none; display: inline-block; vertical-align: top; width: 80px; border-radius: 5px; + margin-right: 10px; + margin-top: 5px; } -.survol-github-container > #survol-github-profile > #survol-github-user-info { +#survol-github-user-info { width: auto; - max-width:300; + max-width : 350px; display: inline-block; overflow: auto; - margin-left: 10px; display: block; text-decoration: inherit; color: inherit; } - .survol-github-container > #survol-github-profile > #survol-github-user-info > .survol-github-name { + .survol-github-name { font-weight: 600; font-size: 20px; } - .survol-github-container > #survol-github-profile > #survol-github-user-info > .survol-github-at { + .survol-github-at { display: block; font-size: 16px; color: #666; @@ -44,18 +45,27 @@ font-weight: 400; margin-bottom: 5px; } + + .dark-theme .survol-github-at { + color: #aab3be; + } - .survol-github-container > #survol-github-profile > #survol-github-user-info > .survol-github-bio { + .survol-github-bio { font-size: 13px; color: #6a737d; } - - .survol-github-container > #survol-github-profile > .survol-github-profile-stats { + + .dark-theme .survol-github-bio { + color: #aab3be; + } + +.survol-github-profile-stats { display: block; margin-top: 8px; + max-width : 500px; } - .survol-github-container > #survol-github-profile >.survol-github-profile-stats > .survol-github-profile-stat { + .survol-github-profile-stat { text-decoration: none; width: 70px; border-right: 1px solid #eaecef; @@ -63,31 +73,35 @@ display: inline-block; padding: 0 6px; margin-top: 5px; + margin-bottom: 8px; + } + + .dark-theme .survol-github-profile-stat span, .dark-theme .survol-github-profile-stat b { + color: #eaecef; } + - .survol-github-container > #survol-github-profile > .survol-github-profile-stats >.survol-github-profile-stat:last-of-type { + .survol-github-profile-stat:last-of-type { border-right: none; } - .survol-github-container > #survol-github-profile > .survol-github-profile-stats >.survol-github-profile-stat >.survol-github-prof-stat-val { - color: #586069; + .survol-github-prof-stat-val { font-size: 19px; text-align: center; display: block; } - .survol-github-container > #survol-github-profile > .survol-github-profile-stats >.survol-github-profile-stat >.survol-github-prof-stat-name { - color: #7b828a; + .survol-github-prof-stat-name { font-size: 11px; text-align: center; display: block; } - .survol-github-container > #survol-github-profile >.survol-github-profile-stats > .survol-github-links{ + .survol-github-links{ display: inline-block; } - .survol-github-container > #survol-github-profile >.survol-github-profile-stats > .survol-github-links > .survol-github-link{ + .survol-github-link{ display: block; position: relative; font-size: 15; diff --git a/js/templates/github.js b/js/templates/github.js index 29e7c95..083f978 100644 --- a/js/templates/github.js +++ b/js/templates/github.js @@ -61,8 +61,8 @@ class GitHubHover { githubAt.appendChild(document.createTextNode(` @${data.login}`)); let bio = document.createElement('span'); - bio.className = 'survol-github-bio'; - bio.appendChild(document.createTextNode(data.bio)); + bio.className = 'survol-github-bio' ; + bio.appendChild(document.createTextNode(data.bio? data.bio : '')); profInfo.appendChild(name); profInfo.appendChild(githubAt); @@ -118,7 +118,6 @@ class GitHubHover { githubContainer.appendChild(githubProfileContainer); - if (window.lastHovered == node && container.innerHTML == '') { container.appendChild(githubContainer); } From db6975ed835b4898b578c149b01a1f19f60a4939 Mon Sep 17 00:00:00 2001 From: joelazwar Date: Tue, 20 Oct 2020 11:26:33 +0700 Subject: [PATCH 3/7] cleaned up css --- css/templates/github.css | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/css/templates/github.css b/css/templates/github.css index 1e6b931..15d4d58 100644 --- a/css/templates/github.css +++ b/css/templates/github.css @@ -1,33 +1,20 @@ .survol-github-container { - border: 1px solid #e1e4e8; padding: 15px; - border-radius: 5px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; width: auto; height: auto; } -#survol-github-profile { - position: relative; -} - #survol-github-avatar{ - user-select: none; display: inline-block; vertical-align: top; - width: 80px; - border-radius: 5px; margin-right: 10px; - margin-top: 5px; } #survol-github-user-info { width: auto; max-width : 350px; - display: inline-block; - overflow: auto; - display: block; text-decoration: inherit; color: inherit; } @@ -99,11 +86,11 @@ .survol-github-links{ display: inline-block; + vertical-align: top; } .survol-github-link{ display: block; - position: relative; font-size: 15; font-weight : 100; } \ No newline at end of file From f14ef9580f07653d120c976ed8d1c58a2a682b8b Mon Sep 17 00:00:00 2001 From: joelazwar Date: Thu, 22 Oct 2020 08:38:04 +0700 Subject: [PATCH 4/7] changes as requested in #145, and polished a few styling settings --- css/templates/github.css | 22 ++++++++++++++++------ js/templates/github.js | 37 +++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/css/templates/github.css b/css/templates/github.css index 15d4d58..5a75ed6 100644 --- a/css/templates/github.css +++ b/css/templates/github.css @@ -10,11 +10,12 @@ display: inline-block; vertical-align: top; margin-right: 10px; + border-radius : 50%; } #survol-github-user-info { width: auto; - max-width : 350px; + max-width : 280px; text-decoration: inherit; color: inherit; } @@ -49,16 +50,16 @@ .survol-github-profile-stats { display: block; margin-top: 8px; - max-width : 500px; + text-align: center; + min-width:330px; } .survol-github-profile-stat { text-decoration: none; - width: 70px; + width: 30%; border-right: 1px solid #eaecef; color: #586069; display: inline-block; - padding: 0 6px; margin-top: 5px; margin-bottom: 8px; } @@ -90,7 +91,16 @@ } .survol-github-link{ - display: block; + display: inline; font-size: 15; - font-weight : 100; + font-weight : 400; +} + +.empty{ + color : rgb(197, 190, 190); + font-weight : 100; +} + +.dark-theme .empty{ + color : rgb(102, 99, 99) } \ No newline at end of file diff --git a/js/templates/github.js b/js/templates/github.js index 083f978..f3d887a 100644 --- a/js/templates/github.js +++ b/js/templates/github.js @@ -94,27 +94,40 @@ class GitHubHover { profStats.appendChild(stat); }); + + githubProfileContainer.appendChild(profStats); + let githubLinksContainer = document.createElement('div'); githubLinksContainer.className = 'survol-github-links'; - let links = [data.company? '🗄️ ' + data.company : '🗄️ not available', - data.twitter_username ? '🐦 @' + data.twitter_username : '🐦 not available', - data.blog? '🌐 ' + data.blog : '🌐 not available']; + let links = [{"name": "Company: ", "link" : data.company? data.company : 'not available'}, + {"name": "Twitter: ", "link" : data.twitter_username ? '@' + data.twitter_username : 'not available'}, + {"name": "Website: ", "link" : data.blog? data.blog : 'not available'}]; links.forEach((link)=>{ - let linkContainer = document.createElement('span'); - linkContainer.className = 'survol-github-link'; - linkContainer.appendChild(document.createTextNode(link)); + let linkContainer = document.createElement('div'); + + let linkName = document.createElement('span'); + linkName.appendChild(document.createTextNode(link.name)); + linkName.className = 'survol-github-link'; + + linkContainer.appendChild(linkName); + + let linkText = document.createElement('span'); + linkText.appendChild(document.createTextNode(link.link)); + + if (link.link.includes('not available')){ + linkText.className = 'survol-github-link empty'; + }else{ + linkText.className = 'survol-github-link'; + } + + linkContainer.appendChild(linkText); - if (link.includes('not available')) - linkContainer.style.color= '#586069'; - githubLinksContainer.appendChild(linkContainer); }) - - profStats.appendChild(githubLinksContainer); - githubProfileContainer.appendChild(profStats); + githubProfileContainer.appendChild(githubLinksContainer); githubContainer.appendChild(githubProfileContainer); From d93cc81594e5081b1696943a8b6324451bf21aa6 Mon Sep 17 00:00:00 2001 From: joelazwar Date: Thu, 22 Oct 2020 08:47:00 +0700 Subject: [PATCH 5/7] styling for unavailable links --- css/templates/github.css | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/css/templates/github.css b/css/templates/github.css index 5a75ed6..e90b73a 100644 --- a/css/templates/github.css +++ b/css/templates/github.css @@ -97,10 +97,7 @@ } .empty{ - color : rgb(197, 190, 190); + opacity : 35%; font-weight : 100; + font-style : italic; } - -.dark-theme .empty{ - color : rgb(102, 99, 99) -} \ No newline at end of file From cbb117f4b72dc7425b9643c182233e922335823b Mon Sep 17 00:00:00 2001 From: joelazwar Date: Thu, 22 Oct 2020 08:51:48 +0700 Subject: [PATCH 6/7] minor typo in a display text --- js/templates/github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/templates/github.js b/js/templates/github.js index f3d887a..a3ac83b 100644 --- a/js/templates/github.js +++ b/js/templates/github.js @@ -100,7 +100,7 @@ class GitHubHover { let githubLinksContainer = document.createElement('div'); githubLinksContainer.className = 'survol-github-links'; - let links = [{"name": "Company: ", "link" : data.company? data.company : 'not available'}, + let links = [{"name": "Workplace: ", "link" : data.company? data.company : 'not available'}, {"name": "Twitter: ", "link" : data.twitter_username ? '@' + data.twitter_username : 'not available'}, {"name": "Website: ", "link" : data.blog? data.blog : 'not available'}]; From 34dcaa01349dc8ec0cc8125263f28497608ca124 Mon Sep 17 00:00:00 2001 From: M$ <19026937+mdolr@users.noreply.github.com> Date: Fri, 23 Oct 2020 23:41:35 +0200 Subject: [PATCH 7/7] fix styling + show login when name is null + bump version number --- js/templates/github.js | 36 ++++++++++++++++++------------------ manifest.json | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/js/templates/github.js b/js/templates/github.js index a3ac83b..698d7d9 100644 --- a/js/templates/github.js +++ b/js/templates/github.js @@ -49,20 +49,20 @@ class GitHubHover { let profInfo = document.createElement('div'); profInfo.id = 'survol-github-user-info'; - + profInfo.style = 'display: inline-block'; let name = document.createElement('span'); name.className = 'survol-github-name'; - name.appendChild(document.createTextNode(data.name)); + name.appendChild(document.createTextNode(data.name || data.login)); let githubAt = document.createElement('span'); githubAt.className = 'survol-github-at'; githubAt.appendChild(document.createTextNode(` @${data.login}`)); - + let bio = document.createElement('span'); - bio.className = 'survol-github-bio' ; - bio.appendChild(document.createTextNode(data.bio? data.bio : '')); + bio.className = 'survol-github-bio'; + bio.appendChild(document.createTextNode(data.bio ? data.bio : '')); profInfo.appendChild(name); profInfo.appendChild(githubAt); @@ -71,13 +71,13 @@ class GitHubHover { githubProfileContainer.appendChild(profInfo); let profStats = document.createElement('div'); - profStats.className = "survol-github-profile-stats"; + profStats.className = 'survol-github-profile-stats'; - let statdata = [{'name' : 'Repos', 'stat': data.public_repos}, - {'name' : 'Followers', 'stat': data.followers}, - {'name' : 'Following', 'stat': data.following}]; + let statdata = [{ 'name': 'Repos', 'stat': data.public_repos }, + { 'name': 'Followers', 'stat': data.followers }, + { 'name': 'Following', 'stat': data.following }]; - statdata.forEach((x)=>{ + statdata.forEach((x) => { let stat = document.createElement('a'); stat.className = 'survol-github-profile-stat'; @@ -94,17 +94,17 @@ class GitHubHover { profStats.appendChild(stat); }); - + githubProfileContainer.appendChild(profStats); let githubLinksContainer = document.createElement('div'); githubLinksContainer.className = 'survol-github-links'; - let links = [{"name": "Workplace: ", "link" : data.company? data.company : 'not available'}, - {"name": "Twitter: ", "link" : data.twitter_username ? '@' + data.twitter_username : 'not available'}, - {"name": "Website: ", "link" : data.blog? data.blog : 'not available'}]; + let links = [{ 'name': 'Workplace: ', 'link': data.company ? data.company : 'not available' }, + { 'name': 'Twitter: ', 'link': data.twitter_username ? '@' + data.twitter_username : 'not available' }, + { 'name': 'Website: ', 'link': data.blog ? data.blog : 'not available' }]; - links.forEach((link)=>{ + links.forEach((link) => { let linkContainer = document.createElement('div'); let linkName = document.createElement('span'); @@ -116,9 +116,9 @@ class GitHubHover { let linkText = document.createElement('span'); linkText.appendChild(document.createTextNode(link.link)); - if (link.link.includes('not available')){ + if (link.link.includes('not available')) { linkText.className = 'survol-github-link empty'; - }else{ + } else { linkText.className = 'survol-github-link'; } @@ -126,7 +126,7 @@ class GitHubHover { githubLinksContainer.appendChild(linkContainer); }) - + githubProfileContainer.appendChild(githubLinksContainer); githubContainer.appendChild(githubProfileContainer); diff --git a/manifest.json b/manifest.json index e73a46d..2820456 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "manifest_version": 2, - "version": "6.0.0", + "version": "0.6.2", "name": "__MSG_extensionName__", "short_name": "__MSG_extensionShortName__", "description": "__MSG_extensionDescription__",