diff --git a/CHANGELOG.md b/CHANGELOG.md index e75bbc7..c2065ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.1.0 +- Updated extension to pull colours from https://github.com/ozh/github-colors + - colours are loaded every week, which roughly coincides with how often the above repo is updated +- Updated to manifest v3 to bring back the chrome version + - also removed the background script from the distributed version since it was only for 0.1.9 integrity issues +- Setting up project to be also used within my personal website + # 1.0.13 - Pulling in dependabot pull requests - Fixing organisation page displays diff --git a/dist/colors.json b/dist/colors.json deleted file mode 100644 index 09891b6..0000000 --- a/dist/colors.json +++ /dev/null @@ -1 +0,0 @@ -{"1C Enterprise": "#814CCC", "2-Dimensional Array": "#38761D", "4D": "#004289", "ABAP": "#E8274B", "ABAP CDS": "#555e25", "AGS Script": "#B9D9FF", "AIDL": "#34EB6B", "AL": "#3AA2B5", "AMPL": "#E6EFBB", "ANTLR": "#9DC3FF", "API Blueprint": "#2ACCA8", "APL": "#5A8164", "ASP.NET": "#9400ff", "ATS": "#1ac620", "ActionScript": "#882B0F", "Ada": "#02f88c", "Adobe Font Metrics": "#fa0f00", "Agda": "#315665", "Alloy": "#64C800", "Alpine Abuild": "#0D597F", "Altium Designer": "#A89663", "AngelScript": "#C7D7DC", "Ant Build System": "#A9157E", "Antlers": "#ff269e", "ApacheConf": "#d12127", "Apex": "#1797c0", "Apollo Guidance Computer": "#0B3D91", "AppleScript": "#101F1F", "Arc": "#aa2afe", "AsciiDoc": "#73a0c5", "AspectJ": "#a957b0", "Assembly": "#6E4C13", "Astro": "#ff5a03", "Asymptote": "#ff0000", "Augeas": "#9CC134", "AutoHotkey": "#6594b9", "AutoIt": "#1C3552", "Avro IDL": "#0040FF", "Awk": "#c30e9b", "BASIC": "#ff0000", "Ballerina": "#FF5000", "Batchfile": "#C1F12E", "Beef": "#a52f4e", "Berry": "#15A13C", "BibTeX": "#778899", "Bicep": "#519aba", "Bikeshed": "#5562ac", "Bison": "#6A463F", "BitBake": "#00bce4", "Blade": "#f7523f", "BlitzBasic": "#00FFAE", "BlitzMax": "#cd6400", "Bluespec": "#12223c", "Boo": "#d4bec1", "Boogie": "#c80fa0", "Brainfuck": "#2F2530", "BrighterScript": "#66AABB", "Brightscript": "#662D91", "Browserslist": "#ffd539", "C": "#555555", "C#": "#178600", "C++": "#f34b7d", "CAP CDS": "#0092d1", "CLIPS": "#00A300", "CMake": "#DA3434", "COLLADA": "#F1A42B", "CSON": "#244776", "CSS": "#563d7c", "CSV": "#237346", "CUE": "#5886E1", "CWeb": "#00007a", "Cabal Config": "#483465", "Cadence": "#00ef8b", "Cairo": "#ff4a48", "CameLIGO": "#3be133", "Cap'n Proto": "#c42727", "Ceylon": "#dfa535", "Chapel": "#8dc63f", "ChucK": "#3f8000", "Cirru": "#ccccff", "Clarion": "#db901e", "Clarity": "#5546ff", "Classic ASP": "#6a40fd", "Clean": "#3F85AF", "Click": "#E4E6F3", "Clojure": "#db5855", "Closure Templates": "#0d948f", "Cloud Firestore Security Rules": "#FFA000", "CodeQL": "#140f46", "CoffeeScript": "#244776", "ColdFusion": "#ed2cd6", "ColdFusion CFC": "#ed2cd6", "Common Lisp": "#3fb68b", "Common Workflow Language": "#B5314C", "Component Pascal": "#B0CE4E", "Coq": "#d0b68c", "Crystal": "#000100", "Csound": "#1a1a1a", "Csound Document": "#1a1a1a", "Csound Score": "#1a1a1a", "Cuda": "#3A4E3A", "Curry": "#531242", "Cython": "#fedf5b", "D": "#ba595e", "DM": "#447265", "Dafny": "#FFEC25", "Darcs Patch": "#8eff23", "Dart": "#00B4AB", "DataWeave": "#003a52", "Debian Package Control File": "#D70751", "DenizenScript": "#FBEE96", "Dhall": "#dfafff", "DirectX 3D File": "#aace60", "Dockerfile": "#384d54", "Dogescript": "#cca760", "Dylan": "#6c616e", "E": "#ccce35", "ECL": "#8a1267", "ECLiPSe": "#001d9d", "EJS": "#a91e50", "EQ": "#a78649", "Earthly": "#2af0ff", "Easybuild": "#069406", "Ecere Projects": "#913960", "EditorConfig": "#fff1f2", "Eiffel": "#4d6977", "Elixir": "#6e4a7e", "Elm": "#60B5CC", "Emacs Lisp": "#c065db", "EmberScript": "#FFF4F3", "Erlang": "#B83998", "Euphoria": "#FF790B", "F#": "#b845fc", "F*": "#572e30", "FIGlet Font": "#FFDDBB", "FLUX": "#88ccff", "Factor": "#636746", "Fancy": "#7b9db4", "Fantom": "#14253c", "Faust": "#c37240", "Fennel": "#fff3d7", "Filebench WML": "#F6B900", "Fluent": "#ffcc33", "Forth": "#341708", "Fortran": "#4d41b1", "Fortran Free Form": "#4d41b1", "FreeBasic": "#867db1", "FreeMarker": "#0050b2", "Frege": "#00cafe", "Futhark": "#5f021f", "G-code": "#D08CF2", "GAML": "#FFC766", "GAMS": "#f49a22", "GAP": "#0000cc", "GCC Machine Description": "#FFCFAB", "GDScript": "#355570", "GEDCOM": "#003058", "GLSL": "#5686a5", "GSC": "#FF6800", "Game Maker Language": "#71b417", "Gemfile.lock": "#701516", "Genero": "#63408e", "Genero Forms": "#d8df39", "Genie": "#fb855d", "Genshi": "#951531", "Gentoo Ebuild": "#9400ff", "Gentoo Eclass": "#9400ff", "Gerber Image": "#d20b00", "Gherkin": "#5B2063", "Git Attributes": "#F44D27", "Git Config": "#F44D27", "Git Revision List": "#F44D27", "Gleam": "#ffaff3", "Glyph": "#c1ac7f", "Gnuplot": "#f0a9f0", "Go": "#00ADD8", "Go Checksums": "#00ADD8", "Go Module": "#00ADD8", "Golo": "#88562A", "Gosu": "#82937f", "Grace": "#615f8b", "Gradle": "#02303a", "Grammatical Framework": "#ff0000", "GraphQL": "#e10098", "Graphviz (DOT)": "#2596be", "Groovy": "#4298b8", "Groovy Server Pages": "#4298b8", "HAProxy": "#106da9", "HLSL": "#aace60", "HTML": "#e34c26", "HTML+ECR": "#2e1052", "HTML+EEX": "#6e4a7e", "HTML+ERB": "#701516", "HTML+PHP": "#4f5d95", "HTML+Razor": "#512be4", "HTTP": "#005C9C", "HXML": "#f68712", "Hack": "#878787", "Haml": "#ece2a9", "Handlebars": "#f7931e", "Harbour": "#0e60e3", "Haskell": "#5e5086", "Haxe": "#df7900", "HiveQL": "#dce200", "HolyC": "#ffefaf", "Hy": "#7790B2", "IDL": "#a3522f", "IGOR Pro": "#0000cc", "INI": "#d1dbe0", "Idris": "#b30000", "Ignore List": "#000000", "ImageJ Macro": "#99AAFF", "Inno Setup": "#264b99", "Io": "#a9188d", "Ioke": "#078193", "Isabelle": "#FEFE00", "Isabelle ROOT": "#FEFE00", "J": "#9EEDFF", "JAR Manifest": "#b07219", "JFlex": "#DBCA00", "JSON": "#292929", "JSON with Comments": "#292929", "JSON5": "#267CB9", "JSONLD": "#0c479c", "JSONiq": "#40d47e", "Janet": "#0886a5", "Jasmin": "#d03600", "Java": "#b07219", "Java Properties": "#2A6277", "Java Server Pages": "#2A6277", "JavaScript": "#f1e05a", "JavaScript+ERB": "#f1e05a", "Jest Snapshot": "#15c213", "JetBrains MPS": "#21D789", "Jinja": "#a52a22", "Jison": "#56b3cb", "Jison Lex": "#56b3cb", "Jolie": "#843179", "Jsonnet": "#0064bd", "Julia": "#a270ba", "Jupyter Notebook": "#DA5B0B", "KRL": "#28430A", "Kaitai Struct": "#773b37", "KakouneScript": "#6f8042", "KiCad Layout": "#2f4aab", "KiCad Legacy Layout": "#2f4aab", "KiCad Schematic": "#2f4aab", "Kotlin": "#A97BFF", "LFE": "#4C3023", "LLVM": "#185619", "LOLCODE": "#cc9900", "LSL": "#3d9970", "LabVIEW": "#fede06", "Lark": "#2980B9", "Lasso": "#999999", "Latte": "#f2a542", "Less": "#1d365d", "Lex": "#DBCA00", "LigoLANG": "#0e74ff", "LilyPond": "#9ccc7c", "Liquid": "#67b8de", "Literate Agda": "#315665", "Literate CoffeeScript": "#244776", "Literate Haskell": "#5e5086", "LiveScript": "#499886", "Logtalk": "#295b9a", "LookML": "#652B81", "Lua": "#000080", "MATLAB": "#e16737", "MAXScript": "#00a6a6", "MLIR": "#5EC8DB", "MQL4": "#62A8D6", "MQL5": "#4A76B8", "MTML": "#b7e1f4", "Macaulay2": "#d8ffff", "Makefile": "#427819", "Mako": "#7e858d", "Markdown": "#083fa1", "Marko": "#42bff2", "Mask": "#f97732", "Mathematica": "#dd1100", "Max": "#c4a79c", "Mercury": "#ff2b2b", "Meson": "#007800", "Metal": "#8f14e9", "MiniYAML": "#ff1111", "Mint": "#02b046", "Mirah": "#c7a938", "Modelica": "#de1d31", "Modula-2": "#10253f", "Modula-3": "#223388", "Monkey C": "#8D6747", "MoonScript": "#ff4585", "Motoko": "#fbb03b", "Motorola 68K Assembly": "#005daa", "Mustache": "#724b3b", "NCL": "#28431f", "NPM Config": "#cb3837", "NWScript": "#111522", "Nearley": "#990000", "Nemerle": "#3d3c6e", "NetLinx": "#0aa0ff", "NetLinx+ERB": "#747faa", "NetLogo": "#ff6375", "NewLisp": "#87AED7", "Nextflow": "#3ac486", "Nginx": "#009639", "Nim": "#ffc200", "Nit": "#009917", "Nix": "#7e7eff", "Nu": "#c9df40", "NumPy": "#9C8AF9", "Nunjucks": "#3d8137", "OCaml": "#3be133", "ObjectScript": "#424893", "Objective-C": "#438eff", "Objective-C++": "#6866fb", "Objective-J": "#ff0c5a", "Odin": "#60AFFE", "Omgrofl": "#cabbff", "Opal": "#f7ede0", "Open Policy Agent": "#7d9199", "OpenCL": "#ed2e2d", "OpenEdge ABL": "#5ce600", "OpenQASM": "#AA70FF", "OpenSCAD": "#e5cd45", "Org": "#77aa99", "Oxygene": "#cdd0e3", "Oz": "#fab738", "P4": "#7055b5", "PEG.js": "#234d6b", "PHP": "#4F5D95", "PLSQL": "#dad8d8", "PLpgSQL": "#336790", "POV-Ray SDL": "#6bac65", "Pan": "#cc0000", "Papyrus": "#6600cc", "Parrot": "#f3ca0a", "Pascal": "#E3F171", "Pawn": "#dbb284", "Pep8": "#C76F5B", "Perl": "#0298c3", "PicoLisp": "#6067af", "PigLatin": "#fcd7de", "Pike": "#005390", "PogoScript": "#d80074", "Portugol": "#f8bd00", "PostCSS": "#dc3a0c", "PostScript": "#da291c", "PowerBuilder": "#8f0f8d", "PowerShell": "#012456", "Prisma": "#0c344b", "Processing": "#0096D8", "Procfile": "#3B2F63", "Prolog": "#74283c", "Promela": "#de0000", "Propeller Spin": "#7fa2a7", "Pug": "#a86454", "Puppet": "#302B6D", "PureBasic": "#5a6986", "PureScript": "#1D222D", "Python": "#3572A5", "Python console": "#3572A5", "Python traceback": "#3572A5", "Q#": "#fed659", "QML": "#44a51c", "Qt Script": "#00b841", "Quake": "#882233", "R": "#198CE7", "RAML": "#77d9fb", "RDoc": "#701516", "REXX": "#d90e09", "RMarkdown": "#198ce7", "RPGLE": "#2BDE21", "RUNOFF": "#665a4e", "Racket": "#3c5caa", "Ragel": "#9d5200", "Raku": "#0000fb", "Rascal": "#fffaa0", "ReScript": "#ed5051", "Reason": "#ff5847", "ReasonLIGO": "#ff5847", "Rebol": "#358a5b", "Record Jar": "#0673ba", "Red": "#f50000", "Regular Expression": "#009a00", "Ren'Py": "#ff7f7f", "Ring": "#2D54CB", "Riot": "#A71E49", "RobotFramework": "#00c0b5", "Roff": "#ecdebe", "Roff Manpage": "#ecdebe", "Rouge": "#cc0088", "Ruby": "#701516", "Rust": "#dea584", "SAS": "#B34936", "SCSS": "#c6538c", "SPARQL": "#0C4597", "SQF": "#3F3F3F", "SQL": "#e38c00", "SQLPL": "#e38c00", "SRecode Template": "#348a34", "STL": "#373b5e", "SVG": "#ff9900", "SaltStack": "#646464", "Sass": "#a53b70", "Scala": "#c22d40", "Scaml": "#bd181a", "Scheme": "#1e4aec", "Scilab": "#ca0f21", "Self": "#0579aa", "ShaderLab": "#222c37", "Shell": "#89e051", "ShellCheck Config": "#cecfcb", "Shen": "#120F14", "Singularity": "#64E6AD", "Slash": "#007eff", "Slice": "#003fa2", "Slim": "#2b2b2b", "SmPL": "#c94949", "Smalltalk": "#596706", "Smarty": "#f0c040", "Solidity": "#AA6746", "SourcePawn": "#f69e1d", "Squirrel": "#800000", "Stan": "#b2011d", "Standard ML": "#dc566d", "Starlark": "#76d275", "Stata": "#1a5f91", "StringTemplate": "#3fb34f", "Stylus": "#ff6347", "SubRip Text": "#9e0101", "SugarSS": "#2fcc9f", "SuperCollider": "#46390b", "Svelte": "#ff3e00", "Swift": "#F05138", "SystemVerilog": "#DAE1C2", "TI Program": "#A0AA87", "TLA": "#4b0079", "TOML": "#9c4221", "TSQL": "#e38c00", "TSV": "#237346", "TSX": "#3178c6", "TXL": "#0178b8", "Talon": "#333333", "Tcl": "#e4cc98", "TeX": "#3D6117", "Terra": "#00004c", "TextMate Properties": "#df66e4", "Textile": "#ffe7ac", "Thrift": "#D12127", "Turing": "#cf142b", "Twig": "#c1d026", "TypeScript": "#3178c6", "Unified Parallel C": "#4e3617", "Unity3D Asset": "#222c37", "Uno": "#9933cc", "UnrealScript": "#a54c4d", "UrWeb": "#ccccee", "V": "#4f87c4", "VBA": "#867db1", "VBScript": "#15dcdc", "VCL": "#148AA8", "VHDL": "#adb2cb", "Vala": "#a56de2", "Valve Data Format": "#f26025", "Verilog": "#b2b7f8", "Vim Help File": "#199f4b", "Vim Script": "#199f4b", "Vim Snippet": "#199f4b", "Visual Basic .NET": "#945db7", "Volt": "#1F1F1F", "Vue": "#41b883", "Vyper": "#2980b9", "Web Ontology Language": "#5b70bd", "WebAssembly": "#04133b", "Whiley": "#d5c397", "Wikitext": "#fc5757", "Windows Registry Entries": "#52d5ff", "Witcher Script": "#ff0000", "Wollok": "#a23738", "World of Warcraft Addon Data": "#f7e43f", "X10": "#4B6BEF", "XC": "#99DA07", "XML": "#0060ac", "XML Property List": "#0060ac", "XQuery": "#5232e7", "XSLT": "#EB8CEB", "Xojo": "#81bd41", "Xonsh": "#285EEF", "Xtend": "#24255d", "YAML": "#cb171e", "YARA": "#220000", "YASnippet": "#32AB90", "Yacc": "#4B6C4B", "Yul": "#794932", "ZAP": "#0d665e", "ZIL": "#dc75e5", "ZenScript": "#00BCD1", "Zephir": "#118f9e", "Zig": "#ec915c", "Zimpl": "#d67711", "eC": "#913960", "fish": "#4aae47", "hoon": "#00b171", "jq": "#c7254e", "kvlang": "#1da6e0", "mIRC Script": "#3d57c3", "mcfunction": "#E22837", "mupad": "#244963", "nanorc": "#2d004d", "nesC": "#94B0C7", "ooc": "#b0b77e", "q": "#0040cd", "reStructuredText": "#141414", "sed": "#64b970", "wdl": "#42f1f4", "wisp": "#7582D1", "xBase": "#403a40"} \ No newline at end of file diff --git a/dist/manifest.json b/dist/manifest.json index 0fe4dba..4b2092a 100644 --- a/dist/manifest.json +++ b/dist/manifest.json @@ -1,15 +1,9 @@ { - "author": "freyamade", - "background": { - "persistent": false, - "scripts": [ - "js/background.js" - ] - }, - "browser_action": { + "action": { "default_icon": "images/github-user-languages.128.png", "default_popup": "popup.html" }, + "author": "freyamade", "browser_specific_settings": { "gecko": { "id": "extension@github-user-languages.github.com" @@ -27,18 +21,18 @@ } ], "description": "See the language usage breakdown of a User or Org right on their GitHub profile page.", + "host_permissions": [ + "https://api.github.com/", + "https://raw.githubusercontent.com/ozh/github-colors/master/colors.json" + ], "icons": { "128": "images/github-user-languages.128.png" }, - "manifest_version": 2, + "manifest_version": 3, "name": "GitHub User Languages", "permissions": [ - "https://api.github.com/", "storage" ], "short_name": "github-user-languages", - "version": "1.0.13", - "web_accessible_resources": [ - "colors.json" - ] -} + "version": "1.1.0" +} \ No newline at end of file diff --git a/dist/popup.html b/dist/popup.html index e7e4684..e240071 100644 --- a/dist/popup.html +++ b/dist/popup.html @@ -37,7 +37,7 @@

