diff --git a/.gitignore b/.gitignore index 81d23dd..d121d5b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,5 @@ node_modules/ dist/ -### My ### +### Temp ### demo.json -.token diff --git a/README.md b/README.md index 1633f3c..47dcd8f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # GithubEventsExt_Userscript -+ A Userscript (Tampermonkey) extension that let browser show GitHub activity events. -+ For chrome version, please visit [Aoi-hosizora/GithubEventsExt](https://github.com/Aoi-hosizora/GithubEventsExt). ++ A Userscript extension that let browser show GitHub activity events. ++ For Chrome version, please visit [Aoi-hosizora/GithubEventsExt](https://github.com/Aoi-hosizora/GithubEventsExt). ### Functions @@ -10,17 +10,20 @@ ### Install -+ Install `Tampermonkey` / `Greasemonkey` extension for your browser (Chrome, Edge, Firefox, etc). -+ Visit https://github.com/Aoi-hosizora/GithubEventsExt_Userscript/raw/dist/github-events.user.js (build by GitHub Actions). -+ Click the "Install" button to install the extension. +1. Install `Tampermonkey` / `Greasemonkey` extension for your browser (Chrome, Edge, Firefox, etc). +2. Visit https://github.com/Aoi-hosizora/GithubEventsExt_Userscript/raw/dist/github-events.user.js, this code is built by GitHub Actions. +3. Click the "Install" button to install the extension. Now you will see the effect after refresh the GitHub page. -![how-to-install.jpg](./assets/how-to-install.jpg) +

+ how-to-install +

### Screenshot -![screenshot-sidebar](./assets/screenshot-sidebar.jpg) - -![screenshot-setting](./assets/screenshot-setting.jpg) +

+ screenshot-sidebar + screenshot-setting +

