Skip to content

Commit 4cc9a27

Browse files
committed
release 26 - fix manifest, disable a few locations, removed background script
1 parent 68e849d commit 4cc9a27

File tree

11 files changed

+85
-99
lines changed

11 files changed

+85
-99
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
APP_VERSION=8.3.4
1+
APP_VERSION=9.0.4
22
PAYPAL_URL=https://www.paypal.me/KasElvirov
33
OPENCOLLECTIVE_URL=https://opencollective.com/kas-elvirov

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ Initial version: 2.0.1 ( 2017, 12 february )
1818
I made this extension in the Russian Army while I was on duty. I was coding as fast as i could )))
1919

2020
## Description
21-
Works for **public** and **private** repos.
21+
Works for **public** and **private** repos
22+
2223
Counts lines of code in:
2324
- user's pinned repos ([check it out](https://github.com/torvalds))
25+
- project detail page ([check it out](https://github.com/torvalds/linux))
26+
27+
Previosly was counting there but i decided to stop it because it's huge load on the services of GutHub (ethics etc.)
2428
- user's repositories ([check it out](https://github.com/torvalds?tab=repositories))
2529
- user's liked repositories ([check it out](https://github.com/torvalds?tab=stars))
26-
- project detail page ([check it out](https://github.com/torvalds/linux))
2730
- organization page ([check it out](https://github.com/facebook))
2831
- search results page ([check it out](https://github.com/search?q=react))
2932
- trending page ([check it out](https://github.com/trending))

manifest.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
{
22
"manifest_version": 3,
33
"default_locale": "en",
4-
"name": "__MSG_name__",
5-
"short_name": "__MSG_shortName__",
6-
"author": "__MSG_author__",
7-
"description": "__MSG_description__",
8-
"version": "8.3.4",
9-
"browser_action": {
10-
"default_icon": "img/icon128.png",
11-
"default_popup": "index.html",
12-
"default_title": "Github Gloc"
4+
"name": "Gloc",
5+
"short_name": "Gloc",
6+
"author": "Kas Elvirov",
7+
"description": "Github Gloc - counts locs on GitHub pages",
8+
"version": "9.0.4",
9+
"action": {
10+
"default_icon": {
11+
"16": "img/icon16.png",
12+
"32": "img/icon32.png",
13+
"64": "img/icon64.png",
14+
"128": "img/icon128.png"
15+
},
16+
"default_title": "Github Gloc - counts locs on GitHub pages",
17+
"default_popup": "index.html"
1318
},
1419
"options_ui": {
1520
"page": "options.html"
@@ -25,12 +30,6 @@
2530
]
2631
}
2732
],
28-
"background": {
29-
"scripts": [
30-
"src/background.js"
31-
],
32-
"persistent": false
33-
},
3433
"permissions": [
3534
"storage"
3635
],

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "gloc",
3-
"version": "8.3.4",
2+
"name": "Gloc",
3+
"version": "9.0.4",
44
"engines": {
55
"node": "16.19.0",
66
"npm": "0.39.3"
@@ -31,7 +31,7 @@
3131
"zip": "grunt",
3232
"build:prod": "webpack --config webpack.config.prod && grunt",
3333
"build:dev": "webpack --config webpack.config.dev && grunt",
34-
"version:up": "npm version patch --no-git-tag-version --force && node ./scripts/upAppVersion.js && git add package.json .env manifest.json"
34+
"version:up": "npm version patch --no-git-tag-version --force && node ./scripts/upAppVersion.js && git add package.json package-lock.json .env manifest.json"
3535
},
3636
"husky": {
3737
"hooks": {

src/background.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/configs/parametersToMap.ts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,52 @@
1-
import isPositiveArray from 'is-positive-array';
2-
31
import { LOCATION } from '../types';
42

53
export type ExistenceChecker = (entity: HTMLAnchorElement[]) => boolean;
64
export type Wrapper = (links: HTMLAnchorElement) => HTMLAnchorElement[];
75

86
export interface ParameterToMap {
97
locationName: LOCATION;
10-
selector: 'querySelectorAll' | 'querySelector' | void;
11-
pathToSelect: string | void;
8+
selector: 'querySelectorAll' | 'querySelector';
9+
pathToSelect: string;
1210
pathToInsert?: string ;
13-
existenceChecker: ExistenceChecker | void;
14-
wrapper: Wrapper | void;
11+
existenceChecker: ExistenceChecker;
12+
wrapper: Wrapper;
1513
}
1614

1715
const currentUserLocation = window.location.pathname.replace('/', '');
1816

19-
export const parametersToMap: ParameterToMap[] = [
17+
export const GITHUB_LOCATION_CONFIGS: ParameterToMap[] = [
2018
{
21-
/*
22-
https://github.com/kas-elvirov
19+
/**
20+
* Example https://github.com/kas-elvirov
2321
*/
2422
locationName: LOCATION.PINNED_REPOS,
2523
selector: 'querySelectorAll',
2624
pathToSelect: '.js-pinned-items-reorder-list .pinned-item-list-item-content div a',
2725
pathToInsert: '.wb-break-all',
28-
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
26+
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
2927
wrapper: (entity) => Array.prototype.slice.call(entity),
3028
},
29+
{
30+
locationName: LOCATION.SINGLE,
31+
selector: 'querySelector',
32+
pathToSelect: '#repository-container-header > div.d-flex.mb-3.px-3.px-lg-5 > div > div > strong a',
33+
/**
34+
* Example https://github.com/kas-elvirov/gloc
35+
*/
36+
pathToInsert: '.public',
37+
existenceChecker: (entity: HTMLAnchorElement[]) => Boolean(entity),
38+
wrapper: (entity: HTMLAnchorElement) => [entity],
39+
},
40+
{
41+
locationName: LOCATION.UNKNOWN,
42+
selector: 'querySelectorAll',
43+
pathToSelect: '',
44+
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
45+
wrapper: (entity) => Array.prototype.slice.call(entity),
46+
},
47+
];
48+
49+
export const GITHUB_LOCATION_CONFIGS_LEGACY: ParameterToMap[] = [
3150
{
3251
/*
3352
https://github.com/torvalds
@@ -36,48 +55,37 @@ export const parametersToMap: ParameterToMap[] = [
3655
selector: 'querySelectorAll',
3756
pathToSelect: '.js-pinned-items-reorder-container ol li div div div a',
3857
pathToInsert: '.wb-break-all',
39-
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
58+
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
4059
wrapper: (entity) => Array.prototype.slice.call(entity),
4160
},
4261
{
4362
locationName: LOCATION.ORGANIZATION,
4463
selector: 'querySelectorAll',
4564
pathToSelect: '#org-repositories div ul div.flex-auto > h3 > a',
46-
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
65+
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
4766
wrapper: (entity) => Array.prototype.slice.call(entity),
4867
},
4968
{
5069
locationName: LOCATION.SEARCH,
5170
selector: 'querySelectorAll',
5271
pathToSelect: '.codesearch-results ul li a.v-align-middle',
53-
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
72+
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
5473
wrapper: (entity) => Array.prototype.slice.call(entity),
5574
},
56-
{
57-
locationName: LOCATION.SINGLE,
58-
selector: 'querySelector',
59-
pathToSelect: '#repository-container-header > div.d-flex.mb-3.px-3.px-lg-5 > div > div > strong a',
60-
/*
61-
for example: https://github.com/kas-elvirov/gloc
62-
*/
63-
pathToInsert: '.public',
64-
existenceChecker: (entity: HTMLAnchorElement[]) => Boolean(entity),
65-
wrapper: (entity: HTMLAnchorElement) => [entity],
66-
},
6775
{
6876
locationName: LOCATION.EXPLORE,
6977
selector: 'querySelectorAll',
7078
pathToSelect: 'article h1 a.text-bold',
7179
existenceChecker: (entity: HTMLAnchorElement[]) =>
72-
currentUserLocation === LOCATION.EXPLORE.toLowerCase() && isPositiveArray(entity),
80+
currentUserLocation === LOCATION.EXPLORE.toLowerCase() && entity?.length > 0,
7381
wrapper: (entity) => Array.prototype.slice.call(entity),
7482
},
7583
{
7684
locationName: LOCATION.TRENDING,
7785
selector: 'querySelectorAll',
7886
pathToSelect: 'article h1 a',
7987
existenceChecker: (entity: HTMLAnchorElement[]) =>
80-
currentUserLocation === LOCATION.TRENDING.toLowerCase() && isPositiveArray(entity),
88+
currentUserLocation === LOCATION.TRENDING.toLowerCase() && entity?.length > 0,
8189
wrapper: (entity) => Array.prototype.slice.call(entity),
8290
},
8391
{
@@ -87,21 +95,14 @@ export const parametersToMap: ParameterToMap[] = [
8795
locationName: LOCATION.USER_REPOSITORIES,
8896
selector: 'querySelectorAll',
8997
pathToSelect: '#user-repositories-list ul li h3 a',
90-
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
98+
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
9199
wrapper: (entity) => Array.prototype.slice.call(entity),
92100
},
93101
{
94102
locationName: LOCATION.LIKED_REPOS,
95103
selector: 'querySelectorAll',
96104
pathToSelect: '.page-profile h3 a',
97-
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
105+
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
98106
wrapper: (entity) => Array.prototype.slice.call(entity),
99107
},
100-
{
101-
locationName: LOCATION.UNKNOWN,
102-
selector: undefined,
103-
pathToSelect: undefined,
104-
existenceChecker: undefined,
105-
wrapper: undefined,
106-
},
107108
];

src/utils/getLinksFromDom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import isPositiveArray from 'is-positive-array';
22

33
import { InitialData, LOCATION } from '../types';
4-
import { parametersToMap } from '../configs/parametersToMap';
4+
import { GITHUB_LOCATION_CONFIGS } from '../configs/parametersToMap';
55

66
import { scrapData } from './scrapData';
77

88
export const getLinksFromDom = (): Promise<InitialData> => {
9-
const data = scrapData(parametersToMap) as InitialData;
9+
const data = scrapData(GITHUB_LOCATION_CONFIGS) as InitialData;
1010

1111
if (data.location !== LOCATION.UNKNOWN && isPositiveArray(data.links)) {
1212
return Promise.resolve(data);

src/utils/scrapData.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { ParameterToMap, ExistenceChecker, Wrapper } from '../configs/parametersToMap';
1+
import { ParameterToMap } from '../configs/parametersToMap';
22
import { LOCATION, InitialData } from '../types';
33

4-
export const scrapData = (parameters: ParameterToMap[]): InitialData | void => {
4+
export const scrapData = (parameters: ParameterToMap[]): InitialData => {
5+
const result: InitialData = {
6+
location: LOCATION.UNKNOWN,
7+
links: [],
8+
linksToInsert: [],
9+
};
10+
511
for (let i = 0; i < parameters.length; i++) {
612
const config = parameters[i];
713

@@ -14,27 +20,23 @@ export const scrapData = (parameters: ParameterToMap[]): InitialData | void => {
1420
wrapper,
1521
} = config;
1622

17-
if (locationName === LOCATION.UNKNOWN) {
18-
return {
19-
location: LOCATION.UNKNOWN,
20-
links: [],
21-
linksToInsert: [],
22-
};
23-
}
24-
2523
// @ts-ignore
2624
const entity = document[selector](pathToSelect);
2725
// @ts-ignore
2826
const entityToInsert = document[selector](pathToInsert);
2927

30-
if ((existenceChecker as ExistenceChecker)(entity)) {
31-
console.log('scrapData.locationName', locationName);
32-
console.log('scrapData.links', (wrapper as Wrapper)(entity));
33-
return {
34-
location: locationName,
35-
links: (wrapper as Wrapper)(entity) as HTMLAnchorElement[],
36-
linksToInsert: (wrapper as Wrapper)(entityToInsert) as HTMLAnchorElement[],
37-
};
28+
if (locationName === LOCATION.UNKNOWN) {
29+
break;
30+
}
31+
32+
if (existenceChecker(entity)) {
33+
result.location = locationName;
34+
result.links = wrapper(entity) as HTMLAnchorElement[];
35+
result.linksToInsert = wrapper(entityToInsert) as HTMLAnchorElement[];
36+
37+
break;
3838
}
3939
}
40+
41+
return result;
4042
};

webpack.config.dev.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const JSconfig = {
1010
mode: 'development',
1111
name: 'JS',
1212
entry: {
13-
'background': './src/background.ts',
1413
'inject': './src/inject.ts',
1514
'options': './src/options.ts',
1615
'popup': './src/popup.tsx',

0 commit comments

Comments
 (0)