feat: add additional github mappings

This commit is contained in:
Maddison Hellstrom 2018-11-08 17:46:22 -08:00
parent 8e67a2fdae
commit 3f4a3c1e4d
5 changed files with 252 additions and 7 deletions

View File

@ -1,3 +1,5 @@
const ghReservedNames = require("github-reserved-names")
const util = require("./util")
const actions = {}
@ -105,6 +107,92 @@ actions.gh.star = ({ toggle = false } = {}) => () => {
Front.showBanner(`${star} Repository ${repo} ${verb} ${statusMsg}!`)
}
actions.gh.openRepo = () => {
const elements = [...document.querySelectorAll("a[href]")]
.filter(a => {
const u = new URL(a.href)
const [user, repo, ...rest] = u.pathname.split("/").filter(s => s !== "")
return (
u.origin === window.location.origin &&
u.hash === "" &&
u.search === "" &&
typeof user === "string" &&
typeof repo === "string" &&
rest.length === 0 &&
repo.length >= 1 &&
/^([a-zA-Z0-9]+-?)+$/.test(user) &&
!ghReservedNames.check(user)
)
})
Hints.create(elements, Hints.dispatchMouseClick)
}
actions.gh.openUser = () => {
const elements = [...document.querySelectorAll("a[href]")]
.filter(a => {
const u = new URL(a.href)
const [user, ...rest] = u.pathname.split("/").filter(s => s !== "")
return (
u.origin === window.location.origin &&
u.hash === "" &&
u.search === "" &&
typeof user === "string" &&
rest.length === 0 &&
/^([a-zA-Z0-9]+-?)+$/.test(user) &&
!ghReservedNames.check(user)
)
})
Hints.create(elements, Hints.dispatchMouseClick)
}
actions.gh.openFile = () => {
const elements = [...document.querySelectorAll("a[href]")]
.filter(a => {
const u = new URL(a.href)
const [user, repo, maybeBlob, ...rest] = u.pathname.split("/").filter(s => s !== "")
return (
u.origin === window.location.origin &&
u.hash === "" &&
u.search === "" &&
typeof user === "string" &&
typeof maybeBlob === "string" &&
( maybeBlob === "blob" || maybeBlob === "tree" ) &&
rest.length !== 0 &&
/^([a-zA-Z0-9]+-?)+$/.test(user) &&
!ghReservedNames.check(user)
)
})
Hints.create(elements, Hints.dispatchMouseClick)
}
actions.gh.goParent = () => {
const segments = window.location.pathname
.split("/").filter(s => s !== "")
const newPath = (() => {
const [user, repo, maybeBlob] = segments
switch(segments.length) {
case 0:
return false
case 4:
switch(maybeBlob) {
case "blob":
case "tree":
return [user, repo]
case "pull":
return [user, repo, "pulls"]
}
case 5:
if (maybeBlob === "blob") {
return [user, repo]
}
}
return segments.slice(0, segments.length - 1)
})()
if(newPath !== false) {
window.location.assign(`${window.location.origin}/${newPath.join("/")}`)
}
}
// GitLab
// ------
actions.gl = {}

View File

