diff --git a/package.json b/package.json index f39fde9c..c9272fc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "hypertrons-crx", - "version": "1.1.0", + "name": "hypercrx", + "version": "1.0.2", "private": true, "description": "Hypertrons Chromium Extension", "license": "Apache", @@ -22,7 +22,6 @@ "@types/chrome": "0.0.104", "@types/react": "^17.0.2", "copy-to-clipboard": "^3.3.1", - "delegated-events": "^1.1.2", "echarts": "^5.0.2", "github-url-detection": "^4.10.0", "jquery": "^3.6.0", diff --git a/src/api/github.ts b/src/api/github.ts index 6dcd65d4..1775824d 100644 --- a/src/api/github.ts +++ b/src/api/github.ts @@ -14,8 +14,8 @@ export const getConfigFromGithub = async (owner: string, repo: string) => { const response = await octokit.request('GET /repos/{owner}/{repo}/contents/.github/hypertrons.json', { owner, repo }); const res = response.data as any; res.content = Buffer.from(res.content, 'base64').toString('ascii'); - return JSON.parse(res.content); + return JSON.parse(res.content)["hypertrons-crx"]; } catch (error: unknown) { return {}; } -} \ No newline at end of file +} diff --git a/src/components/Graph/Radar.tsx b/src/components/Graph/Radar.tsx deleted file mode 100644 index 504dbe72..00000000 --- a/src/components/Graph/Radar.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import EChartsWrapper from './Echarts/index'; -import { Stack, Link } from 'office-ui-fabric-react'; -import { isNull, getMessageByLocale } from '../../utils/utils'; -import Settings, { loadSettings } from '../../utils/settings'; - -interface RadarProps { - /** - * data - */ - readonly data: any; -} - -const Radar: React.FC = ({ data}) => { - - const [inited, setInited] = useState(false); - const [settings, setSettings] = useState(new Settings()); - - useEffect(() => { - const initSettings = async () => { - const temp = await loadSettings(); - setSettings(temp); - setInited(true); - } - if (!inited) { - initSettings(); - } - }, [inited, settings]); - - if (isNull(data)) { - return (
) - } - return ( - - - - - - ) -}; - -export default Radar; \ No newline at end of file diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index b22685bb..c31b2c5e 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -8,9 +8,6 @@ "golbal_loading": { "message": "Loading……" }, - "golbal_link": { - "message": "Link" - }, "global_error_message": { "message": "Sorry,an error occurred while loading Hypertrons-crx extention. Error Code is: " }, @@ -143,18 +140,6 @@ "component_activeDeveloperCollabrationNetwork_description_edge": { "message": "Edge: Collaborative relationship between developers, the value indicates the closeness of the connection between developers." }, - "component_projectDimensionIndex_title": { - "message": "Project Dimension Index" - }, - "component_projectDimensionIndex_description": { - "message": "Project Dimension Index shows how do these fields change comparing the last time." - }, - "component_projectDimensionIndex_description_sub1": { - "message": "" - }, - "component_projectDimensionIndex_description_sub2": { - "message": "" - }, "component_darkMode": { "message": "Dark mode" }, @@ -259,14 +244,5 @@ }, "options_about_description_website": { "message": "Welcome to visit out website to get more infomation:" - }, - "hypertrons_tab_title": { - "message": "Hypertrons Commands" - }, - "hypertrons_tab_description": { - "message": "You can use hypertrons commands here. See usage:" - }, - "hypertrons_tab_link": { - "message": "https://www.hypertrons.io/#/component/index" } } \ No newline at end of file diff --git a/src/locales/zh_CN/messages.json b/src/locales/zh_CN/messages.json index ae02a890..1832514f 100644 --- a/src/locales/zh_CN/messages.json +++ b/src/locales/zh_CN/messages.json @@ -8,9 +8,6 @@ "golbal_loading": { "message": "载入中......" }, - "golbal_link": { - "message": "链接" - }, "global_error_message": { "message": "抱歉,Hypertrons-crx 插件加载时遇到了一点问题。错误代码为:" }, @@ -143,18 +140,6 @@ "component_activeDeveloperCollabrationNetwork_description_edge": { "message": "边:开发者与开发者之间的连接关系,值的大小表示开发者间联系的紧密程度。" }, - "component_projectDimensionIndex_title": { - "message": "项目维度指标图" - }, - "component_projectDimensionIndex_description": { - "message": "项目维度指标图展现了项目相对于上一周期各维度的变化。" - }, - "component_projectDimensionIndex_description_sub1": { - "message": "" - }, - "component_projectDimensionIndex_description_sub2": { - "message": "" - }, "component_darkMode": { "message": "深色模式" }, @@ -259,14 +244,5 @@ }, "options_about_description_website": { "message": "欢迎访问我们的网站获取更多信息:" - }, - "hypertrons_tab_title": { - "message": "Hypertrons 指令" - }, - "hypertrons_tab_description": { - "message": "可在此处使用hypertrons指令,详情请见:" - }, - "hypertrons_tab_link": { - "message": "https://www.hypertrons.io/#/zh-cn/component/index" } } \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index e3c61202..46549b36 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -26,8 +26,7 @@ "*://github.com/*", "storage", "notifications", - "alarms", - "cookies" + "alarms" ], "manifest_version": 2, "content_security_policy": "script-src 'self'; object-src 'self'" diff --git a/src/mock/radar.data.ts b/src/mock/radar.data.ts deleted file mode 100644 index 1ebc3b03..00000000 --- a/src/mock/radar.data.ts +++ /dev/null @@ -1,29 +0,0 @@ -export const radarData = { - legend: { - data: ['previous', 'current'] - }, - radar: { - // shape: 'circle', - indicator: [ - { name: 'commit', max: 6500}, - { name: 'issue', max: 16000}, - { name: 'pr', max: 30000}, - { name: 'comment', max: 38000}, - { name: 'star', max: 52000}, - { name: 'fork', max: 25000} - ] - }, - series: [{ - type: 'radar', - data: [ - { - value: [4200, 3000, 20000, 35000, 50000, 18000], - name: 'previous' - }, - { - value: [5000, 14000, 28000, 26000, 42000, 21000], - name: 'current' - } - ] - }] -}; \ No newline at end of file diff --git a/src/pages/Background/index.ts b/src/pages/Background/index.ts index 89d1c8dc..b86df896 100644 --- a/src/pages/Background/index.ts +++ b/src/pages/Background/index.ts @@ -62,27 +62,4 @@ chrome.notifications.onClicked.addListener(async function(notificationId){ break; } chrome.notifications.clear(notificationId); -}); - -chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { - const type = request.task_type - if(type==="get_username_from_cookie"){ - chrome.cookies.get({ - url : "https://github.com", - name : "dotcom_user" - }, function(cookie) { - let message; - if(cookie){ - message=cookie.value; - } - else{ - message=null; - } - sendResponse({ - message: message - }); - }); - } - // must return true in async mode - return true; -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/src/pages/Content/Hypertrons.tsx b/src/pages/Content/Hypertrons.tsx deleted file mode 100644 index f478a201..00000000 --- a/src/pages/Content/Hypertrons.tsx +++ /dev/null @@ -1,236 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { render } from 'react-dom'; -import $ from 'jquery'; -import { fire } from 'delegated-events' -import * as pageDetect from 'github-url-detection'; -import { - Callout, Stack,Link, Text, initializeIcons, - mergeStyleSets, FontWeights, DirectionalHint -} from '@fluentui/react'; -import { useBoolean } from '@fluentui/react-hooks'; -import { utils } from 'github-url-detection'; -import { Command,LabelStyles,Label2Style,getUserNameFromCookie } from "../../services/hypertrons" -import { getMessageByLocale, runsWhen } from '../../utils/utils'; -import PerceptorBase from './PerceptorBase'; -import { inject2Perceptor } from './Perceptor'; -import logger from '../../utils/logger'; -import Settings, { loadSettings } from '../../utils/settings'; -import { getConfigFromGithub } from '../../api/github'; - -initializeIcons(); - -const styles = mergeStyleSets({ - callout: { - width: 360, - padding: '20px 24px', - }, - title: { - fontWeight: FontWeights.bold, - marginBottom: 10, - }, - buttons: { - marginTop: 20, - overflow:"hidden" - }, -}); - -interface HypertronsTabViewProps { - hypertronsConfig: any; -} - -const HypertronsTabView: React.FC = ({hypertronsConfig}) => { - const commandsInit: Command[]=[] - const [settings, setSettings] = useState(new Settings()); - const [settingsInited, setSettingsInited] = useState(false); - const [isCalloutVisible, { toggle: toggleIsCalloutVisible }] = useBoolean(false); - const [userName, setUserName] = useState(null); - const [userNameInited, setUserNameInited] = useState(false); - const [commandsCurrent, setCommandsCurrent] = useState(commandsInit); - const [commandsCurrentInited, setCommandsCurrentInited] = useState(false); - - useEffect(() => { - const initSettings = async () => { - const temp = await loadSettings(); - setSettings(temp); - setSettingsInited(true); - } - if (!settingsInited) { - initSettings(); - } - }, [settingsInited,settings]); - - useEffect(() => { - const initUserName = async () => { - const userNameFromCookie = await getUserNameFromCookie(); - // @ts-ignore - setUserName(userNameFromCookie["message"]); - setUserNameInited(true); - } - if (!userNameInited) { - initUserName(); - } - }, [userNameInited,userName]); - - useEffect(() => { - const initCommandsCurrent = async () => { - let commandsCanUse=new Set([]); - if("role" in hypertronsConfig){ - // @ts-ignore - const roleConfig=hypertronsConfig["role"]; - if("roles" in roleConfig){ - const rolesConfig=roleConfig["roles"]; - // @ts-ignore - for(const role of rolesConfig){ - const roleName=role["name"]; - const usersSet=new Set(role["users"]); - const commands=role["commands"]; - if(usersSet.has(userName)||roleName==="anyone"){ - for(const command of commands){ - // @ts-ignore - commandsCanUse.add(command); - } - } - } - } - } - let commandsFinal: Command[]=[]; - for (const command of commandsCanUse) { - const commandNew:Command= { "command":command } - commandsFinal.push(commandNew); - } - setCommandsCurrent(commandsFinal); - setCommandsCurrentInited(true); - } - if (!commandsCurrentInited&&userNameInited) { - initCommandsCurrent(); - } - }, [userNameInited, commandsCurrentInited, commandsCurrent, hypertronsConfig, userName]); - - const ExecCommand=(command:Command)=>{ - const textarea=document.getElementById("new_comment_field") as HTMLTextAreaElement; - if(textarea){ - const commentCurrent=textarea.value; - let commandExec; - switch (command.command){ - case "/start-vote":commandExec=`${command.command} A,B,C,D`;break; - case "/vote":commandExec=`${command.command} A`;break; - case "/rerun":commandExec=`${command.command} CI`;break; - case "/complete-checklist":commandExec=`${command.command} 1 #1`;break; - default:commandExec=command.command;break; - } - const commentNew=`${commentCurrent}${commandExec} `; - // @ts-ignore - Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set.call(textarea, commentNew); - fire(textarea,"change"); - toggleIsCalloutVisible(); - } - } - - return ( -
0?"block":"none" - }} - > - - { - isCalloutVisible && ( - - - {getMessageByLocale("hypertrons_tab_title",settings.locale)} - - - {getMessageByLocale("hypertrons_tab_description",settings.locale)}  - - {getMessageByLocale("golbal_link",settings.locale)} - - - - { - commandsCurrent.map((command, index) => { - const styleIndex=index%(LabelStyles.length-1); - return ( -
{ - ExecCommand(command) - }} - > - {command.command} -
- ) - }) - } -
-
- ) - } -
- ) -} - -@runsWhen([pageDetect.isPR,pageDetect.isIssue]) -class Hypertrons extends PerceptorBase { - public static hypertronsConfig:any; - - private static renderView():void{ - // avoid redundant button - if($("#hypertrons_button").length>0){ - logger.info("hypertrons tab exists") - return - } - - // add hypertrons tab - const commentForm=$(".js-new-comment-form"); - const parentContainer = commentForm.find('.d-flex.flex-justify-end'); - const hypertronsTab=document.createElement('div'); - render( - , - hypertronsTab, - ); - parentContainer.prepend(hypertronsTab); - } - - public async run(config:any): Promise { - Hypertrons.hypertronsConfig=config; - // @ts-ignore - const observer = new MutationObserver(Hypertrons.renderView); - const element = document.querySelector('#new_comment_field'); - // @ts-ignore - observer.observe(element,{ - 'attributes': true, - }); - - Hypertrons.renderView(); - } -} - -inject2Perceptor(Hypertrons); \ No newline at end of file diff --git a/src/pages/Content/Perceptor.tsx b/src/pages/Content/Perceptor.tsx index 1b2d4eef..7d7acc91 100644 --- a/src/pages/Content/Perceptor.tsx +++ b/src/pages/Content/Perceptor.tsx @@ -7,7 +7,6 @@ import logger from '../../utils/logger'; export class Perceptor extends PerceptorBase { public static Features: Map = new Map(); public settings: any; - public hypertronsConfig: any; public async run(): Promise { logger.info('start.'); @@ -29,15 +28,9 @@ export class Perceptor extends PerceptorBase { logger.info('Detected that this is a repo page, trying to load configuration file from the repo ...'); const owner = utils.getRepositoryInfo(window.location)!.owner; const repo = utils.getRepositoryInfo(window.location)!.name; - const configHypertrons=await getConfigFromGithub(owner, repo); - logger.info('The configurations are: ', configHypertrons); - this.hypertronsConfig=configHypertrons; - if("hypertrons-crx" in configHypertrons){ - this.settings = await mergeSettings(configHypertrons["hypertrons-crx"]); - } - else{ - this.settings = await loadSettings(); - } + const configFromGithub = await getConfigFromGithub(owner, repo); + logger.info('The configurations are: ', configFromGithub); + this.settings = await mergeSettings(configFromGithub); } else { this.settings = await loadSettings(); } @@ -65,7 +58,7 @@ export class Perceptor extends PerceptorBase { } logger.info('running ', featureId) const feature = new Feature(); - await feature.run(this.hypertronsConfig); + await feature.run(); }, this) } diff --git a/src/pages/Content/PerceptorBase.tsx b/src/pages/Content/PerceptorBase.tsx index 6dd81aa9..44cbbb27 100644 --- a/src/pages/Content/PerceptorBase.tsx +++ b/src/pages/Content/PerceptorBase.tsx @@ -1,3 +1,3 @@ -export default abstract class PerceptorBase{ - public abstract run(config:any|null): Promise; +export default abstract class PerceptorBase { + public abstract run(): Promise; } \ No newline at end of file diff --git a/src/pages/Content/PerceptorLayout.tsx b/src/pages/Content/PerceptorLayout.tsx index 74535b31..7027ec62 100644 --- a/src/pages/Content/PerceptorLayout.tsx +++ b/src/pages/Content/PerceptorLayout.tsx @@ -5,7 +5,7 @@ import { isPerceptor, runsWhen } from '../../utils/utils'; import PerceptorBase from './PerceptorBase'; import { inject2Perceptor } from './Perceptor'; -const PerceptorLayoutView: React.FC = () => { +const PerceptorLayoutView: React.FC<{}> = () => { return (
) diff --git a/src/pages/Content/ProjectNetwork.tsx b/src/pages/Content/ProjectNetwork.tsx index 3bda5505..69c2c3a6 100644 --- a/src/pages/Content/ProjectNetwork.tsx +++ b/src/pages/Content/ProjectNetwork.tsx @@ -4,7 +4,6 @@ import $ from 'jquery'; import { utils } from 'github-url-detection'; import { Stack, Dropdown, IDropdownStyles, IDropdownOption, Spinner } from 'office-ui-fabric-react'; import Graph from '../../components/Graph/Graph'; -import Radar from '../../components/Graph/Radar' import { isPerceptor, runsWhen } from '../../utils/utils'; import { getRepoCorrelation, getDevelopersByRepo } from '../../api/repo'; import { getMessageByLocale } from '../../utils/utils'; @@ -12,7 +11,6 @@ import PerceptorBase from './PerceptorBase'; import { inject2Perceptor } from './Perceptor'; import Settings, { loadSettings } from '../../utils/settings'; import ErrorPage from '../../components/ExceptionPage/ErrorPage'; -import { radarData } from "../../mock/radar.data" interface ProjectNetworkViewProps { currentRepo: string; @@ -180,29 +178,6 @@ const ProjectNetworkView: React.FC = ({ currentRepo, gr
-
- - {getMessageByLocale('component_projectDimensionIndex_title', settings.locale)} - -
-
-
- -
-
-
-
-

{getMessageByLocale('component_projectDimensionIndex_description', settings.locale)}

- {/*
    */} - {/*
  • {getMessageByLocale('component_projectDimensionIndex_description_sub1', settings.locale)}
  • */} - {/*
  • {getMessageByLocale('component_projectDimensionIndex_description_sub2', settings.locale)}
  • */} - {/*
*/} -
-
-
-
) } diff --git a/src/pages/Content/index.ts b/src/pages/Content/index.ts index 0d9d3915..7c06d8a2 100644 --- a/src/pages/Content/index.ts +++ b/src/pages/Content/index.ts @@ -2,7 +2,6 @@ import './PerceptorTab'; import './PerceptorLayout'; import './DeveloperNetwork'; import './ProjectNetwork'; -import './Hypertrons'; import './content.styles.css'; import { Perceptor } from './Perceptor'; import { loadSettings } from '../../utils/settings'; @@ -15,4 +14,5 @@ async function mainInject() { } } -mainInject(); \ No newline at end of file +mainInject() + diff --git a/src/services/hypertrons.ts b/src/services/hypertrons.ts deleted file mode 100644 index 5e55e03f..00000000 --- a/src/services/hypertrons.ts +++ /dev/null @@ -1,38 +0,0 @@ -export interface Command { - command: string; -} - -export const LabelStyles:string[]=[ - "--label-r:17;--label-g:238;--label-b:17;--label-h:120;--label-s:86;--label-l:50", - "--label-r:3;--label-g:102;--label-b:214;--label-h:211;--label-s:97;--label-l:42", - "--label-r:199;--label-g:222;--label-b:248;--label-h:211;--label-s:77;--label-l:87", - "--label-r:184;--label-g:20;--label-b:91;--label-h:334;--label-s:80;--label-l:40", - "--label-r:95;--label-g:221;--label-b:164;--label-h:152;--label-s:64;--label-l:61", - "--label-r:112;--label-g:87;--label-b:255;--label-h:248;--label-s:100;--label-l:67", - "--label-r:252;--label-g:41;--label-b:41;--label-h:0;--label-s:97;--label-l:57", - "--label-r:251;--label-g:202;--label-b:4;--label-h:48;--label-s:96;--label-l:50", - "--label-r:246;--label-g:180;--label-b:222;--label-h:321;--label-s:78;--label-l:83", - "--label-r:67;--label-g:1;--label-b:137;--label-h:269;--label-s:98;--label-l:27", - "--label-r:237;--label-g:237;--label-b:237;--label-h:0;--label-s:0;--label-l:92", - "--label-r:147;--label-g:245;--label-b:168;--label-h:132;--label-s:83;--label-l:76" -] - -export function Label2Style(lable:string){ - let result: { [key: string]:number; } ={}; - const group=lable.split(";"); - for(const kv of group){ - const kvp=kv.split(":"); - result[kvp[0]]=parseInt(kvp[1]); - } - return result; -} - -export async function getUserNameFromCookie() { - return new Promise((resolve, reject) => { - chrome.runtime.sendMessage({ - task_type: "get_username_from_cookie" - }, response => { - resolve(response); - }) - }); -}