Skip to content

Commit

Permalink
release 26 - fix manifest, disable a few locations, removed backgroun…
Browse files Browse the repository at this point in the history
…d script
  • Loading branch information
kas-elvirov committed Jan 1, 2025
1 parent 68e849d commit 4cc9a27
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APP_VERSION=8.3.4
APP_VERSION=9.0.4
PAYPAL_URL=https://www.paypal.me/KasElvirov
OPENCOLLECTIVE_URL=https://opencollective.com/kas-elvirov
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ Initial version: 2.0.1 ( 2017, 12 february )
I made this extension in the Russian Army while I was on duty. I was coding as fast as i could )))

## Description
Works for **public** and **private** repos.
Works for **public** and **private** repos

Counts lines of code in:
- user's pinned repos ([check it out](https://github.com/torvalds))
- project detail page ([check it out](https://github.com/torvalds/linux))

Previosly was counting there but i decided to stop it because it's huge load on the services of GutHub (ethics etc.)
- user's repositories ([check it out](https://github.com/torvalds?tab=repositories))
- user's liked repositories ([check it out](https://github.com/torvalds?tab=stars))
- project detail page ([check it out](https://github.com/torvalds/linux))
- organization page ([check it out](https://github.com/facebook))
- search results page ([check it out](https://github.com/search?q=react))
- trending page ([check it out](https://github.com/trending))
Expand Down
29 changes: 14 additions & 15 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"manifest_version": 3,
"default_locale": "en",
"name": "__MSG_name__",
"short_name": "__MSG_shortName__",
"author": "__MSG_author__",
"description": "__MSG_description__",
"version": "8.3.4",
"browser_action": {
"default_icon": "img/icon128.png",
"default_popup": "index.html",
"default_title": "Github Gloc"
"name": "Gloc",
"short_name": "Gloc",
"author": "Kas Elvirov",
"description": "Github Gloc - counts locs on GitHub pages",
"version": "9.0.4",
"action": {
"default_icon": {
"16": "img/icon16.png",
"32": "img/icon32.png",
"64": "img/icon64.png",
"128": "img/icon128.png"
},
"default_title": "Github Gloc - counts locs on GitHub pages",
"default_popup": "index.html"
},
"options_ui": {
"page": "options.html"
Expand All @@ -25,12 +30,6 @@
]
}
],
"background": {
"scripts": [
"src/background.js"
],
"persistent": false
},
"permissions": [
"storage"
],
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gloc",
"version": "8.3.4",
"name": "Gloc",
"version": "9.0.4",
"engines": {
"node": "16.19.0",
"npm": "0.39.3"
Expand Down Expand Up @@ -31,7 +31,7 @@
"zip": "grunt",
"build:prod": "webpack --config webpack.config.prod && grunt",
"build:dev": "webpack --config webpack.config.dev && grunt",
"version:up": "npm version patch --no-git-tag-version --force && node ./scripts/upAppVersion.js && git add package.json .env manifest.json"
"version:up": "npm version patch --no-git-tag-version --force && node ./scripts/upAppVersion.js && git add package.json package-lock.json .env manifest.json"
},
"husky": {
"hooks": {
Expand Down
17 changes: 0 additions & 17 deletions src/background.ts

This file was deleted.

71 changes: 36 additions & 35 deletions src/configs/parametersToMap.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
import isPositiveArray from 'is-positive-array';

import { LOCATION } from '../types';

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

export interface ParameterToMap {
locationName: LOCATION;
selector: 'querySelectorAll' | 'querySelector' | void;
pathToSelect: string | void;
selector: 'querySelectorAll' | 'querySelector';
pathToSelect: string;
pathToInsert?: string ;
existenceChecker: ExistenceChecker | void;
wrapper: Wrapper | void;
existenceChecker: ExistenceChecker;
wrapper: Wrapper;
}

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

export const parametersToMap: ParameterToMap[] = [
export const GITHUB_LOCATION_CONFIGS: ParameterToMap[] = [
{
/*
https://github.com/kas-elvirov
/**
* Example https://github.com/kas-elvirov
*/
locationName: LOCATION.PINNED_REPOS,
selector: 'querySelectorAll',
pathToSelect: '.js-pinned-items-reorder-list .pinned-item-list-item-content div a',
pathToInsert: '.wb-break-all',
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
{
locationName: LOCATION.SINGLE,
selector: 'querySelector',
pathToSelect: '#repository-container-header > div.d-flex.mb-3.px-3.px-lg-5 > div > div > strong a',
/**
* Example https://github.com/kas-elvirov/gloc
*/
pathToInsert: '.public',
existenceChecker: (entity: HTMLAnchorElement[]) => Boolean(entity),
wrapper: (entity: HTMLAnchorElement) => [entity],
},
{
locationName: LOCATION.UNKNOWN,
selector: 'querySelectorAll',
pathToSelect: '',
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
];

export const GITHUB_LOCATION_CONFIGS_LEGACY: ParameterToMap[] = [
{
/*
https://github.com/torvalds
Expand All @@ -36,48 +55,37 @@ export const parametersToMap: ParameterToMap[] = [
selector: 'querySelectorAll',
pathToSelect: '.js-pinned-items-reorder-container ol li div div div a',
pathToInsert: '.wb-break-all',
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
{
locationName: LOCATION.ORGANIZATION,
selector: 'querySelectorAll',
pathToSelect: '#org-repositories div ul div.flex-auto > h3 > a',
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
{
locationName: LOCATION.SEARCH,
selector: 'querySelectorAll',
pathToSelect: '.codesearch-results ul li a.v-align-middle',
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
{
locationName: LOCATION.SINGLE,
selector: 'querySelector',
pathToSelect: '#repository-container-header > div.d-flex.mb-3.px-3.px-lg-5 > div > div > strong a',
/*
for example: https://github.com/kas-elvirov/gloc
*/
pathToInsert: '.public',
existenceChecker: (entity: HTMLAnchorElement[]) => Boolean(entity),
wrapper: (entity: HTMLAnchorElement) => [entity],
},
{
locationName: LOCATION.EXPLORE,
selector: 'querySelectorAll',
pathToSelect: 'article h1 a.text-bold',
existenceChecker: (entity: HTMLAnchorElement[]) =>
currentUserLocation === LOCATION.EXPLORE.toLowerCase() && isPositiveArray(entity),
currentUserLocation === LOCATION.EXPLORE.toLowerCase() && entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
{
locationName: LOCATION.TRENDING,
selector: 'querySelectorAll',
pathToSelect: 'article h1 a',
existenceChecker: (entity: HTMLAnchorElement[]) =>
currentUserLocation === LOCATION.TRENDING.toLowerCase() && isPositiveArray(entity),
currentUserLocation === LOCATION.TRENDING.toLowerCase() && entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
{
Expand All @@ -87,21 +95,14 @@ export const parametersToMap: ParameterToMap[] = [
locationName: LOCATION.USER_REPOSITORIES,
selector: 'querySelectorAll',
pathToSelect: '#user-repositories-list ul li h3 a',
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
{
locationName: LOCATION.LIKED_REPOS,
selector: 'querySelectorAll',
pathToSelect: '.page-profile h3 a',
existenceChecker: (entity: HTMLAnchorElement[]) => isPositiveArray(entity),
existenceChecker: (entity: HTMLAnchorElement[]) => entity?.length > 0,
wrapper: (entity) => Array.prototype.slice.call(entity),
},
{
locationName: LOCATION.UNKNOWN,
selector: undefined,
pathToSelect: undefined,
existenceChecker: undefined,
wrapper: undefined,
},
];
4 changes: 2 additions & 2 deletions src/utils/getLinksFromDom.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import isPositiveArray from 'is-positive-array';

import { InitialData, LOCATION } from '../types';
import { parametersToMap } from '../configs/parametersToMap';
import { GITHUB_LOCATION_CONFIGS } from '../configs/parametersToMap';

import { scrapData } from './scrapData';

export const getLinksFromDom = (): Promise<InitialData> => {
const data = scrapData(parametersToMap) as InitialData;
const data = scrapData(GITHUB_LOCATION_CONFIGS) as InitialData;

if (data.location !== LOCATION.UNKNOWN && isPositiveArray(data.links)) {
return Promise.resolve(data);
Expand Down
38 changes: 20 additions & 18 deletions src/utils/scrapData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { ParameterToMap, ExistenceChecker, Wrapper } from '../configs/parametersToMap';
import { ParameterToMap } from '../configs/parametersToMap';
import { LOCATION, InitialData } from '../types';

export const scrapData = (parameters: ParameterToMap[]): InitialData | void => {
export const scrapData = (parameters: ParameterToMap[]): InitialData => {
const result: InitialData = {
location: LOCATION.UNKNOWN,
links: [],
linksToInsert: [],
};

for (let i = 0; i < parameters.length; i++) {
const config = parameters[i];

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

if (locationName === LOCATION.UNKNOWN) {
return {
location: LOCATION.UNKNOWN,
links: [],
linksToInsert: [],
};
}

// @ts-ignore
const entity = document[selector](pathToSelect);
// @ts-ignore
const entityToInsert = document[selector](pathToInsert);

if ((existenceChecker as ExistenceChecker)(entity)) {
console.log('scrapData.locationName', locationName);
console.log('scrapData.links', (wrapper as Wrapper)(entity));
return {
location: locationName,
links: (wrapper as Wrapper)(entity) as HTMLAnchorElement[],
linksToInsert: (wrapper as Wrapper)(entityToInsert) as HTMLAnchorElement[],
};
if (locationName === LOCATION.UNKNOWN) {
break;
}

if (existenceChecker(entity)) {
result.location = locationName;
result.links = wrapper(entity) as HTMLAnchorElement[];
result.linksToInsert = wrapper(entityToInsert) as HTMLAnchorElement[];

break;
}
}

return result;
};
1 change: 0 additions & 1 deletion webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const JSconfig = {
mode: 'development',
name: 'JS',
entry: {
'background': './src/background.ts',
'inject': './src/inject.ts',
'options': './src/options.ts',
'popup': './src/popup.tsx',
Expand Down
1 change: 0 additions & 1 deletion webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const JSconfig = {
mode: 'production',
name: 'JS',
entry: {
'background': './src/background.ts',
'inject': './src/inject.ts',
'options': './src/options.ts',
'popup': './src/popup.tsx',
Expand Down

0 comments on commit 4cc9a27

Please sign in to comment.