├── .github
├── dependabot.yml
└── workflows
│ ├── combinedabot.yml
│ └── nodejs.yml
├── .gitignore
├── .nvmrc
├── .parcelrc
├── .prettierrc
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README-zh.md
├── README.md
├── img
├── chrome-store.png
├── dev-mode.png
├── enterprise.png
├── preview.png
└── reload-link.png
├── package-lock.json
├── package.json
└── src
├── icon-128.png
├── icon-48.png
├── iso.css
├── iso.js
├── manifest-v2.json
├── manifest.json
└── obelisk.min.js
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "npm"
4 | directory: "/"
5 | schedule:
6 | interval: "weekly"
7 | day: "monday"
8 | groups:
9 | parcel:
10 | patterns:
11 | - "@parcel/*"
12 | - "parcel"
13 |
--------------------------------------------------------------------------------
/.github/workflows/combinedabot.yml:
--------------------------------------------------------------------------------
1 | name: 'Combine Dependabot PRs'
2 |
3 | # Controls when the action will run - in this case triggered manually
4 | on:
5 | workflow_dispatch:
6 | inputs:
7 | branchPrefix:
8 | description: 'Branch prefix to find combinable PRs based on'
9 | required: true
10 | default: 'dependabot'
11 | mustBeGreen:
12 | description: 'Only combine PRs that are green (status is success). Set to false if repo does not run checks'
13 | type: boolean
14 | required: true
15 | default: true
16 | combineBranchName:
17 | description: 'Name of the branch to combine PRs into'
18 | required: true
19 | default: 'combine-prs-branch'
20 | ignoreLabel:
21 | description: 'Exclude PRs with this label'
22 | required: true
23 | default: 'nocombine'
24 |
25 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
26 | jobs:
27 | # This workflow contains a single job called "combine-prs"
28 | combine-prs:
29 | # The type of runner that the job will run on
30 | runs-on: ubuntu-latest
31 |
32 | # Steps represent a sequence of tasks that will be executed as part of the job
33 | steps:
34 | - uses: actions/github-script@v6
35 | id: create-combined-pr
36 | name: Create Combined PR
37 | with:
38 | github-token: ${{secrets.GITHUB_TOKEN}}
39 | script: |
40 | const pulls = await github.paginate('GET /repos/:owner/:repo/pulls', {
41 | owner: context.repo.owner,
42 | repo: context.repo.repo
43 | });
44 | let branchesAndPRStrings = [];
45 | let baseBranch = null;
46 | let baseBranchSHA = null;
47 | for (const pull of pulls) {
48 | const branch = pull['head']['ref'];
49 | console.log('Pull for branch: ' + branch);
50 | if (branch.startsWith('${{ github.event.inputs.branchPrefix }}')) {
51 | console.log('Branch matched prefix: ' + branch);
52 | let statusOK = true;
53 | if(${{ github.event.inputs.mustBeGreen }}) {
54 | console.log('Checking green status: ' + branch);
55 | const stateQuery = `query($owner: String!, $repo: String!, $pull_number: Int!) {
56 | repository(owner: $owner, name: $repo) {
57 | pullRequest(number:$pull_number) {
58 | commits(last: 1) {
59 | nodes {
60 | commit {
61 | statusCheckRollup {
62 | state
63 | }
64 | }
65 | }
66 | }
67 | }
68 | }
69 | }`
70 | const vars = {
71 | owner: context.repo.owner,
72 | repo: context.repo.repo,
73 | pull_number: pull['number']
74 | };
75 | const result = await github.graphql(stateQuery, vars);
76 | const [{ commit }] = result.repository.pullRequest.commits.nodes;
77 | const state = commit.statusCheckRollup.state
78 | console.log('Validating status: ' + state);
79 | if(state != 'SUCCESS') {
80 | console.log('Discarding ' + branch + ' with status ' + state);
81 | statusOK = false;
82 | }
83 | }
84 | console.log('Checking labels: ' + branch);
85 | const labels = pull['labels'];
86 | for(const label of labels) {
87 | const labelName = label['name'];
88 | console.log('Checking label: ' + labelName);
89 | if(labelName == '${{ github.event.inputs.ignoreLabel }}') {
90 | console.log('Discarding ' + branch + ' with label ' + labelName);
91 | statusOK = false;
92 | }
93 | }
94 | if (statusOK) {
95 | console.log('Adding branch to array: ' + branch);
96 | const prString = '#' + pull['number'] + ' ' + pull['title'];
97 | branchesAndPRStrings.push({ branch, prString });
98 | baseBranch = pull['base']['ref'];
99 | baseBranchSHA = pull['base']['sha'];
100 | }
101 | }
102 | }
103 | if (branchesAndPRStrings.length == 0) {
104 | core.setFailed('No PRs/branches matched criteria');
105 | return;
106 | }
107 | try {
108 | await github.rest.git.createRef({
109 | owner: context.repo.owner,
110 | repo: context.repo.repo,
111 | ref: 'refs/heads/' + '${{ github.event.inputs.combineBranchName }}',
112 | sha: baseBranchSHA
113 | });
114 | } catch (error) {
115 | console.log(error);
116 | core.setFailed('Failed to create combined branch - maybe a branch by that name already exists?');
117 | return;
118 | }
119 |
120 | let combinedPRs = [];
121 | let mergeFailedPRs = [];
122 | for(const { branch, prString } of branchesAndPRStrings) {
123 | try {
124 | await github.rest.repos.merge({
125 | owner: context.repo.owner,
126 | repo: context.repo.repo,
127 | base: '${{ github.event.inputs.combineBranchName }}',
128 | head: branch,
129 | });
130 | console.log('Merged branch ' + branch);
131 | combinedPRs.push(prString);
132 | } catch (error) {
133 | console.log('Failed to merge branch ' + branch);
134 | mergeFailedPRs.push(prString);
135 | }
136 | }
137 |
138 | console.log('Creating combined PR');
139 | const combinedPRsString = combinedPRs.join('\n');
140 | let body = '✅ This PR was created by the Combine PRs action by combining the following PRs:\n' + combinedPRsString;
141 | if(mergeFailedPRs.length > 0) {
142 | const mergeFailedPRsString = mergeFailedPRs.join('\n');
143 | body += '\n\n⚠️ The following PRs were left out due to merge conflicts:\n' + mergeFailedPRsString
144 | }
145 | await github.rest.pulls.create({
146 | owner: context.repo.owner,
147 | repo: context.repo.repo,
148 | title: 'Combined PR',
149 | head: '${{ github.event.inputs.combineBranchName }}',
150 | base: baseBranch,
151 | body: body
152 | });
153 |
--------------------------------------------------------------------------------
/.github/workflows/nodejs.yml:
--------------------------------------------------------------------------------
1 | name: Node.js CI
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 |
9 | strategy:
10 | matrix:
11 | node-version: [22.x, 24.x]
12 |
13 | steps:
14 | - uses: actions/checkout@v3
15 | - name: Use Node.js ${{ matrix.node-version }}
16 | uses: actions/setup-node@v3
17 | with:
18 | node-version: ${{ matrix.node-version }}
19 | - run: npm install
20 | - run: npm test
21 | env:
22 | CI: true
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | isometric-contributions.zip
2 | .DS_Store
3 | *.un~
4 | node_modules
5 | .direnv
6 | .envrc
7 | src/Archive.zip
8 | .do_tasks
9 | dist
10 | .parcel-cache
11 | .claude
12 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | 13.7.0
2 |
--------------------------------------------------------------------------------
/.parcelrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@parcel/config-webextension"
3 | }
4 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "semi": false,
3 | "trailingComma": "none",
4 | "singleQuote": true,
5 | "printWidth": 120,
6 | "tabWidth": 2,
7 | "useTabs": false,
8 | "jsxSingleQuote": true,
9 | "bracketSpacing": true
10 | }
11 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, caste, color, religion, or sexual
10 | identity and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the overall
26 | community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or advances of
31 | any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email address,
35 | without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | jason@jasonlong.me.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series of
86 | actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or permanent
93 | ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within the
113 | community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.1, available at
119 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120 |
121 | Community Impact Guidelines were inspired by
122 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123 |
124 | For answers to common questions about this code of conduct, see the FAQ at
125 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126 | [https://www.contributor-covenant.org/translations][translations].
127 |
128 | [homepage]: https://www.contributor-covenant.org
129 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130 | [Mozilla CoC]: https://github.com/mozilla/diversity
131 | [FAQ]: https://www.contributor-covenant.org/faq
132 | [translations]: https://www.contributor-covenant.org/translations
133 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Jason Long
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README-zh.md:
--------------------------------------------------------------------------------
1 | # GitHub 立体贡献图浏览器拓展程序
2 |
3 | [英文版](https://github.com/jasonlong/isometric-contributions/blob/main/README.md) | 中文版
4 |
5 | 
6 | [](https://github.com/xojs/xo)
7 |
8 | 这是一个为 Chrome / Brave 和 Firefox 而量身打造的浏览器拓展程序,让你能够在 GitHub 用户档案页面的贡献图处,切换显示原生 2D 图与立体像素版贡献图。我们使用了 [obelisk.js](https://github.com/nosir/obelisk.js) 用于绘制立体图像。
9 |
10 | 除了看起来更整洁干净外,我们的立体图像还很是有趣。它以更高的精细度,突出显示了贡献数量之间的差异。但是这并不意味着完全替代标准2D图形,因为在大多数情况下,它其实也就是个花瓶。例如,图像没有轴标签,较短的条形图可能会被隐藏在较高的条形图后面,而且在我们将鼠标悬停在条形图上时候,我们无法查看到日期和计数等。
11 |
12 |
13 |
14 | ## 安装方式
15 |
16 | ### Chrome / Brave
17 |
18 | [Install from the Chrome Web Store](https://chrome.google.com/webstore/detail/isometric-contributions/mjoedlfflcchnleknnceiplgaeoegien?hl=en&gl=US)
19 |
20 | ### Firefox
21 |
22 | [Install from Mozilla Add-ons site](https://addons.mozilla.org/en-US/firefox/addon/github-isometric-contributions/)
23 |
24 | #### GitHub Enterprise
25 |
26 | 默认情况下,这个拓展程序只会渲染 `github.com` 上的贡献图,而我们可以点击拓展程序图标,选择 `Enable Isometric Contributions on this domain`,手动让拓展程序能够在我们的 Enterprise 版域名上显示。
27 |
28 |
29 |
30 | ## 贡献
31 |
32 | 如果您想自定义扩展程序,那么你可能需要手动安装它。首先先克隆或分叉此仓库,然后,在 Chrome 扩展程序 页面上,选中 “开发人员模式,点击 “加载已解压缩的扩展程序……” 按钮,然后选定仓库所在的文件夹即可。
33 |
34 |
35 |
36 | 要自定义该扩展程序,首先需要确保已在开发人员模式下安装了该扩展程序(参见上文)。对扩展程序进行更改后,请返回 “扩展程序” 页面,然后单击扩展程序条目下的 “重新加载” 链接。
37 |
38 |
39 |
40 | 如果你有什么改进的内容,请随时打开一个拉取请求。
41 |
42 | ## 开源协议
43 |
44 | 本项目以 [MIT License](http://opensource.org/licenses/MIT) 协议开源。
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GitHub Isometric Contributions extension
2 |
3 | 
4 | [](https://github.com/xojs/xo)
5 |
6 | This is a browser extension for Chrome/Brave and Firefox that lets you toggle between your regular GitHub contribution chart and an isometric pixel art version. It uses [obelisk.js](https://github.com/nosir/obelisk.js) for the isometric graphics.
7 |
8 | Besides being sort of neat looking, this view is interesting in that it highlights the differences between the number of contributions with more granularity. This isn't meant to completely replace the standard 2D graph though, because in most ways it is actually less useful. For example, there are no axis labels, shorter bars can be hidden behind taller ones, you can't hover over a bar to see the day and count, etc.
9 |
10 |
11 |
12 | ## Installation
13 |
14 | ### Chrome/Brave
15 |
16 | [Install from the Chrome Web Store](https://chrome.google.com/webstore/detail/isometric-contributions/mjoedlfflcchnleknnceiplgaeoegien?hl=en&gl=US)
17 |
18 | ### Firefox
19 |
20 | [Install from Mozilla Add-ons site](https://addons.mozilla.org/en-US/firefox/addon/github-isometric-contributions/)
21 |
22 | ### Microsoft Edge
23 |
24 | [Install from Microsoft Edge Add-ons site](https://microsoftedge.microsoft.com/addons/detail/github-isometric-contribu/hcicbpfcbdpfgibhlbphodkcbojakpej)
25 |
26 | ## Contributing
27 |
28 | **_Note that I don't currently have any plans for adding new features to the extension. Please contact me before submitting a PR with new functionality._**
29 |
30 | If you want to hack on the extension, you'll need to install it manually. First clone or fork this repo. Then, on your Chrome Extensions page, make sure "Developer mode" is checked. You can then click the "Load unpacked extension..." button and browse to the `src` directory of this repo.
31 |
32 |
33 |
34 | To hack on the extension, you'll first need to make sure you've installed it in Developer mode (see above). Once you've made changes to the extension, go back to the Extensions page and click the Reload link under the extension entry.
35 |
36 |
37 |
38 | ## License
39 |
40 | This project is licensed under the [MIT License](http://opensource.org/licenses/MIT).
41 |
--------------------------------------------------------------------------------
/img/chrome-store.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonlong/isometric-contributions/dc391405f38982fda9111ed64297b1270f8ebd39/img/chrome-store.png
--------------------------------------------------------------------------------
/img/dev-mode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonlong/isometric-contributions/dc391405f38982fda9111ed64297b1270f8ebd39/img/dev-mode.png
--------------------------------------------------------------------------------
/img/enterprise.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonlong/isometric-contributions/dc391405f38982fda9111ed64297b1270f8ebd39/img/enterprise.png
--------------------------------------------------------------------------------
/img/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonlong/isometric-contributions/dc391405f38982fda9111ed64297b1270f8ebd39/img/preview.png
--------------------------------------------------------------------------------
/img/reload-link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonlong/isometric-contributions/dc391405f38982fda9111ed64297b1270f8ebd39/img/reload-link.png
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": "module",
3 | "engines": {
4 | "node": ">=22.0"
5 | },
6 | "scripts": {
7 | "start": "parcel watch src/manifest.json --host localhost",
8 | "build": "parcel build src/manifest.json",
9 | "test": "xo",
10 | "release": "release:*",
11 | "release:ff": "npx web-ext-submit --source-dir src",
12 | "release:chrome": "npx webstore upload --source=isometric-contributions.zip --auto-publish"
13 | },
14 | "dependencies": {
15 | "lodash-es": "^4.17.21"
16 | },
17 | "devDependencies": {
18 | "@parcel/config-webextension": "^2.15.1",
19 | "@parcel/reporter-bundle-analyzer": "^2.15.1",
20 | "@parcel/reporter-bundle-buddy": "^2.15.1",
21 | "chrome-webstore-upload-cli": "^3.3.2",
22 | "parcel": "^2.15.1",
23 | "web-ext-submit": "^7.8.0",
24 | "xo": "^1.0.0"
25 | },
26 | "xo": {
27 | "prettier": true,
28 | "semicolon": false,
29 | "space": true,
30 | "languageOptions": {
31 | "globals": {
32 | "obelisk": "readonly",
33 | "chrome": "readonly",
34 | "document": "readonly",
35 | "localStorage": "readonly",
36 | "getComputedStyle": "readonly",
37 | "MutationObserver": "readonly"
38 | },
39 | "ecmaVersion": "latest",
40 | "sourceType": "module"
41 | },
42 | "rules": {
43 | "unicorn/prefer-top-level-await": 0,
44 | "n/no-unsupported-features/node-builtins": "off"
45 | }
46 | },
47 | "targets": {
48 | "default": {
49 | "engines": {
50 | "browsers": ">= 50%"
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/icon-128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonlong/isometric-contributions/dc391405f38982fda9111ed64297b1270f8ebd39/src/icon-128.png
--------------------------------------------------------------------------------
/src/icon-48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonlong/isometric-contributions/dc391405f38982fda9111ed64297b1270f8ebd39/src/icon-48.png
--------------------------------------------------------------------------------
/src/iso.css:
--------------------------------------------------------------------------------
1 | /* Normal chart display */
2 | .ic-squares #isometric-contributions,
3 | .ic-squares .ic-contributions-wrapper {
4 | display: none;
5 | }
6 |
7 | /* Isometric cube display */
8 | .ic-cubes .contrib-details {
9 | display: none;
10 | }
11 |
12 | .ic-cubes .js-calendar-graph {
13 | display: none ! important;
14 | }
15 |
--------------------------------------------------------------------------------
/src/iso.js:
--------------------------------------------------------------------------------
1 | import { toArray, groupBy, last } from 'lodash-es'
2 |
3 | const dateFormat = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' })
4 | const sameDay = (d1, d2) => d1.toDateString() === d2.toDateString()
5 |
6 | let days
7 | let weeks
8 | let calendarGraph
9 | let contributionsBox
10 | let yearTotal = 0
11 | let weekTotal = 0
12 | let averageCount = 0
13 | let maxCount = 0
14 | let countTotal = 0
15 | let weekCountTotal = 0
16 | let streakLongest = 0
17 | let streakCurrent = 0
18 | let bestDay = null
19 | let firstDay = null
20 | let lastDay = null
21 | let datesTotal = null
22 | let weekStartDay = null
23 | let weekDatesTotal = null
24 | let datesLongest = null
25 | let datesCurrent = null
26 | let dateBest = null
27 | let toggleSetting = 'cubes'
28 |
29 | const resetValues = () => {
30 | yearTotal = 0
31 | averageCount = 0
32 | maxCount = 0
33 | streakLongest = 0
34 | streakCurrent = 0
35 | weekTotal = 0
36 | bestDay = null
37 | firstDay = null
38 | lastDay = null
39 | datesLongest = null
40 | datesCurrent = null
41 | weekStartDay = null
42 | }
43 |
44 | const getSettings = () => {
45 | return new Promise((resolve) => {
46 | // Check for user preference, if chrome.storage is available.
47 | // The storage API is not supported in content scripts.
48 | // https://developer.mozilla.org/Add-ons/WebExtensions/Chrome_incompatibilities#storage
49 | if (typeof chrome !== 'undefined' && chrome.storage && chrome.storage.local) {
50 | chrome.storage.local.get(['toggleSetting'], (settings) => {
51 | toggleSetting = settings.toggleSetting ?? 'cubes'
52 | resolve('Settings loaded')
53 | })
54 | } else {
55 | toggleSetting = localStorage.toggleSetting ?? 'cubes'
56 | resolve('Settings loaded')
57 | }
58 | })
59 | }
60 |
61 | const persistSetting = (key, value) => {
62 | if (chrome && chrome.storage) {
63 | const object = {}
64 | object[key] = value
65 | chrome.storage.local.set(object)
66 | } else {
67 | localStorage[key] = value
68 | }
69 | }
70 |
71 | const initUI = () => {
72 | const contributionsWrapper = document.createElement('div')
73 | contributionsWrapper.className = 'ic-contributions-wrapper position-relative'
74 | calendarGraph.before(contributionsWrapper)
75 |
76 | const canvas = document.createElement('canvas')
77 | canvas.id = 'isometric-contributions'
78 | canvas.width = 1000
79 | canvas.height = 600
80 | canvas.style.width = '100%'
81 | contributionsWrapper.append(canvas)
82 |
83 | // Inject toggle
84 | let insertLocation = contributionsBox.querySelector('h2')
85 | if (insertLocation.previousElementSibling && insertLocation.previousElementSibling.nodeName === 'DETAILS') {
86 | insertLocation = insertLocation.previousElementSibling
87 | }
88 |
89 | const buttonGroup = document.createElement('div')
90 | buttonGroup.className = 'BtnGroup mt-1 ml-3 position-relative top-0 float-right'
91 |
92 | const squaresButton = document.createElement('button')
93 | squaresButton.innerHTML = '2D'
94 | squaresButton.className = 'ic-toggle-option squares btn BtnGroup-item btn-sm py-0 px-1'
95 | squaresButton.dataset.icOption = 'squares'
96 | squaresButton.addEventListener('click', handleViewToggle)
97 | if (toggleSetting === 'squares') {
98 | squaresButton.classList.add('selected')
99 | }
100 |
101 | const cubesButton = document.createElement('button')
102 | cubesButton.innerHTML = '3D'
103 | cubesButton.className = 'ic-toggle-option cubes btn BtnGroup-item btn-sm py-0 px-1'
104 | cubesButton.dataset.icOption = 'cubes'
105 | cubesButton.addEventListener('click', handleViewToggle)
106 | if (toggleSetting === 'cubes') {
107 | cubesButton.classList.add('selected')
108 | }
109 |
110 | buttonGroup.append(squaresButton)
111 | buttonGroup.append(cubesButton)
112 | insertLocation.before(buttonGroup)
113 |
114 | setContainerViewType(toggleSetting)
115 | }
116 |
117 | const handleViewToggle = (event) => {
118 | setContainerViewType(event.target.dataset.icOption)
119 |
120 | for (const toggle of document.querySelectorAll('.ic-toggle-option')) {
121 | toggle.classList.remove('selected')
122 | }
123 |
124 | event.target.classList.add('selected')
125 |
126 | persistSetting('toggleSetting', event.target.dataset.icOption)
127 | toggleSetting = event.target.dataset.icOption
128 |
129 | // Apply user preference
130 | document.querySelector(`.ic-toggle-option.${toggleSetting}`).classList.add('selected')
131 | contributionsBox.classList.add(`ic-${toggleSetting}`)
132 | }
133 |
134 | const setContainerViewType = (type) => {
135 | if (type === 'squares') {
136 | contributionsBox.classList.remove('ic-cubes')
137 | contributionsBox.classList.add('ic-squares')
138 | } else {
139 | contributionsBox.classList.remove('ic-squares')
140 | contributionsBox.classList.add('ic-cubes')
141 | }
142 | }
143 |
144 | const getCountFromNode = (node) => {
145 | // Contribution label formats:
146 | // No contributions on January 9th
147 | // 1 contribution on January 10th.
148 | // 2 contributions on August 31st.
149 | const contributionMatches = node.innerHTML.match(/(\d*|No) contributions? on (.*)./)
150 |
151 | if (!contributionMatches) {
152 | return 0
153 | }
154 |
155 | const dataCount = contributionMatches[1]
156 | return dataCount === 'No' ? 0 : Number.parseInt(dataCount, 10)
157 | }
158 |
159 | const getSquareColor = (rect) => {
160 | return rgbToHex(getComputedStyle(rect).getPropertyValue('fill'))
161 | }
162 |
163 | const loadStats = () => {
164 | let temporaryStreak = 0
165 | let temporaryStreakStart = null
166 | let longestStreakStart = null
167 | let longestStreakEnd = null
168 | let currentStreakStart = null
169 | let currentStreakEnd = null
170 |
171 | const dayNodes = [...document.querySelectorAll('.js-calendar-graph-table tbody td.ContributionCalendar-day')].map(
172 | (d) => {
173 | return {
174 | date: new Date(d.dataset.date),
175 | week: d.dataset.ix,
176 | color: getSquareColor(d),
177 | tid: d.getAttribute('aria-labelledby')
178 | }
179 | }
180 | )
181 |
182 | const tooltipNodes = [...document.querySelectorAll('.js-calendar-graph tool-tip')].map((t) => {
183 | return {
184 | tid: t.id,
185 | count: getCountFromNode(t)
186 | }
187 | })
188 |
189 | const data = dayNodes.map((d) => {
190 | return {
191 | ...d,
192 | ...tooltipNodes.find((t) => t.tid === d.tid)
193 | }
194 | })
195 |
196 | days = data.sort((a, b) => a.date.getTime() - b.date.getTime())
197 | weeks = toArray(groupBy(days, 'week'))
198 | const currentWeekDays = last(weeks)
199 |
200 | for (const d of days) {
201 | const currentDayCount = d.count
202 | yearTotal += currentDayCount
203 |
204 | if (days[0] === d) {
205 | firstDay = d.date
206 | }
207 |
208 | if (sameDay(d.date, new Date())) {
209 | lastDay = d.date
210 | } else if (!lastDay && days.at(-1) === d) {
211 | lastDay = d.date
212 | }
213 |
214 | // Check for best day
215 | if (currentDayCount > maxCount) {
216 | bestDay = d.date
217 | maxCount = currentDayCount
218 | }
219 |
220 | // Check for longest streak
221 | if (currentDayCount > 0) {
222 | if (temporaryStreak === 0) {
223 | temporaryStreakStart = d.date
224 | }
225 |
226 | temporaryStreak++
227 |
228 | if (temporaryStreak >= streakLongest) {
229 | longestStreakStart = temporaryStreakStart
230 | longestStreakEnd = d.date
231 | streakLongest = temporaryStreak
232 | }
233 | } else {
234 | temporaryStreak = 0
235 | temporaryStreakStart = null
236 | }
237 | }
238 |
239 | for (const d of currentWeekDays) {
240 | const currentDayCount = d.count
241 | weekTotal += currentDayCount
242 |
243 | if (currentWeekDays[0] === d) {
244 | weekStartDay = d.date
245 | }
246 | }
247 |
248 | // Check for current streak
249 | const reversedDays = days
250 | reversedDays.reverse()
251 | currentStreakEnd = reversedDays[0].date
252 |
253 | for (let i = 0; i < reversedDays.length; i++) {
254 | const currentDayCount = reversedDays[i].count
255 | // If there's no activity today, continue on to yesterday
256 | if (i === 0 && currentDayCount === 0) {
257 | currentStreakEnd = reversedDays[1].date
258 | continue
259 | }
260 |
261 | if (currentDayCount > 0) {
262 | streakCurrent++
263 | currentStreakStart = reversedDays[i].date
264 | } else {
265 | break
266 | }
267 | }
268 |
269 | if (streakCurrent > 0) {
270 | currentStreakStart = dateFormat.format(currentStreakStart)
271 | currentStreakEnd = dateFormat.format(currentStreakEnd)
272 | datesCurrent = `${currentStreakStart} → ${currentStreakEnd}`
273 | } else {
274 | datesCurrent = 'No current streak'
275 | }
276 |
277 | // Year total
278 | countTotal = yearTotal.toLocaleString()
279 | const dateFirst = dateFormat.format(firstDay)
280 | const dateLast = dateFormat.format(lastDay)
281 | datesTotal = `${dateFirst} → ${dateLast}`
282 |
283 | // Average contributions per day
284 | const dayDifference = datesDayDifference(firstDay, lastDay)
285 | averageCount = precisionRound(yearTotal / dayDifference, 2)
286 |
287 | // Best day
288 | dateBest = dateFormat.format(bestDay)
289 | dateBest ||= 'No activity found'
290 |
291 | // Longest streak
292 | if (streakLongest > 0) {
293 | longestStreakStart = dateFormat.format(longestStreakStart)
294 | longestStreakEnd = dateFormat.format(longestStreakEnd)
295 | datesLongest = `${longestStreakStart} → ${longestStreakEnd}`
296 | } else {
297 | datesLongest = 'No longest streak'
298 | }
299 |
300 | // Week total
301 | weekCountTotal = weekTotal.toLocaleString()
302 | const weekDateFirst = dateFormat.format(weekStartDay)
303 | weekDatesTotal = `${weekDateFirst} → ${dateLast}`
304 | }
305 |
306 | const rgbToHex = (rgb) => {
307 | const separator = rgb.includes(',') ? ',' : ' '
308 | rgb = rgb.slice(4).split(')')[0].split(separator)
309 |
310 | let r = Number(rgb[0]).toString(16)
311 | let g = Number(rgb[1]).toString(16)
312 | let b = Number(rgb[2]).toString(16)
313 |
314 | if (r.length === 1) {
315 | r = '0' + r
316 | }
317 |
318 | if (g.length === 1) {
319 | g = '0' + g
320 | }
321 |
322 | if (b.length === 1) {
323 | b = '0' + b
324 | }
325 |
326 | return r + g + b
327 | }
328 |
329 | const renderIsometricChart = () => {
330 | const SIZE = 16
331 | const MAX_HEIGHT = 100
332 | const GH_OFFSET = 14
333 | const canvas = document.querySelector('#isometric-contributions')
334 | const point = new obelisk.Point(130, 90)
335 | const pixelView = new obelisk.PixelView(canvas, point)
336 |
337 | let transform = GH_OFFSET
338 |
339 | for (const w of weeks) {
340 | const x = transform / (GH_OFFSET + 1)
341 | transform += GH_OFFSET
342 | let offsetY = 0 // Hardcode the old y of rect value.
343 | for (const d of w) {
344 | const y = offsetY / GH_OFFSET
345 | offsetY += 13
346 | const currentDayCount = d.count
347 | let cubeHeight = 3
348 |
349 | if (maxCount > 0) {
350 | cubeHeight += Number.parseInt((MAX_HEIGHT / maxCount) * currentDayCount, 10)
351 | }
352 |
353 | const dimension = new obelisk.CubeDimension(SIZE, SIZE, cubeHeight)
354 | const color = new obelisk.CubeColor().getByHorizontalColor(Number.parseInt(d.color, 16))
355 | const cube = new obelisk.Cube(dimension, color, false)
356 | const p3d = new obelisk.Point3D(SIZE * x, SIZE * y, 0)
357 | pixelView.renderObject(cube, p3d)
358 | }
359 | }
360 | }
361 |
362 | const renderStats = () => {
363 | const graphHeaderText =
364 | document.querySelector('.ic-contributions-wrapper').parentNode.previousElementSibling.textContent
365 | const viewingYear = graphHeaderText.match(/in \d{4}/g) !== null
366 |
367 | let topMarkup = `
368 |
395 | Average: ${averageCount} / day 396 |
397 |