diff --git a/README.md b/README.md index aaa9099..c9317cd 100644 --- a/README.md +++ b/README.md @@ -30,21 +30,109 @@ Features ### Site-Specific Key Mappings -Key mappings have been included which can help you perform some common actions -on many popular sites. +181 key mappings for 16 unique +sites have been included which can help you perform some common actions: -Some examples of these mappings are: -- Star the current GitHub/GitLab repository: `s` -- Follow a user on Twitter: `f` -- Upvote a post/comment on Reddit/HackerNews `s` -- Analyze the current Amazon Product using Fakespot `fs` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -The mappings are activated by typing the `` (`` by default), -followed by the key sequence. - -See [keys.js](./keys.js) for all of the mappings. - - + +
global
MappingDescription
wScroll up
sScroll down
giEdit current URL with vim editor
giEdit current URL with vim editor
gIView image in new tab
ypCopy URL path of current page
yICopy Image URL
;seEdit Settings
gSOpen Chrome settings
=wLookup whois information for domain
=dLookup dns information for domain
=DLookup all information for domain
;pdToggle PDF viewer from SurfingKeys
amazon.com
MappingDescription
<Space>fsFakespot
behance.net
MappingDescription
<Space>sAppreciate project
<Space>bAdd project to collection
<Space>aView project
<Space>AView project (new tab)
dribbble.com
MappingDescription
<Space>sHeart Shot
<Space>aView shot
<Space>AView shot (new tab)
<Space>vView attachment image
<Space>VYank attachment image source URL
<Space>zZoom shot
fonts.adobe.com
MappingDescription
<Space>aActivate font
<Space>sFavorite font
github.com
MappingDescription
<Space>aView Repository
<Space>uView User
<Space>fView File
<Space>iView Issue
<Space>gpGo to parent
<Space>sToggle Star
<Space>SCheck Star
<Space>yCopy Project Path
<Space>YCopy Project Path (including domain)
<Space>DView GoDoc for Project
gitlab.com
MappingDescription
<Space>sToggle Star
<Space>yCopy Project Path
<Space>YCopy Project Path (including domain)
<Space>DView GoDoc for Project
google.com
MappingDescription
<Space>aOpen search result
<Space>AOpen search result (new tab)
news.ycombinator.com
MappingDescription
<Space>xCollapse comment
<Space>XCollapse next comment
<Space>sUpvote
<Space>SDownvote
<Space>aView post (link)
<Space>AView post (link) (new tab)
<Space>cView post (comments)
<Space>CView post (comments) (new tab)
<Space>pGo to parent
producthunt.com
MappingDescription
<Space>aView product (external)
<Space>vView product
<Space>sUpvote product
reddit.com
MappingDescription
<Space>xCollapse comment
<Space>XCollapse next comment
<Space>sUpvote
<Space>SDownvote
<Space>eExpand expando
<Space>aView post (link)
<Space>AView post (link) (new tab)
<Space>cView post (comments)
<Space>CView post (comments) (new tab)
twitter.com
MappingDescription
<Space>fFollow user
<Space>sLike tweet
<Space>RRetweet
<Space>cComment/Reply
<Space>tNew tweet
<Space>TTweet to
<Space>rLoad new tweets
<Space>gGoto user
vimeo.com
MappingDescription
<Space>FToggle fullscreen
wikipedia.org
MappingDescription
<Space>sToggle simple version of current article
yelp.com
MappingDescription
<Space>fsFakespot
youtube.com
MappingDescription
AOpen video
COpen channel
gHGoto homepage
FToggle fullscreen
<Space>Play/pause
### Bundled Search Engine Completions @@ -55,51 +143,51 @@ You can access a Search Engine auto-completion by pressing the search leader key For example, to open the Wikipedia completion, you would type `awp` while in normal mode. | Alias | Name | Domain | Screenshots | -| ---- | ------ | ----- | ----- | -| `af` | `archforums` | `Google Custom Search` | | -| `al` | `archlinux` | `www.archlinux.org` | | -| `au` | `AUR` | `aur.archlinux.org` | | -| `aw` | `archwiki` | `wiki.archlinux.org` | | -| `az` | `amazon` | `smile.amazon.com` | | -| `cl` | `craigslist` | `craigslist.org` | | -| `co` | `crunchbase-orgs` | `www.crunchbase.com` | | -| `cp` | `crunchbase-people` | `www.crunchbase.com` | [:framed_picture:](#crunchbase-people) | -| `cs` | `chromestore` | `chrome.google.com` | | -| `de` | `define` | `onelook.com` | [:framed_picture:](#define) | -| `dg` | `duckduckgo` | `duckduckgo.com` | | -| `dh` | `dockerhub` | `hub.docker.com` | [:framed_picture:](#dockerhub) | -| `do` | `domainr` | `domainr.com` | [:framed_picture:](#domainr) | -| `eb` | `ebay` | `www.ebay.com` | | -| `ex` | `exdocs` | `hex.pm` | | -| `gd` | `godoc` | `godoc.org` | | -| `gg` | `golang` | `Google Custom Search` | | -| `gh` | `github` | `github.com` | [:framed_picture:](#github) | -| `gi` | `google-images` | `www.google.com` | | -| `gl` | `google-lucky` | `www.google.com` | | -| `go` | `google` | `www.google.com` | | -| `gs` | `go-search` | `go-search.org` | | -| `gw` | `gowalker` | `gowalker.org` | | -| `ha` | `hackage` | `hackage.haskell.org` | | -| `hd` | `hexdocs` | `hex.pm` | | -| `hn` | `hackernews` | `hn.algolia.com` | [:framed_picture:](#hackernews) | -| `ho` | `hoogle` | `www.haskell.org` | [:framed_picture:](#hoogle) | -| `hw` | `haskellwiki` | `wiki.haskell.org` | | -| `hx` | `hex` | `hex.pm` | | -| `hy` | `hayoo` | `hayoo.fh-wedel.de` | | -| `jq` | `jquery` | `Google Custom Search` | | -| `md` | `mdn` | `developer.mozilla.org` | [:framed_picture:](#mdn) | -| `no` | `node` | `Google Custom Search` | | -| `np` | `npm` | `www.npmjs.com` | [:framed_picture:](#npm) | -| `ow` | `owasp` | `www.owasp.org` | | -| `re` | `reddit` | `www.reddit.com` | | -| `so` | `stackoverflow` | `stackoverflow.com` | | -| `th` | `thesaurus` | `www.onelook.com` | [:framed_picture:](#thesaurus) | -| `vw` | `vimwikia` | `vim.wikia.com` | | -| `wa` | `wolframalpha` | `www.wolframalpha.com` | [:framed_picture:](#wolframalpha) [:framed_picture:](#wolframalpha-2) | -| `wp` | `wikipedia` | `en.wikipedia.org` | | -| `ws` | `wikipedia-simple` | `simple.wikipedia.org` | | -| `yp` | `yelp` | `www.yelp.com` | | -| `yt` | `youtube` | `www.youtube.com` | [:framed_picture:](#youtube) | +| ----- | ---- | ------ | ----------- | + | `af` | `archforums` | `Google Custom Search` | | + | `al` | `archlinux` | `www.archlinux.org` | | + | `au` | `AUR` | `aur.archlinux.org` | | + | `aw` | `archwiki` | `wiki.archlinux.org` | | + | `az` | `amazon` | `smile.amazon.com` | | + | `cl` | `craigslist` | `craigslist.org` | | + | `co` | `crunchbase-orgs` | `www.crunchbase.com` | | + | `cp` | `crunchbase-people` | `www.crunchbase.com` | [:framed_picture:](#crunchbase-people) | + | `cs` | `chromestore` | `chrome.google.com` | | + | `de` | `define` | `onelook.com` | [:framed_picture:](#define) | + | `dg` | `duckduckgo` | `duckduckgo.com` | | + | `dh` | `dockerhub` | `hub.docker.com` | [:framed_picture:](#dockerhub) | + | `do` | `domainr` | `domainr.com` | [:framed_picture:](#domainr) | + | `eb` | `ebay` | `www.ebay.com` | | + | `ex` | `exdocs` | `hex.pm` | | + | `gd` | `godoc` | `godoc.org` | | + | `gg` | `golang` | `Google Custom Search` | | + | `gh` | `github` | `github.com` | [:framed_picture:](#github) | + | `gi` | `google-images` | `www.google.com` | | + | `gl` | `google-lucky` | `www.google.com` | | + | `go` | `google` | `www.google.com` | | + | `gs` | `go-search` | `go-search.org` | | + | `gw` | `gowalker` | `gowalker.org` | | + | `ha` | `hackage` | `hackage.haskell.org` | | + | `hd` | `hexdocs` | `hex.pm` | | + | `hn` | `hackernews` | `hn.algolia.com` | [:framed_picture:](#hackernews) | + | `ho` | `hoogle` | `www.haskell.org` | [:framed_picture:](#hoogle) | + | `hw` | `haskellwiki` | `wiki.haskell.org` | | + | `hx` | `hex` | `hex.pm` | | + | `hy` | `hayoo` | `hayoo.fh-wedel.de` | | + | `jq` | `jquery` | `Google Custom Search` | | + | `md` | `mdn` | `developer.mozilla.org` | [:framed_picture:](#mdn) | + | `no` | `node` | `Google Custom Search` | | + | `np` | `npm` | `www.npmjs.com` | [:framed_picture:](#npm) | + | `ow` | `owasp` | `www.owasp.org` | | + | `re` | `reddit` | `www.reddit.com` | | + | `so` | `stackoverflow` | `stackoverflow.com` | | + | `th` | `thesaurus` | `www.onelook.com` | [:framed_picture:](#thesaurus) | + | `vw` | `vimwikia` | `vim.wikia.com` | | + | `wa` | `wolframalpha` | `www.wolframalpha.com` | [:framed_picture:](#wolframalpha) [:framed_picture:](#wolframalpha-2) | + | `wp` | `wikipedia` | `en.wikipedia.org` | | + | `ws` | `wikipedia-simple` | `simple.wikipedia.org` | | + | `yp` | `yelp` | `www.yelp.com` | | + | `yt` | `youtube` | `www.youtube.com` | [:framed_picture:](#youtube) | Installation diff --git a/README.tmpl.md b/README.tmpl.md index d3e8be8..b59b2f0 100644 --- a/README.tmpl.md +++ b/README.tmpl.md @@ -24,21 +24,14 @@ Features ### Site-Specific Key Mappings -Key mappings have been included which can help you perform some common actions -on many popular sites. + key mappings for unique +sites have been included which can help you perform some common actions: -Some examples of these mappings are: -- Star the current GitHub/GitLab repository: `s` -- Follow a user on Twitter: `f` -- Upvote a post/comment on Reddit/HackerNews `s` -- Analyze the current Amazon Product using Fakespot `fs` - -The mappings are activated by typing the `` (`` by default), -followed by the key sequence. - -See [keys.js](./keys.js) for all of the mappings. - - + + + + +
### Bundled Search Engine Completions @@ -49,7 +42,7 @@ You can access a Search Engine auto-completion by pressing the search leader key For example, to open the Wikipedia completion, you would type `awp` while in normal mode. | Alias | Name | Domain | Screenshots | -| ---- | ------ | ----- | ----- | +| ----- | ---- | ------ | ----------- | Installation diff --git a/actions.js b/actions.js index 1dc0797..3c78839 100644 --- a/actions.js +++ b/actions.js @@ -1,6 +1,7 @@ const ghReservedNames = require("github-reserved-names") const util = require("./util") +const Hints = require("./hints") const actions = {} @@ -10,17 +11,17 @@ const actions = {} // URL Manipulation/querying // ------------------------- actions.vimEditURL = () => Front - .showEditor(window.location.href, (data) => { - window.location.href = data + .showEditor(util.getCurrentLocation(), (url) => { + actions.openLink(url)() }, "url") actions.getURLPath = ({ count = 0, domain = false } = {}) => { - let path = window.location.pathname.slice(1) + let path = util.getCurrentLocation("pathname").slice(1) if (count) { path = path.split("/").slice(0, count).join("/") } if (domain) { - path = `${window.location.hostname}/${path}` + path = `${util.getCurrentLocation("hostname")}/${path}` } return path } @@ -32,16 +33,18 @@ actions.copyURLPath = ({ count, domain } = {}) => // ---------------- const domainDossierUrl = "http://centralops.net/co/DomainDossier.aspx" -actions.showWhois = ({ hostname = window.location.hostname } = {}) => - () => tabOpenLink(`${domainDossierUrl}?dom_whois=true&addr=${hostname}`) +actions.showWhois = ({ hostname = util.getCurrentLocation("hostname") } = {}) => + () => actions.openLink(`${domainDossierUrl}?dom_whois=true&addr=${hostname}`, { newTab: true })() -actions.showDns = ({ hostname = window.location.hostname, verbose = false } = {}) => +actions.showDns = ({ hostname = util.getCurrentLocation("hostname"), verbose = false } = {}) => () => { + let u = "" if (verbose) { - tabOpenLink(`${domainDossierUrl}?dom_whois=true&dom_dns=true&traceroute=true&net_whois=true&svc_scan=true&addr=${hostname}`) + u = `${domainDossierUrl}?dom_whois=true&dom_dns=true&traceroute=true&net_whois=true&svc_scan=true&addr=${hostname}` } else { - tabOpenLink(`${domainDossierUrl}?dom_dns=true&addr=${hostname}`) + u = `${domainDossierUrl}?dom_dns=true&addr=${hostname}` } + actions.openLink(u, { newTab: true })() } // Surfingkeys-specific actions @@ -49,9 +52,18 @@ actions.showDns = ({ hostname = window.location.hostname, verbose = false } = {} actions.createHint = (selector, action = Hints.dispatchMouseClick) => () => Hints.create(selector, action) -actions.open = ({ newTab = false, prop = "href" } = {}) => a => window.open(a[prop], newTab ? "_BLANK" : undefined) +actions.openAnchor = ({ newTab = false, prop = "href" } = {}) => + a => actions.openLink(a[prop], { newTab })() -actions.editSettings = () => tabOpenLink("/pages/options.html") +actions.openLink = (u, { newTab = false } = {}) => + () => { + if (window === undefined) { + return + } + window.open(u, newTab ? "_blank" : "_self") + } + +actions.editSettings = actions.openLink("/pages/options.html", { newTab: true }) actions.togglePdfViewer = () => chrome.storage.local.get("noPdfViewer", (resp) => { @@ -71,18 +83,19 @@ actions.togglePdfViewer = () => // FakeSpot // -------- -actions.fakeSpot = (url = window.location.href) => tabOpenLink(`http://fakespot.com/analyze?url=${url}`) +actions.fakeSpot = + (url = util.getCurrentLocation("href")) => actions.openLink(`http://fakespot.com/analyze?url=${url}`, { newTab: true })() // Godoc // ----- actions.viewGodoc = () => - tabOpenLink(`https://godoc.org/${actions.getURLPath({ count: 2, domain: true })}`) + actions.openLink(`https://godoc.org/${actions.getURLPath({ count: 2, domain: true })}`, { newTab: true })() // GitHub // ------ actions.gh = {} actions.gh.star = ({ toggle = false } = {}) => () => { - const repo = window.location.pathname.slice(1).split("/").slice(0, 2).join("/") + const repo = util.getCurrentLocation("pathname").slice(1).split("/").slice(0, 2).join("/") const container = document.querySelector("div.starring-container") const status = container.classList.contains("on") @@ -113,13 +126,14 @@ actions.gh.openRepo = () => { const u = new URL(a.href) const [user, repo, ...rest] = u.pathname.split("/").filter(s => s !== "") return ( - u.origin === window.location.origin && + u.origin === util.getCurrentLocation("origin") && u.hash === "" && u.search === "" && typeof user === "string" && + user.length > 0 && typeof repo === "string" && + repo.length > 0 && rest.length === 0 && - repo.length >= 1 && /^([a-zA-Z0-9]+-?)+$/.test(user) && !ghReservedNames.check(user) ) @@ -133,10 +147,11 @@ actions.gh.openUser = () => { const u = new URL(a.href) const [user, ...rest] = u.pathname.split("/").filter(s => s !== "") return ( - u.origin === window.location.origin && + u.origin === util.getCurrentLocation("origin") && u.hash === "" && u.search === "" && typeof user === "string" && + user.length > 0 && rest.length === 0 && /^([a-zA-Z0-9]+-?)+$/.test(user) && !ghReservedNames.check(user) @@ -151,10 +166,13 @@ actions.gh.openFile = () => { const u = new URL(a.href) const [user, repo, maybeBlob, ...rest] = u.pathname.split("/").filter(s => s !== "") return ( - u.origin === window.location.origin && + u.origin === util.getCurrentLocation("origin") && u.hash === "" && u.search === "" && typeof user === "string" && + user.length > 0 && + typeof repo === "string" && + repo.length > 0 && typeof maybeBlob === "string" && ( maybeBlob === "blob" || maybeBlob === "tree" ) && rest.length !== 0 && @@ -165,9 +183,33 @@ actions.gh.openFile = () => { Hints.create(elements, Hints.dispatchMouseClick) } +actions.gh.openIssue = () => { + const elements = [...document.querySelectorAll("a[href]")] + .filter(a => { + const u = new URL(a.href) + const [user, repo, maybeIssues, maybeIssueNum, ...rest] = u.pathname.split("/").filter(s => s !== "") + return ( + u.origin === util.getCurrentLocation("origin") && + u.hash === "" && + u.search === "" && + typeof user === "string" && + user.length > 0 && + typeof repo === "string" && + repo.length > 0 && + maybeIssues === "issues" && + typeof maybeIssueNum === "string" && + maybeIssueNum.length > 0 && + /^([a-zA-Z0-9]+-?)+$/.test(user) && + !ghReservedNames.check(user) + ) + }) + Hints.create(elements, Hints.dispatchMouseClick) +} + actions.gh.goParent = () => { - const segments = window.location.pathname + const segments = util.getCurrentLocation("pathname") .split("/").filter(s => s !== "") + console.log(`goParent: ${segments}`) const newPath = (() => { const [user, repo, maybeBlob] = segments switch(segments.length) { @@ -188,8 +230,11 @@ actions.gh.goParent = () => { } return segments.slice(0, segments.length - 1) })() + console.log(`newPath: ${newPath}`) if(newPath !== false) { - window.location.assign(`${window.location.origin}/${newPath.join("/")}`) + const u = `${util.getCurrentLocation("origin")}/${newPath.join("/")}` + console.log(`newPath u: ${u}`) + actions.openLink(u)() } } @@ -197,7 +242,7 @@ actions.gh.goParent = () => { // ------ actions.gl = {} actions.gl.star = () => { - const repo = window.location.pathname.slice(1).split("/").slice(0, 2).join("/") + const repo = util.getCurrentLocation("pathname").slice(1).split("/").slice(0, 2).join("/") const btn = document.querySelector(".btn.star-btn > span") btn.click() const action = `${btn.textContent.toLowerCase()}red` @@ -242,7 +287,7 @@ actions.hn.goParent = () => { if (!par) { return } - window.location.assign(par.href) + actions.openLink(par.href)() } actions.hn.collapseNextComment = () => { @@ -258,20 +303,25 @@ actions.hn.collapseNextComment = () => { actions.ph = {} actions.ph.openExternal = () => { Hints.create("ul[class^='postsList_'] > li > div[class^='item_']", p => - tabOpenLink(p.querySelector("div[class^='meta_'] > div[class^='actions_'] > div[class^='minorActions_'] > a:nth-child(1)").href)) + actions.openLink( + p.querySelector("div[class^='meta_'] > div[class^='actions_'] > div[class^='minorActions_'] > a:nth-child(1)").href + , { newTab: true } + )() + ) } // Dribbble // -------- actions.dr = {} -actions.dr.attachment = (cb = a => tabOpenLink(a)) => +actions.dr.attachment = (cb = a => actions.openLink(a, { newTab: true })()) => actions.createHint(".attachments .thumb", a => cb(a.src.replace("/thumbnail/", "/"))) // Wikipedia // --------- actions.wp = {} actions.wp.toggleSimple = () => { - window.location.hostname = window.location.hostname.split(".") + const u = new URL(util.getCurrentLocation("href")) + u.hostname = u.hostname.split(".") .map((s, i) => { if (i === 0) { return s === "simple" ? "" : "simple" diff --git a/conf.js b/conf.js index ea4de9a..e0d9e02 100644 --- a/conf.js +++ b/conf.js @@ -3,12 +3,11 @@ const keys = require("./keys") const completions = require("./completions") // ---- Settings ----// -settings.hintAlign = "left" -settings.omnibarSuggestionTimeout = 500 -settings.richHintsForKeystroke = 1 - -// ---- Theme ----// -settings.theme = ` +util.addSettings({ + hintAlign : "left", + omnibarSuggestionTimeout : 500, + richHintsForKeystroke : 1, + theme: ` /* Disable RichHints CSS animation */ .expandRichHints { animation: 0s ease-in-out 1 forwards expandRichHints; @@ -16,7 +15,8 @@ settings.theme = ` .collapseRichHints { animation: 0s ease-in-out 1 forwards collapseRichHints; } -` + ` +}) // Leader for site-specific mappings const siteleader = "" @@ -30,3 +30,5 @@ util.rmMaps(keys.unmaps.mappings) util.rmSearchAliases(keys.unmaps.searchAliases) util.processMaps(keys.maps, siteleader) util.processCompletions(completions, searchleader) + +module.exports = { siteleader, searchleader } diff --git a/gulpfile.js b/gulpfile.js index 5122c90..90727f0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,6 +10,11 @@ const fs = require("fs") const { spawn } = require("child_process") const { URL } = require("url") +const compl = require("./completions") +const conf = require("./conf") +const keys = require("./keys") +const util = require("./util") + const paths = { scripts: ["conf.priv.js", "completions.js", "conf.js", "actions.js", "help.js", "keys.js", "util.js"], entry: "conf.js", @@ -81,7 +86,6 @@ gulp.task("watch-nogulpfile", () => { }) gulp.task("readme", () => { - const compl = require("./completions") // eslint-disable-line global-require const screens = {} let screenshotList = "" fs.readdirSync(path.join(__dirname, paths.screenshots)).forEach((s) => { @@ -92,7 +96,8 @@ gulp.task("readme", () => { } screens[alias].push(path.join(paths.screenshots, path.basename(s))) }) - const table = Object.keys(compl).sort((a, b) => { + + const complTable = Object.keys(compl).sort((a, b) => { if (a < b) return -1 if (a > b) return 1 return 0 @@ -109,12 +114,35 @@ gulp.task("readme", () => { screenshotList += `![${c.name} screenshot](./${url})\n\n` }) } - return `${a}| \`${c.alias}\` | \`${c.name}\` | \`${domain}\` | ${s} |\n` + return `${a} | \`${c.alias}\` | \`${c.name}\` | \`${domain}\` | ${s} |\n` }, "") + + const keysTable = Object.keys(keys.maps).sort((a, b) => { + if (a === "global") return -1 + if (b === "global") return 1 + if (a < b) return -1 + if (a > b) return 1 + return 0 + }).reduce((acc1, domain) => { + const header = "MappingDescription" + const c = keys.maps[domain] + const maps = c.reduce((acc2, map) => { + const leader = typeof map.leader !== "undefined" ? map.leader : domain === "global" ? "" : conf.siteleader + const mapStr = util.escape(`${leader}${map.alias}`.replace(" ", "")) + console.log({leader, mapStr, sl: conf.siteleader, ml: map.leader }) + return `${acc2}${mapStr}${map.description}\n` + }, "") + const domainStr = domain === "global" ? "global" : `${domain}` + return `${acc1}${domainStr}${header}\n${maps}` + }, "") + return gulp.src(["./README.tmpl.md"]) .pipe(replace("", disclaimer)) .pipe(replace("", Object.keys(compl).length)) - .pipe(replace("", table)) + .pipe(replace("", complTable)) + .pipe(replace("", Object.keys(keys.maps).reduce((acc, m) => acc + m.length, 0))) + .pipe(replace("", Object.keys(keys.maps).length)) + .pipe(replace("", keysTable)) .pipe(replace("", screenshotList)) .pipe(rename("README.md")) .pipe(gulp.dest(".")) diff --git a/hints.js b/hints.js new file mode 100644 index 0000000..127a329 --- /dev/null +++ b/hints.js @@ -0,0 +1,9 @@ +if (typeof Hints === "undefined") { + module.exports = { + create: () => {}, + dispatchMouseClick: () => {}, + } +} else { + module.exports = Hints +} + diff --git a/keys.js b/keys.js index 2ad7bdf..cc64c78 100644 --- a/keys.js +++ b/keys.js @@ -49,7 +49,7 @@ const maps = { alias: "gI", category: categories.pageNav, description: "View image in new tab", - callback: actions.createHint("img", i => tabOpenLink(i.src)), + callback: actions.createHint("img", i => actions.openLink(i.src)()), }, { alias: "yp", @@ -117,7 +117,7 @@ const maps = { { alias: "A", description: "Open search result (new tab)", - callback: actions.createHint(".r>a", actions.open({ newTab: true })), + callback: actions.createHint(".r>a", actions.openAnchor({ newTab: true })), }, ], @@ -135,7 +135,7 @@ const maps = { leader: "", alias: "A", description: "Open video", - callback: actions.createHint("*[id='video-title']", actions.open({ newTab: true })), + callback: actions.createHint("*[id='video-title']", actions.openAnchor({ newTab: true })), }, { leader: "", @@ -147,7 +147,7 @@ const maps = { leader: "", alias: "gH", description: "Goto homepage", - callback: () => window.location.assign("https://www.youtube.com/feed/subscriptions?flow=2"), + callback: actions.openLink("https://www.youtube.com/feed/subscriptions?flow=2"), }, { leader: "", @@ -324,7 +324,7 @@ const maps = { { alias: "A", description: "View post (link) (new tab)", - callback: actions.createHint(".title", actions.open({ newTab: true })), + callback: actions.createHint(".title", actions.openAnchor({ newTab: true })), }, { alias: "c", @@ -334,7 +334,7 @@ const maps = { { alias: "C", description: "View post (comments) (new tab)", - callback: actions.createHint(".comments", actions.open({ newTab: true })), + callback: actions.createHint(".comments", actions.openAnchor({ newTab: true })), }, ], @@ -367,7 +367,7 @@ const maps = { { alias: "A", description: "View post (link) (new tab)", - callback: actions.createHint(".storylink", actions.open({ newTab: true })), + callback: actions.createHint(".storylink", actions.openAnchor({ newTab: true })), }, { alias: "c", @@ -377,7 +377,7 @@ const maps = { { alias: "C", description: "View post (comments) (new tab)", - callback: actions.createHint("td > a[href*='item']:not(.storylink)", actions.open({ newTab: true })), + callback: actions.createHint("td > a[href*='item']:not(.storylink)", actions.openAnchor({ newTab: true })), }, { alias: "p", @@ -418,7 +418,7 @@ const maps = { { alias: "A", description: "View shot (new tab)", - callback: actions.createHint(".dribbble-over, .gif-target, .more-thumbs a", actions.open({ newTab: true })), + callback: actions.createHint(".dribbble-over, .gif-target, .more-thumbs a", actions.openAnchor({ newTab: true })), }, { alias: "v", @@ -456,7 +456,7 @@ const maps = { { alias: "A", description: "View project (new tab)", - callback: actions.createHint(".rf-project-cover__title", actions.open({ newTab: true })), + callback: actions.createHint(".rf-project-cover__title", actions.openAnchor({ newTab: true })), }, ], diff --git a/util.js b/util.js index 7d4fafb..421e328 100644 --- a/util.js +++ b/util.js @@ -2,6 +2,13 @@ const { categories } = require("./help") const util = {} +util.getCurrentLocation = (prop = "href") => { + if (typeof window === "undefined") { + return "" + } + return window.location[prop] +} + util.escape = str => String(str).replace(/[&<>"'`=/]/g, s => ({ "&": "&", "<": "<", @@ -46,14 +53,27 @@ util.isRectVisibleInViewport = rect => ( util.isElementInViewport = e => util.isRectVisibleInViewport(e.getBoundingClientRect()) // Process Unmaps -util.rmMaps = a => a.forEach(u => unmap(u)) +util.rmMaps = a => { + if (typeof unmap === "undefined") { + return + } + a.forEach(u => unmap(u)) +} -util.rmSearchAliases = a => Object.entries(a).forEach(([leader, items]) => +util.rmSearchAliases = a => Object.entries(a).forEach(([leader, items]) =>{ + if (typeof removeSearchAliasX === "undefined") { + return + } items.forEach(v => - removeSearchAliasX(v, leader))) + removeSearchAliasX(v, leader) + ) +}) // Process Mappings -util.processMaps = (maps, siteleader) => +util.processMaps = (maps, siteleader) => { + if (typeof map === "undefined" || typeof mapkey === "undefined") { + return + } Object.entries(maps).forEach(([domain, domainMaps]) => domainMaps.forEach(((mapObj) => { const { @@ -82,11 +102,22 @@ util.processMaps = (maps, siteleader) => mapkey(key, fullDescription, callback, opts) } }))) +} // process completions util.processCompletions = (completions, searchleader) => Object.values(completions).forEach((s) => { + if (typeof Front === "undefined" || typeof addSearchAliasX === "undefined" || typeof mapkey === "undefined") { + return + } addSearchAliasX(s.alias, s.name, s.search, searchleader, s.compl, s.callback) mapkey(`${searchleader}${s.alias}`, `#8Search ${s.name}`, () => Front.openOmnibar({ type: "SearchEngine", extra: s.alias })) }) +util.addSettings = (s) => { + if (typeof settings === "undefined") { + return + } + Object.assign(settings, s) +} + module.exports = util