@ -109,7 +109,7 @@ completions.dh = {
completions.dh.callback = response => JSON.parse(response.text).results.map((s) => {
let meta = ""
let repo = escape(s.repo_name)
let repo = s.repo_name
meta += `[★${escape(s.star_count)}] `
meta += `[↓${escape(s.pull_count)}] `
if (repo.indexOf("/") === -1) {
@ -117,7 +117,7 @@ completions.dh.callback = response => JSON.parse(response.text).results.map((s)
}
return createSuggestionItem(`
<div>
<div class="title"><strong>${escape(s.repo_name)}</strong></div>
<div class="title"><strong>${escape(repo)}</strong></div>
<div>${meta}</div>
<div>${escape(s.short_description)}</div>
</div>

25
keys.js
View File

@ -172,6 +172,31 @@ const maps = {
],
"github.com": [
{
alias: "a",
description: "View Repository",
callback: actions.gh.openRepo,
},
{
alias: "u",
description: "View User",
callback: actions.gh.openUser,
},
{
alias: "f",
description: "View File",
callback: actions.gh.openFile,
},
{
alias: "i",
description: "View Issue",
callback: actions.gh.openIssue,
},
{
alias: "gp",
description: "Go to parent",
callback: actions.gh.goParent,
},
{
alias: "s",
description: "Toggle Star",

View File

@ -17,7 +17,9 @@
],
"author": "Maddison Hellstrom",
"license": "MIT",
"dependencies": {},
"dependencies": {
"github-reserved-names": "^1.1.3"
},
"devDependencies": {
"cz-conventional-changelog": "^2.1.0",
"del": "^3.0.0",

138
yarn.lock
View File

@ -170,6 +170,10 @@ array-each@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/array-each/-/array-each-1.0.1.tgz#a794af0c05ab1752846ee753a1f211a05ba0c44f"
array-find-index@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/array-find-index/-/array-find-index-1.0.2.tgz#df010aa1287e164bbda6f9723b0a96a1ec4187a1"
array-includes@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.0.3.tgz#184b48f62d92d7452bb31b323165c7f8bd02266d"
@ -199,7 +203,7 @@ array-unique@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"
arrify@^1.0.0:
arrify@^1.0.0, arrify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
@ -958,6 +962,18 @@ callsites@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca"
camelcase-keys@^4.0.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-4.2.0.tgz#a2aa5fb1af688758259c32c141426d78923b9b77"
dependencies:
camelcase "^4.1.0"
map-obj "^2.0.0"
quick-lru "^1.0.0"
camelcase@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
caniuse-api@^1.5.2:
version "1.6.1"
resolved "https://registry.yarnpkg.com/caniuse-api/-/caniuse-api-1.6.1.tgz#b534e7c734c4f81ec5fbe8aca2ad24354b962c6c"
@ -1480,6 +1496,12 @@ csso@~2.3.1:
clap "^1.0.9"
source-map "^0.5.3"
currently-unhandled@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"
dependencies:
array-find-index "^1.0.1"
cz-conventional-changelog@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cz-conventional-changelog/-/cz-conventional-changelog-2.1.0.tgz#2f4bc7390e3244e4df293e6ba351e4c740a7c764"
@ -1521,7 +1543,14 @@ debug@^3.1.0:
dependencies:
ms "2.0.0"
decamelize@^1.1.2:
decamelize-keys@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.0.tgz#d171a87933252807eb3cb61dc1c1445d078df2d9"
dependencies:
decamelize "^1.1.0"
map-obj "^1.0.0"
decamelize@^1.1.0, decamelize@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
@ -2259,6 +2288,12 @@ get-value@^2.0.3, get-value@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28"
github-reserved-names@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/github-reserved-names/-/github-reserved-names-1.1.3.tgz#0036905c22af9787776ff9de7cf0dd0f1e4fef14"
dependencies:
meow "^5.0.0"
glob-parent@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-3.1.0.tgz#9e6af6299d8d3bd2bd40430832bd113df906c5ae"
@ -2649,6 +2684,10 @@ imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
indent-string@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-3.2.0.tgz#4a5fd6d27cc332f37e5419a504dbb837105c9289"
indexes-of@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/indexes-of/-/indexes-of-1.0.1.tgz#f30f716c8e2bd346c7b67d3df3915566a7c05607"
@ -2875,7 +2914,7 @@ is-path-inside@^1.0.0:
dependencies:
path-is-inside "^1.0.1"
is-plain-obj@^1.0.0:
is-plain-obj@^1.0.0, is-plain-obj@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
@ -3103,6 +3142,15 @@ load-json-file@^2.0.0:
pify "^2.0.0"
strip-bom "^3.0.0"
load-json-file@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b"
dependencies:
graceful-fs "^4.1.2"
parse-json "^4.0.0"
pify "^3.0.0"
strip-bom "^3.0.0"
locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
@ -3237,6 +3285,13 @@ loose-envify@^1.0.0, loose-envify@^1.3.1:
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
loud-rejection@^1.0.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f"
dependencies:
currently-unhandled "^0.4.1"
signal-exit "^3.0.0"
lru-cache@2:
version "2.7.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"
@ -3270,6 +3325,14 @@ map-cache@^0.2.0, map-cache@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf"
map-obj@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d"
map-obj@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-2.0.0.tgz#a65cd29087a92598b8791257a523e021222ac1f9"
map-visit@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f"
@ -3291,6 +3354,20 @@ mdn-data@^1.0.0, mdn-data@~1.1.0:
version "1.1.4"
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-1.1.4.tgz#50b5d4ffc4575276573c4eedb8780812a8419f01"
meow@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/meow/-/meow-5.0.0.tgz#dfc73d63a9afc714a5e371760eb5c88b91078aa4"
dependencies:
camelcase-keys "^4.0.0"
decamelize-keys "^1.0.0"
loud-rejection "^1.0.0"
minimist-options "^3.0.1"
normalize-package-data "^2.3.4"
read-pkg-up "^3.0.0"
redent "^2.0.0"
trim-newlines "^2.0.0"
yargs-parser "^10.0.0"
merge-source-map@1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/merge-source-map/-/merge-source-map-1.0.4.tgz#a5de46538dae84d4114cc5ea02b4772a6346701f"
@ -3361,6 +3438,13 @@ minimatch@~0.2.11:
lru-cache "2"
sigmund "~1.0.0"
minimist-options@^3.0.1:
version "3.0.2"
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-3.0.2.tgz#fba4c8191339e13ecf4d61beb03f070103f3d954"
dependencies:
arrify "^1.0.1"
is-plain-obj "^1.1.0"
minimist@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
@ -3515,7 +3599,7 @@ nopt@~3.0.1:
dependencies:
abbrev "1"
normalize-package-data@^2.3.2:
normalize-package-data@^2.3.2, normalize-package-data@^2.3.4:
version "2.4.0"
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.4.0.tgz#12f95a307d58352075a04907b84ac8be98ac012f"
dependencies:
@ -3912,6 +3996,12 @@ path-type@^2.0.0:
dependencies:
pify "^2.0.0"
path-type@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
dependencies:
pify "^3.0.0"
pbkdf2@^3.0.3:
version "3.0.16"
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.16.tgz#7404208ec6b01b62d85bf83853a8064f8d9c2a5c"
@ -4529,6 +4619,10 @@ querystring@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
quick-lru@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8"
quote-stream@^1.0.1, quote-stream@~1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/quote-stream/-/quote-stream-1.0.2.tgz#84963f8c9c26b942e153feeb53aae74652b7e0b2"
@ -4570,6 +4664,13 @@ read-pkg-up@^2.0.0:
find-up "^2.0.0"
read-pkg "^2.0.0"
read-pkg-up@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-3.0.0.tgz#3ed496685dba0f8fe118d0691dc51f4a1ff96f07"
dependencies:
find-up "^2.0.0"
read-pkg "^3.0.0"
read-pkg@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-2.0.0.tgz#8ef1c0623c6a6db0dc6713c4bfac46332b2368f8"
@ -4578,6 +4679,14 @@ read-pkg@^2.0.0:
normalize-package-data "^2.3.2"
path-type "^2.0.0"
read-pkg@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389"
dependencies:
load-json-file "^4.0.0"
normalize-package-data "^2.3.2"
path-type "^3.0.0"
"readable-stream@>=1.0.33-1 <1.1.0-0":
version "1.0.34"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c"
@ -4623,6 +4732,13 @@ rechoir@^0.6.2:
dependencies:
resolve "^1.1.6"
redent@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/redent/-/redent-2.0.0.tgz#c1b2007b42d57eb1389079b3c8333639d5e1ccaa"
dependencies:
indent-string "^3.0.0"
strip-indent "^2.0.0"
reduce-css-calc@^1.2.6:
version "1.3.0"
resolved "https://registry.yarnpkg.com/reduce-css-calc/-/reduce-css-calc-1.3.0.tgz#747c914e049614a4c9cfbba629871ad1d2927716"
@ -5169,6 +5285,10 @@ strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
strip-indent@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-2.0.0.tgz#5ef8db295d01e6ed6cbf7aab96998d7822527b68"
strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
@ -5353,6 +5473,10 @@ tomlify-j0.4@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/tomlify-j0.4/-/tomlify-j0.4-3.0.0.tgz#99414d45268c3a3b8bf38be82145b7bba34b7473"
trim-newlines@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-2.0.0.tgz#b403d0b91be50c331dfc4b82eeceb22c3de16d20"
trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
@ -5576,3 +5700,9 @@ yallist@^2.1.2:
yallist@^3.0.0, yallist@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9"
yargs-parser@^10.0.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8"
dependencies:
camelcase "^4.1.0"