### References diff --git a/package-lock.json b/package-lock.json index bc69d91..71e6b17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,8 +29,7 @@ "ts-loader": "^6.2.1", "typescript": "^3.7.5", "webpack": "^4.41.5", - "webpack-cli": "^4.8.0", - "webpack-fix-style-only-entries": "^0.4.0" + "webpack-cli": "^4.8.0" } }, "node_modules/@babel/code-frame": { @@ -6344,12 +6343,6 @@ "node": ">= 10" } }, - "node_modules/webpack-fix-style-only-entries": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/webpack-fix-style-only-entries/-/webpack-fix-style-only-entries-0.4.0.tgz", - "integrity": "sha512-6TDa56V/xSOw6CBVlhFm6J+xXY2oJzx7CEgH0dmex2Xe1rwb95KkLl3rXvSNpO4wyahwD3YnYqffDNR0LH1BNQ==", - "dev": true - }, "node_modules/webpack-merge": { "version": "5.8.0", "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.8.0.tgz", @@ -12048,12 +12041,6 @@ } } }, - "webpack-fix-style-only-entries": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/webpack-fix-style-only-entries/-/webpack-fix-style-only-entries-0.4.0.tgz", - "integrity": "sha512-6TDa56V/xSOw6CBVlhFm6J+xXY2oJzx7CEgH0dmex2Xe1rwb95KkLl3rXvSNpO4wyahwD3YnYqffDNR0LH1BNQ==", - "dev": true - }, "webpack-merge": { "version": "5.8.0", "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.8.0.tgz", diff --git a/package.json b/package.json index 5a82f28..63b13fe 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "githubeventsext_userscript", + "title": "GitHub events extension", "version": "1.0.8", "description": "A Userscript extension that let browser show GitHub activity events.", "main": "index.js", @@ -30,8 +31,7 @@ "ts-loader": "^6.2.1", "typescript": "^3.7.5", "webpack": "^4.41.5", - "webpack-cli": "^4.8.0", - "webpack-fix-style-only-entries": "^0.4.0" + "webpack-cli": "^4.8.0" }, "dependencies": { "axios": "^0.19.2", diff --git a/src/content_script.ts b/src/content_script.ts index 11d10c3..70dc300 100644 --- a/src/content_script.ts +++ b/src/content_script.ts @@ -1,12 +1,13 @@ -import './ts/extension'; +import '@src/ts/extension'; import $ from 'jquery'; -import { Global, readStorageToGlobal } from './ts/global'; -import { adjustGithubUI, injectSidebar } from './ts/main'; -import { checkURL } from './ts/util'; +import { Global, readStorageToGlobal } from '@src/ts/global'; +import { adjustGithubUI, injectSidebar } from '@src/ts/main'; +import { checkURL } from '@src/ts/util'; // python -m http.server 5000 // http://localhost:5000/dist/github-events.user.js + $(() => { onLoaded(); }); diff --git a/src/etc/banner.js b/src/etc/banner.js index 7c7f522..434ca89 100644 --- a/src/etc/banner.js +++ b/src/etc/banner.js @@ -1,20 +1,22 @@ // ==UserScript== -// @name Github events -// @version 1.0.8 -// @author Aoi-hosizora -// @description A userscript extension that let browser show GitHub activity events. +// +// @name @@title +// @version @@version +// @author @@author +// @description @@description // @namespace https://github.com/ // @match http*://github.com/* -// @copyright 2020+, Aoi-hosizora - +// @copyright 2020+, @@author +// // @downloadURL https://github.com/Aoi-hosizora/GithubEventsExt_Userscript/raw/master/dist/github-events.user.js // @updateURL https://github.com/Aoi-hosizora/GithubEventsExt_Userscript/raw/master/src/etc/banner.js // @icon https://github.com/Aoi-hosizora/GithubEventsExt_Userscript/raw/master/public/image/icon16.png // @icon64 https://github.com/Aoi-hosizora/GithubEventsExt_Userscript/raw/master/public/image/icon32.png - +// // @run-at document-start // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_addStyle +// // ==/UserScript== diff --git a/src/ts/background.ts b/src/ts/background.ts index cd6c3be..34d58e2 100644 --- a/src/ts/background.ts +++ b/src/ts/background.ts @@ -1,4 +1,4 @@ -import { getStorage, removeStorage, setStorage, StorageFlag } from './global'; +import { getStorage, removeStorage, setStorage, StorageFlag } from '@src/ts/global'; export async function onActionClicked() { const token = await getStorage(StorageFlag.TOKEN); diff --git a/src/ts/global.ts b/src/ts/global.ts index 415500e..e6dbde1 100644 --- a/src/ts/global.ts +++ b/src/ts/global.ts @@ -1,5 +1,5 @@ import { GMApi } from 'greasemonkey'; -import { URLInfo } from './model'; +import { URLInfo } from '@src/ts/model'; export class Global { // Settings from storage diff --git a/src/ts/main.ts b/src/ts/main.ts index c801f6a..db7ab4a 100644 --- a/src/ts/main.ts +++ b/src/ts/main.ts @@ -1,12 +1,12 @@ import GMApi from 'greasemonkey'; import $ from 'jquery'; import moment from 'moment'; -import template from '../html/template.html'; -import style from '../scss/core.scss'; -import { Global } from './global'; -import { URLType } from './model'; -import { loadGithubEvents, registerUIEvents } from './ui_events'; -import { requestUserInfo } from './util'; +import template from '@src/html/template.html'; +import style from '@src/scss/core.scss'; +import { Global } from '@src/ts/global'; +import { URLType } from '@src/ts/model'; +import { loadGithubEvents, registerUIEvents } from '@src/ts/ui_events'; +import { requestUserInfo } from '@src/ts/util'; /** * Adjust github UI. diff --git a/src/ts/sidebar_ui.ts b/src/ts/sidebar_ui.ts index 81bfbce..fcc6db2 100644 --- a/src/ts/sidebar_ui.ts +++ b/src/ts/sidebar_ui.ts @@ -1,5 +1,5 @@ import moment from 'moment'; -import { EventInfo, HoverCardType } from './model'; +import { EventInfo, HoverCardType } from '@src/ts/model'; // =================== // format info related diff --git a/src/ts/ui_events.ts b/src/ts/ui_events.ts index cae9494..6e9cf5d 100644 --- a/src/ts/ui_events.ts +++ b/src/ts/ui_events.ts @@ -1,10 +1,10 @@ import $ from 'jquery'; import 'jquery-ui-dist/jquery-ui'; -import { onActionClicked } from './background'; -import { Global, setStorage, StorageFlag } from './global'; -import { EventInfo } from './model'; -import { formatInfoToLi } from './sidebar_ui'; -import { requestGithubEvents } from './util'; +import { onActionClicked } from '@src/ts/background'; +import { Global, setStorage, StorageFlag } from '@src/ts/global'; +import { EventInfo } from '@src/ts/model'; +import { formatInfoToLi } from '@src/ts/sidebar_ui'; +import { requestGithubEvents } from '@src/ts/util'; // =============== // request related diff --git a/src/ts/util.ts b/src/ts/util.ts index 61cdc9c..357c94f 100644 --- a/src/ts/util.ts +++ b/src/ts/util.ts @@ -1,7 +1,7 @@ import axios, { AxiosInstance } from 'axios'; import $ from 'jquery'; import { camelCase, isArray, isObject, mapKeys, mapValues } from 'lodash'; -import { EventInfo, URLInfo, URLType, UserInfo } from './model'; +import { EventInfo, URLInfo, URLType, UserInfo } from '@src/ts/model'; /** * Check the document.URL, return null if current page is not a github page. diff --git a/tsconfig.json b/tsconfig.json index 7b95ad3..84b4d27 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,12 +4,17 @@ "target": "es6", "strict": true, "sourceMap": true, + "baseUrl": ".", + "paths": { + "@src/*": ["src/*"], + }, "rootDir": "src", "outDir": "dist/js", "esModuleInterop": true, "removeComments": true, "moduleResolution": "node" }, + "include": ["src"], "exclude": [ "node_modules", "dist" diff --git a/webpack.config.js b/webpack.config.js index f96ebbb..19b4134 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,21 +1,24 @@ +const fs = require('fs'); const path = require('path'); +const PACKAGE = require('./package.json'); const webpack = require('webpack'); -const fs = require('fs'); function p(f) { return path.join(__dirname, f); } -function f(f) { - return fs.readFileSync(p(f), 'utf8').toString(); -} - module.exports = { mode: process.env.NODE_ENV || 'development', devtool: 'cheap-module-source-map', entry: { main: p('./src/content_script.ts') }, + resolve: { + alias: { + '@src': path.resolve(__dirname, 'src') + }, + extensions: ['.ts', '.tsx', '.js', '.css', '.sass', '.scss'] + }, output: { path: p('./dist'), filename: './github-events.user.js' @@ -24,7 +27,7 @@ module.exports = { rules: [ { test: /\.tsx?$/, - use: ['ts-loader'], + use: 'ts-loader', exclude: /node_modules/ }, { @@ -41,13 +44,18 @@ module.exports = { } ] }, - resolve: { - extensions: ['.ts', '.tsx', '.js', '.css', '.sass', '.scss'] - }, plugins: [ new webpack.BannerPlugin({ raw: true, - banner: f('./src/etc/banner.js') + banner: (() => { + var filename = p('./src/etc/banner.js'); + content = fs.readFileSync(filename, 'utf8').toString(); + content = content.replace(/@@title/g, PACKAGE.title); + content = content.replace(/@@version/g, PACKAGE.version) + content = content.replace(/@@description/g, PACKAGE.description); + content = content.replace(/@@author/g, PACKAGE.author); + return content; + })() }) ] } \ No newline at end of file