API Token Click out of input to save

If you wish to be able to see your own private repos in the chart, be sure to select the repo scope for the token also.

diff --git a/get-colors.py b/get-colors.py deleted file mode 100644 index eef1669..0000000 --- a/get-colors.py +++ /dev/null @@ -1,15 +0,0 @@ -# Cloned for https://github.com/doda/github-language-colors -import subprocess -import yaml -import json -import os - -subprocess.call(['wget', 'https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml', '-q']) - -with open('languages.yml') as f: - langs = yaml.load(f, Loader=yaml.FullLoader) -os.remove('languages.yml') -colors = {name: lang['color'] for name, lang in langs.items() if 'color' in lang} - -with open('dist/colors.json', 'w') as f: - json.dump(colors, f) diff --git a/package-lock.json b/package-lock.json index 1aa79ff..f781ccd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "github-user-languages", - "version": "1.0.13", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "github-user-languages", - "version": "1.0.13", + "version": "1.1.0", "license": "MIT", "dependencies": { "chart.js": "^3.4.0" @@ -134,9 +134,9 @@ } }, "node_modules/@types/eslint": { - "version": "7.2.13", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.2.13.tgz", - "integrity": "sha512-LKmQCWAlnVHvvXq4oasNUMTJJb2GwSyTY8+1C7OH5ILR8mPLaljv1jxL1bXW3xB3jFbQxTKxJAvI8PyjB09aBg==", + "version": "8.44.3", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.3.tgz", + "integrity": "sha512-iM/WfkwAhwmPff3wZuPLYiHX18HI24jU8k1ZSH7P8FHwxTjZ2P6CoX2wnF43oprR+YXJM6UUxATkNvyv/JHd+g==", "dev": true, "dependencies": { "@types/estree": "*", @@ -144,9 +144,9 @@ } }, "node_modules/@types/eslint-scope": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.0.tgz", - "integrity": "sha512-O/ql2+rrCUe2W2rs7wMR+GqPRcgB6UiqN5RhrR5xruFlY7l9YLMn0ZkDzjoHLeiFkR8MCQZVudUuuvQ2BLC9Qw==", + "version": "3.7.5", + "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.5.tgz", + "integrity": "sha512-JNvhIEyxVW6EoMIFIvj93ZOywYFatlpu9deeH6eSx6PE3WHYvHaQtmHmQeNw7aA81bYGBPPQqdtBm6b1SsQMmA==", "dev": true, "dependencies": { "@types/eslint": "*", @@ -154,9 +154,9 @@ } }, "node_modules/@types/estree": { - "version": "0.0.48", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.48.tgz", - "integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==", + "version": "0.0.51", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.51.tgz", + "integrity": "sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==", "dev": true }, "node_modules/@types/filesystem": { @@ -181,9 +181,9 @@ "dev": true }, "node_modules/@types/json-schema": { - "version": "7.0.7", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz", - "integrity": "sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==", + "version": "7.0.13", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.13.tgz", + "integrity": "sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ==", "dev": true }, "node_modules/@types/node": { @@ -386,6 +386,18 @@ "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", "dev": true }, + "node_modules/acorn": { + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", + "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -636,9 +648,9 @@ "dev": true }, "node_modules/enhanced-resolve": { - "version": "5.8.2", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz", - "integrity": "sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==", + "version": "5.15.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz", + "integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==", "dev": true, "dependencies": { "graceful-fs": "^4.2.4", @@ -822,9 +834,9 @@ "dev": true }, "node_modules/graceful-fs": { - "version": "4.2.6", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", - "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==", + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true }, "node_modules/has": { @@ -1397,12 +1409,12 @@ "dev": true }, "node_modules/schema-utils": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.0.0.tgz", - "integrity": "sha512-6D82/xSzO094ajanoOSbe4YvXWMfn2A//8Y1+MUqFAJul5Bs+yn36xbK9OtNDcRVSBJ9jjeoXftM6CfztsjOAA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", + "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", "dev": true, "dependencies": { - "@types/json-schema": "^7.0.6", + "@types/json-schema": "^7.0.8", "ajv": "^6.12.5", "ajv-keywords": "^3.5.2" }, @@ -1760,6 +1772,19 @@ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, + "node_modules/watchpack": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", + "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", + "dev": true, + "dependencies": { + "glob-to-regexp": "^0.4.1", + "graceful-fs": "^4.1.2" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/webpack": { "version": "5.42.0", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.42.0.tgz", @@ -1926,9 +1951,9 @@ } }, "node_modules/webpack-sources": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-2.3.0.tgz", - "integrity": "sha512-WyOdtwSvOML1kbgtXbTDnEW0jkJ7hZr/bDByIwszhWd/4XX1A3XMkrbFMsuH4+/MfLlZCUzlAdg4r7jaGKEIgQ==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-2.3.1.tgz", + "integrity": "sha512-y9EI9AO42JjEcrTJFOYmVywVZdKVUfOvDUPsJea5GIr1JOEGFVqwlY2K098fFoIjOkDzHn2AjRvM8dsBZu+gCA==", "dev": true, "dependencies": { "source-list-map": "^2.0.1", @@ -1938,30 +1963,11 @@ "node": ">=10.13.0" } }, - "node_modules/webpack/node_modules/acorn": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz", - "integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==", - "dev": true, - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/webpack/node_modules/watchpack": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.2.0.tgz", - "integrity": "sha512-up4YAn/XHgZHIxFBVCdlMiWDj6WaLKpwVeGQk2I5thdYxF/KmF0aaz6TfJZ/hfl1h/XlcDr7k1KH7ThDagpFaA==", - "dev": true, - "dependencies": { - "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.1.2" - }, - "engines": { - "node": ">=10.13.0" - } + "node_modules/webpack/node_modules/@types/estree": { + "version": "0.0.48", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.48.tgz", + "integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==", + "dev": true }, "node_modules/which": { "version": "2.0.2", @@ -2096,9 +2102,9 @@ } }, "@types/eslint": { - "version": "7.2.13", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.2.13.tgz", - "integrity": "sha512-LKmQCWAlnVHvvXq4oasNUMTJJb2GwSyTY8+1C7OH5ILR8mPLaljv1jxL1bXW3xB3jFbQxTKxJAvI8PyjB09aBg==", + "version": "8.44.3", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.3.tgz", + "integrity": "sha512-iM/WfkwAhwmPff3wZuPLYiHX18HI24jU8k1ZSH7P8FHwxTjZ2P6CoX2wnF43oprR+YXJM6UUxATkNvyv/JHd+g==", "dev": true, "requires": { "@types/estree": "*", @@ -2106,9 +2112,9 @@ } }, "@types/eslint-scope": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.0.tgz", - "integrity": "sha512-O/ql2+rrCUe2W2rs7wMR+GqPRcgB6UiqN5RhrR5xruFlY7l9YLMn0ZkDzjoHLeiFkR8MCQZVudUuuvQ2BLC9Qw==", + "version": "3.7.5", + "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.5.tgz", + "integrity": "sha512-JNvhIEyxVW6EoMIFIvj93ZOywYFatlpu9deeH6eSx6PE3WHYvHaQtmHmQeNw7aA81bYGBPPQqdtBm6b1SsQMmA==", "dev": true, "requires": { "@types/eslint": "*", @@ -2116,9 +2122,9 @@ } }, "@types/estree": { - "version": "0.0.48", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.48.tgz", - "integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==", + "version": "0.0.51", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.51.tgz", + "integrity": "sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==", "dev": true }, "@types/filesystem": { @@ -2143,9 +2149,9 @@ "dev": true }, "@types/json-schema": { - "version": "7.0.7", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz", - "integrity": "sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==", + "version": "7.0.13", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.13.tgz", + "integrity": "sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ==", "dev": true }, "@types/node": { @@ -2335,6 +2341,12 @@ "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", "dev": true }, + "acorn": { + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", + "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", + "dev": true + }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -2536,9 +2548,9 @@ "dev": true }, "enhanced-resolve": { - "version": "5.8.2", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz", - "integrity": "sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==", + "version": "5.15.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz", + "integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==", "dev": true, "requires": { "graceful-fs": "^4.2.4", @@ -2678,9 +2690,9 @@ "dev": true }, "graceful-fs": { - "version": "4.2.6", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", - "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==", + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true }, "has": { @@ -3117,12 +3129,12 @@ "dev": true }, "schema-utils": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.0.0.tgz", - "integrity": "sha512-6D82/xSzO094ajanoOSbe4YvXWMfn2A//8Y1+MUqFAJul5Bs+yn36xbK9OtNDcRVSBJ9jjeoXftM6CfztsjOAA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", + "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", "dev": true, "requires": { - "@types/json-schema": "^7.0.6", + "@types/json-schema": "^7.0.8", "ajv": "^6.12.5", "ajv-keywords": "^3.5.2" } @@ -3384,6 +3396,16 @@ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, + "watchpack": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", + "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", + "dev": true, + "requires": { + "glob-to-regexp": "^0.4.1", + "graceful-fs": "^4.1.2" + } + }, "webpack": { "version": "5.42.0", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.42.0.tgz", @@ -3415,21 +3437,11 @@ "webpack-sources": "^2.3.0" }, "dependencies": { - "acorn": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz", - "integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==", + "@types/estree": { + "version": "0.0.48", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.48.tgz", + "integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==", "dev": true - }, - "watchpack": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.2.0.tgz", - "integrity": "sha512-up4YAn/XHgZHIxFBVCdlMiWDj6WaLKpwVeGQk2I5thdYxF/KmF0aaz6TfJZ/hfl1h/XlcDr7k1KH7ThDagpFaA==", - "dev": true, - "requires": { - "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.1.2" - } } } }, @@ -3508,9 +3520,9 @@ } }, "webpack-sources": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-2.3.0.tgz", - "integrity": "sha512-WyOdtwSvOML1kbgtXbTDnEW0jkJ7hZr/bDByIwszhWd/4XX1A3XMkrbFMsuH4+/MfLlZCUzlAdg4r7jaGKEIgQ==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-2.3.1.tgz", + "integrity": "sha512-y9EI9AO42JjEcrTJFOYmVywVZdKVUfOvDUPsJea5GIr1JOEGFVqwlY2K098fFoIjOkDzHn2AjRvM8dsBZu+gCA==", "dev": true, "requires": { "source-list-map": "^2.0.1", diff --git a/package.json b/package.json index 3f3f0e9..34eeacd 100644 --- a/package.json +++ b/package.json @@ -30,5 +30,5 @@ "lint": "tslint src/*.ts", "watch": "webpack --config webpack/webpack.dev.js --watch" }, - "version": "1.0.13" + "version": "1.1.0" } diff --git a/src/content.ts b/src/content.ts index 9e6d7db..fa59c2a 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,6 +1,6 @@ // This script is excuted directly from inside the page import { ArcElement, Chart, Legend, LineElement, PieController, Tooltip } from 'chart.js' -import { Data, ICachedData, IColorData, IRepoData, ITokenData } from './data' +import { Data, ICachedRepoData, IColorData, IRepoData, ITokenData } from './data' import { GHULError } from './errors' // Register the parts of Chart.js I need @@ -11,11 +11,11 @@ const ORG_XPATH = '//*[text() = "Top languages"]' const USER_CONTAINER_SELECTOR = 'div[itemtype="http://schema.org/Person"]' class LanguageDisplay { - private canvas : HTMLCanvasElement - private container : HTMLDivElement - private data : Data - private parent : HTMLDivElement - private username : string + protected canvas : HTMLCanvasElement + protected container : HTMLDivElement + protected data : Data + protected parent : HTMLDivElement + protected username : string constructor(username: string) { this.username = username @@ -53,7 +53,7 @@ class LanguageDisplay { }) } - private async getData() { + protected async getData() { // Fetch the color data from the json file // Use the promise provided by the Data class to get all necessary data try { @@ -87,10 +87,10 @@ class LanguageDisplay { } } - private cacheData(data: IRepoData) { + protected cacheData(data: IRepoData) { // Store the repo data in the cache for the username const cachedAt : number = new Date().valueOf() - const value : ICachedData = { + const value : ICachedRepoData = { cachedAt, data, } @@ -99,7 +99,7 @@ class LanguageDisplay { chrome.storage.local.set(cacheData) } - private createContainer() { + protected createContainer() { const div = document.createElement('div') const header = document.createElement('h4') const headerText = document.createTextNode('Languages') @@ -115,7 +115,7 @@ class LanguageDisplay { return div } - private createCanvas(width: number) { + protected createCanvas(width: number) { // Round width down to the nearest 50 width = Math.floor(width / 50) * 50 // Create the canvas to put the chart in @@ -129,7 +129,7 @@ class LanguageDisplay { return canvas } - private build(colorData: IColorData, repoData: IRepoData) { + protected build(colorData: IColorData, repoData: IRepoData) { this.container = this.createContainer() // Get the width and height of the container and use it to build the canvas const width = +(window.getComputedStyle(this.container).width.split('px')[0]) @@ -143,7 +143,7 @@ class LanguageDisplay { }) } - private draw(colorData: IColorData, repoData: IRepoData, showLegend: boolean) { + protected draw(colorData: IColorData, repoData: IRepoData, showLegend: boolean) { // Create the pie chart and populate it with the repo data const counts = [] const colors = [] @@ -153,7 +153,7 @@ class LanguageDisplay { // Prop is one of the languages langs.push(prop) counts.push(repoData[prop]) - colors.push(colorData[prop] || '#ededed') + colors.push((colorData[prop] || {}).color || '#ededed') } } // Update the canvas height based on the number of languages diff --git a/src/data.ts b/src/data.ts index b20de3a..faba897 100644 --- a/src/data.ts +++ b/src/data.ts @@ -2,21 +2,32 @@ // Allows the content script to be agnostic as to where the data is coming from as this class will use promises import { GHULError } from './errors' -const CACHE_THRESHOLD = 36e5 // 1 hour +const REPO_CACHE_THRESHOLD = 36e5 // 1 hour +// The repo I pull from now is updated weekly so this makes sense +const COLOR_CACHE_THRESHOLD = REPO_CACHE_THRESHOLD * 24 * 7 // 7 days +const COLOR_CACHE_KEY = 'GHUL_COLORS' +const COLOR_URL = 'https://raw.githubusercontent.com/ozh/github-colors/master/colors.json' export interface IRepoData { [language: string] : number } export interface IColorData { - [language: string] : string + [language: string] : { + color : string, + } } -export interface ICachedData { +export interface ICachedRepoData { cachedAt : number data : IRepoData } +export interface ICachedColorData { + cachedAt : number + data : IColorData +} + export interface ITokenData { username : string | null token : string @@ -29,9 +40,9 @@ interface IAPIRepoData { export class Data { public repoDataFromCache : boolean = false public emptyAccount : boolean = true - private isOrg : boolean - private personalToken : ITokenData - private username : string + protected isOrg : boolean + protected personalToken : ITokenData + protected username : string constructor(username: string, isOrg: boolean, token: ITokenData) { this.username = username @@ -45,24 +56,43 @@ export class Data { return Promise.all([this.getColorData(), this.getRepoData()]) } - private async getColorData() : Promise { - const url = chrome.runtime.getURL('colors.json') - return (await fetch(url)).json() + // Fetches color data from local storage, or downloads it again if it's more than a week old + protected async getColorData() : Promise { + let colorData : IColorData + try { + // Check the cache + const cachedData = await this.checkColorCache() + colorData = cachedData.data + } catch (e) { + colorData = await this.fetchColorData() + + // Cache the data + const cachedAt : number = new Date().valueOf() + const value : ICachedColorData = { + cachedAt, + data: colorData, + } + const cacheData = {} + cacheData[COLOR_CACHE_KEY] = value + chrome.storage.local.set(cacheData) + } + // Return the found data, regardless of source + return colorData } - private checkCache() : Promise { + protected checkColorCache() : Promise { // Create a promise to retrieve the key from cache, or reject if it's not there return new Promise((resolve, reject) => { // return reject() // Uncomment this to turn off cache reads when in development - chrome.storage.local.get([this.username], (result) => { + chrome.storage.local.get([COLOR_CACHE_KEY], (result) => { // If the data isn't there, result will be an empty object if (Object.keys(result).length < 1) { // If we get to this point, there was nothing in cache or the cache was invalid return reject() } // We have a cached object, so check time of cache - const cachedData : ICachedData = result[this.username] - if (new Date().valueOf() - cachedData.cachedAt < CACHE_THRESHOLD) { + const cachedData : ICachedColorData = result[COLOR_CACHE_KEY] + if (new Date().valueOf() - cachedData.cachedAt < COLOR_CACHE_THRESHOLD) { // We can use the cached version // Set emptyAccount flag to false here too this.emptyAccount = false @@ -74,11 +104,17 @@ export class Data { }) } + // Fetch the new color data + protected async fetchColorData() : Promise { + const response = await fetch(COLOR_URL) + return response.json() + } + // Fetches the repo data either from cache or from the API and returns a Promise for the data - private async getRepoData() : Promise { + protected async getRepoData() : Promise { try { // Check if the user's data is in the cache - const cachedData = await this.checkCache() + const cachedData = await this.checkRepoCache() this.repoDataFromCache = true return Promise.resolve(cachedData.data) } catch (e) { @@ -87,54 +123,32 @@ export class Data { } } - private updateRepoData(repoData: IRepoData, json: IAPIRepoData[]) : IRepoData { - for (const repo of json) { - if (repo.language === null) { continue } - let count = repoData[repo.language] || 0 - count++ - repoData[repo.language] = count - this.emptyAccount = false - } - return repoData - } - - // Helper method to get the next url to go to - private getNextUrlFromHeader(header: string) { - if (header === null) { return null } - const regex = /\<(.*)\>/ - // The header can contain many URLs, separated by commas, each with a rel - // We want only the one that contains rel="next" - for (const url of header.split(', ')) { - if (url.includes('rel="next"')) { - // We need to retrive the actual URL part using regex - return regex.exec(url)[1] - } - } - return null - } + protected checkRepoCache() : Promise { + // Create a promise to retrieve the key from cache, or reject if it's not there + return new Promise((resolve, reject) => { + // return reject() // Uncomment this to turn off cache reads when in development + chrome.storage.local.get([this.username], (result) => { + // If the data isn't there, result will be an empty object + if (Object.keys(result).length < 1) { + // If we get to this point, there was nothing in cache or the cache was invalid + return reject() + } + // We have a cached object, so check time of cache + const cachedData : ICachedRepoData = result[this.username] + if (new Date().valueOf() - cachedData.cachedAt < REPO_CACHE_THRESHOLD) { + // We can use the cached version + // Set emptyAccount flag to false here too + this.emptyAccount = false + return resolve(cachedData) + } - private generateAPIURL() : string { - // Generate the correct API URL request given the circumstances of the request - // Circumstances: Org or User page, and if User page, is it the User using the extension - const urlBase = 'https://api.github.com' - const query = 'page=1&per_page=50' - let url : string - if (this.isOrg) { - url = `${urlBase}/orgs/${this.username}/repos?${query}` - } - else if (this.username === this.personalToken.username) { - // Send the request to list the user's own repos - url = `${urlBase}/user/repos?${query}&affiliation=owner` - } - else { - // Send the request to the normal users endpoint - url = `${urlBase}/users/${this.username}/repos?${query}` - } - return url + return reject() + }) + }) } // Fetch repository data from the API - private async fetchRepoData() : Promise { + protected async fetchRepoData() : Promise { let url = this.generateAPIURL() let linkHeader : string let repoData : IRepoData = {} @@ -142,7 +156,6 @@ export class Data { if (this.personalToken !== null && this.personalToken.username !== null) { headers.Authorization = `token ${this.personalToken.token}` } - const headerRegex = /\<(.*)\> rel="next"/ // Use Promise.resolve to wait for the result let response = await fetch(url, {headers}) linkHeader = response.headers.get('link') @@ -172,4 +185,50 @@ export class Data { // Still gonna return a promise return Promise.resolve(repoData) } + + protected updateRepoData(repoData: IRepoData, json: IAPIRepoData[]) : IRepoData { + for (const repo of json) { + if (repo.language === null) { continue } + let count = repoData[repo.language] || 0 + count++ + repoData[repo.language] = count + this.emptyAccount = false + } + return repoData + } + + protected generateAPIURL() : string { + // Generate the correct API URL request given the circumstances of the request + // Circumstances: Org or User page, and if User page, is it the User using the extension + const urlBase = 'https://api.github.com' + const query = 'page=1&per_page=50' + let url : string + if (this.isOrg) { + url = `${urlBase}/orgs/${this.username}/repos?${query}` + } + else if (this.username === this.personalToken.username) { + // Send the request to list the user's own repos + url = `${urlBase}/user/repos?${query}&affiliation=owner` + } + else { + // Send the request to the normal users endpoint + url = `${urlBase}/users/${this.username}/repos?${query}` + } + return url + } + + // Helper method to get the next url to go to + protected getNextUrlFromHeader(header: string) { + if (header === null) { return null } + const regex = /\<(.*)\>/ + // The header can contain many URLs, separated by commas, each with a rel + // We want only the one that contains rel="next" + for (const url of header.split(', ')) { + if (url.includes('rel="next"')) { + // We need to retrive the actual URL part using regex + return regex.exec(url)[1] + } + } + return null + } } diff --git a/src/popup.ts b/src/popup.ts index 31bec18..85864b2 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -20,7 +20,6 @@ async function getUsernameForToken(token: string) : Promise { if (response.ok) { const data = await response.json() username = data.login - console.log(username) } // If not okay, we'll leave the username as null } @@ -61,7 +60,6 @@ async function setup(result: ISyncData) { personalAccessToken: token, personalAccessTokenOwner: username, } - console.log('setting data', storedData) chrome.storage.sync.set(storedData) }, false) diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 6562b51..34b9fed 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -3,7 +3,7 @@ const path = require('path'); module.exports = { entry: { - background: path.join(__dirname, '../src/background.ts'), + // background: path.join(__dirname, '../src/background.ts'), content_script: path.join(__dirname, '../src/content.ts'), // options: path.join(__dirname, '../src/options.ts'), popup: path.join(__dirname, '../src/popup.ts'),