Skip to content

Commit

Permalink
Merge pull request kas-elvirov#49 from artem-solovev/gloc-44
Browse files Browse the repository at this point in the history
kas-elvirov#44 Fixed LOC's counting for single repo page
  • Loading branch information
kas-elvirov authored Mar 24, 2019
2 parents 478e386 + 72de5ba commit 4ef4a72
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ___
# Browser extension GLOC ( [Chrome](https://chrome.google.com/webstore/detail/gloc-github-counter-lines/kaodcnpebhdbpaeeemkiobcokcnegdki?utm_source=chrome-ntp-icon), [Opera]() )
![Chrome](screens/browsers/chrome.png)
![Opera](screens/browsers/opera.png)
## **Current version: 7.7.0** ( 2019, 24 march )
## **Current version: 7.7.1** ( 2019, 24 march )
## **Initial release 2.0.1** ( 2017, 12 february )


Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"short_name": "__MSG_shortName__",
"author": "__MSG_author__",
"description": "__MSG_description__",
"version": "7.7.0",
"version": "7.7.1",

"browser_action": {
"default_icon": "img/icon128.png",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gloc",
"version": "7.7.0",
"version": "7.7.1",
"description": "Extension counts the number of lines of code in GitHub pages.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const APP_NAME = 'GitHub Gloc';
export const APP_CLASSNAME = 'github-gloc';
export const TRIES_DEFAULT = 5;
export const REPO_CLASS = 'repository-meta-content';
export const REPO_CLASS = 'public';

export const MESSAGE_IDS = {
POPUP: [
Expand Down
29 changes: 13 additions & 16 deletions src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ let githubToken: string = null;
/**
* Renders total LOC into DOM
*/
function insertLocForRepo() {
const reposMetaContent = document.getElementsByClassName(REPO_CLASS)[0];
const insertLocForRepo = () => {
const nodeToMount = document.getElementsByClassName(REPO_CLASS)[0];
const userRepos = document.querySelectorAll('#user-repositories-list h3 a');
const organisationRepos = document.querySelectorAll('.repo-list h3 a');
const recommendedRepos = document.querySelectorAll(
'#recommended-repositories-container h3 a'
);

// Add LOC to single repo
if (reposMetaContent) {
appendLoc(getRepoName(), reposMetaContent);
if (nodeToMount) {
appendLoc(getRepoName(), nodeToMount);
}

let repos: NodeListOf<Element> = null;
Expand All @@ -68,7 +68,7 @@ function insertLocForRepo() {
appendLoc(link, elem);
});
}
}
};

/**
* Gets repo name from current location
Expand All @@ -90,18 +90,18 @@ const getRepoName = () => {
* @param {string} repoName
* @param {Element} element
*/
function appendLoc(repoName: string, element: Element) {
const appendLoc = (repoName: string, element: Element) => {
getGloc(repoName, TRIES_DEFAULT)
.then((lines: number) => (element.innerHTML += getBadgeWithLines(lines)))
.then((lines: number) => element.innerHTML += getBadgeWithLines(lines))
.catch((e: any) => log('e', e));
}
};

/**
* Returns badge container for LOC with LOC
* @param {number} lines - LOC
* @return {html}
*/
function getBadgeWithLines(lines: number) {
const getBadgeWithLines = (lines: number) => {
return (
` <div class='box' style='font-size: 0; font-family: Verdana;'>
<span
Expand All @@ -117,7 +117,7 @@ function getBadgeWithLines(lines: number) {
</span>
</div> `
);
}
};

/**
* Counts LOC
Expand Down Expand Up @@ -151,23 +151,21 @@ const getGloc = (repoName: string, tries: number): Promise<any> => {
* @param {string} repo - /user/repo
* @return {string}
*/
function setApiUrl(repoName: string) {
return `https://api.github.com/repos${repoName}/stats/code_frequency`;
}
const setApiUrl = (repoName: string) => `https://api.github.com/repos${repoName}/stats/code_frequency`;

/**
* Adds token to URL
* @param {string} url
* @return {string}
*/
function tokenizeUrl(url: string) {
const tokenizeUrl = (url: string) => {
if (githubToken !== null && typeof githubToken === 'string') {
return `${url}?access_token=${githubToken}`;
}
log('e', 'Error by tokenizing URL');

return '';
}
};

/**
* PART 2.
Expand Down Expand Up @@ -407,7 +405,6 @@ const insertLocForDir = () => {
* @param {number} loc
*/
const renderLocForFile = (link: HTMLAnchorElement, loc: number) => {
// console.log( str ) --> .eslintrc.js 00 lines
const str = `${link.title}<span style='color:#888'> ${loc} ${chrome.i18n.getMessage('lines')}</span>`;

document.getElementById(link.id).innerHTML = str;
Expand Down

0 comments on commit 4ef4a72

Please sign in to comment.