2018-08-09 21:37:14 +00:00
|
|
|
const completions = require("./completions")
|
|
|
|
|
2017-08-28 03:24:24 +00:00
|
|
|
// Unmap undesired defaults
|
2017-12-02 02:48:58 +00:00
|
|
|
const unmaps = [
|
|
|
|
"sb", "sw", "ob",
|
|
|
|
"ow", "cp", ";cp",
|
|
|
|
";ap", "spa", "spb",
|
|
|
|
"spd", "sps", "spc",
|
|
|
|
"spi", "sfr", "zQ",
|
|
|
|
"zz", "zR", "ab",
|
|
|
|
"Q", "q", "ag",
|
|
|
|
"af", ";s", "yp",
|
|
|
|
]
|
|
|
|
|
|
|
|
unmaps.forEach((u) => {
|
|
|
|
unmap(u)
|
|
|
|
})
|
|
|
|
|
|
|
|
const rmSearchAliases =
|
|
|
|
{
|
|
|
|
s: ["g", "d", "b",
|
|
|
|
"w", "s", "h"],
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(rmSearchAliases).forEach((k) => {
|
|
|
|
rmSearchAliases[k].forEach((v) => {
|
|
|
|
removeSearchAliasX(v, k)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// ---- Settings ----//
|
|
|
|
settings.hintAlign = "left"
|
|
|
|
settings.omnibarSuggestionTimeout = 500
|
|
|
|
settings.richHintsForKeystroke = 1
|
2017-10-18 05:19:57 +00:00
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
// ---- Theme ----//
|
2017-10-18 05:19:57 +00:00
|
|
|
settings.theme = `
|
|
|
|
/* Disable RichHints CSS animation */
|
|
|
|
.expandRichHints {
|
|
|
|
animation: 0s ease-in-out 1 forwards expandRichHints;
|
|
|
|
}
|
|
|
|
.collapseRichHints {
|
|
|
|
animation: 0s ease-in-out 1 forwards collapseRichHints;
|
|
|
|
}
|
2017-12-02 02:48:58 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
// ---- Maps ----//
|
2017-08-28 03:24:24 +00:00
|
|
|
// Left-hand aliases
|
|
|
|
// Movement
|
2017-12-02 02:48:58 +00:00
|
|
|
map("w", "k")
|
|
|
|
map("s", "j")
|
2017-08-28 03:24:24 +00:00
|
|
|
|
|
|
|
// Right-hand aliases
|
|
|
|
// Tab Navigation
|
2017-12-02 02:48:58 +00:00
|
|
|
map("J", "E")
|
|
|
|
map("K", "R")
|
2017-08-28 03:24:24 +00:00
|
|
|
|
|
|
|
// History
|
2017-12-02 02:48:58 +00:00
|
|
|
map("H", "S")
|
|
|
|
map("L", "D")
|
2017-08-28 03:24:24 +00:00
|
|
|
|
2018-08-09 23:42:57 +00:00
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
// ---- Functions ----//
|
2017-08-28 03:24:24 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const vimEditURL = () => Front
|
|
|
|
.showEditor(window.location.href, (data) => {
|
2017-12-02 02:48:58 +00:00
|
|
|
window.location.href = data
|
|
|
|
}, "url")
|
2017-08-28 03:24:24 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const domainDossier = "http://centralops.net/co/DomainDossier.aspx"
|
2017-08-28 03:24:24 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const whois = () =>
|
|
|
|
tabOpenLink(`${domainDossier}?dom_whois=true&addr=${window.location.hostname}`)
|
2017-08-28 03:24:24 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const dns = () =>
|
|
|
|
tabOpenLink(`${domainDossier}?dom_dns=true&addr=${window.location.hostname}`)
|
|
|
|
|
|
|
|
const dnsVerbose = () =>
|
|
|
|
tabOpenLink(`${domainDossier}?dom_whois=true&dom_dns=true&traceroute=true&net_whois=true&svc_scan=true&addr=${window.location.hostname}`)
|
2017-08-28 03:24:24 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const togglePdfViewer = () =>
|
2017-12-02 02:48:58 +00:00
|
|
|
chrome.storage.local.get("noPdfViewer", (resp) => {
|
|
|
|
if (!resp.noPdfViewer) {
|
|
|
|
chrome.storage.local.set({ noPdfViewer: 1 }, () => {
|
|
|
|
Front.showBanner("PDF viewer disabled.")
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
chrome.storage.local.remove("noPdfViewer", () => {
|
|
|
|
Front.showBanner("PDF viewer enabled.")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2017-09-17 23:26:02 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const getURLPath = (count, domain) => {
|
2018-08-18 04:46:34 +00:00
|
|
|
let path = window.location.pathname.slice(1)
|
|
|
|
if (count) {
|
|
|
|
path = path.split("/").slice(0, count).join("/")
|
|
|
|
}
|
|
|
|
if (domain) {
|
|
|
|
path = `${window.location.hostname}/${path}`
|
2017-12-02 02:48:58 +00:00
|
|
|
}
|
2018-08-18 04:46:34 +00:00
|
|
|
return path
|
2017-11-14 05:46:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const copyURLPath = (count, domain) => () => Clipboard.write(getURLPath(count, domain))
|
2017-11-14 05:46:09 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const editSettings = () => tabOpenLink("/pages/options.html")
|
2017-11-06 07:57:39 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const Hint = (selector, action = Hints.dispatchMouseClick) => () => Hints.create(selector, action)
|
2018-07-12 09:46:13 +00:00
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
// ---- Mapkeys ----//
|
|
|
|
const ri = { repeatIgnore: true }
|
|
|
|
|
2018-08-18 07:24:29 +00:00
|
|
|
// --- Global mappings ---//
|
|
|
|
// 0: Help
|
|
|
|
// 1: Mouse Click
|
|
|
|
// 2: Scroll Page / Element
|
|
|
|
// 3: Tabs
|
|
|
|
// 4: Page Navigation
|
|
|
|
mapkey("gi", "#4Edit current URL with vim editor", vimEditURL, ri)
|
2018-08-19 10:53:30 +00:00
|
|
|
mapkey("gI", "#4View image in new tab", Hint("img", i => tabOpenLink(i.src)), ri)
|
2018-08-18 07:24:29 +00:00
|
|
|
// 5: Sessions
|
|
|
|
// 6: Search selected with
|
|
|
|
// 7: Clipboard
|
|
|
|
mapkey("yp", "#7Copy URL path of current page", copyURLPath(), ri)
|
2018-08-19 10:53:30 +00:00
|
|
|
mapkey("yI", "#7Copy Image URL", Hint("img", i => Clipboard.write(i.src)), ri)
|
2018-08-18 07:24:29 +00:00
|
|
|
// 8: Omnibar
|
|
|
|
// 9: Visual Mode
|
|
|
|
// 10: vim-like marks
|
|
|
|
// 11: Settings
|
2017-12-02 02:48:58 +00:00
|
|
|
mapkey(";se", "#11Edit Settings", editSettings, ri)
|
2018-08-18 07:24:29 +00:00
|
|
|
// 12: Chrome URLs
|
2018-08-18 07:10:32 +00:00
|
|
|
mapkey("gS", "#12Open Chrome settings", () => tabOpenLink("chrome://settings/"))
|
2018-08-18 07:24:29 +00:00
|
|
|
// 13: Proxy
|
|
|
|
// 14: Misc
|
|
|
|
mapkey("=w", "#14Lookup whois information for domain", whois, ri)
|
|
|
|
mapkey("=d", "#14Lookup dns information for domain", dns, ri)
|
|
|
|
mapkey("=D", "#14Lookup all information for domain", dnsVerbose, ri)
|
|
|
|
mapkey(";pd", "#14Toggle PDF viewer from SurfingKeys", togglePdfViewer, ri)
|
|
|
|
// 15: Insert Mode
|
|
|
|
|
|
|
|
// --- Site-specific mappings ---//
|
2017-12-02 02:48:58 +00:00
|
|
|
const siteleader = "<Space>"
|
|
|
|
|
2018-07-27 03:49:59 +00:00
|
|
|
function mapsitekey(domainRegex, key, desc, f, opts = {}) {
|
|
|
|
const o = Object.assign({}, {
|
|
|
|
leader: siteleader,
|
|
|
|
}, opts)
|
|
|
|
mapkey(`${o.leader}${key}`, desc, f, { domain: domainRegex })
|
2017-12-02 02:48:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 13:15:14 +00:00
|
|
|
function mapsitekeys(d, maps, opts = {}) {
|
2017-12-02 02:48:58 +00:00
|
|
|
const domain = d.replace(".", "\\.")
|
|
|
|
const domainRegex = new RegExp(`^http(s)?://(([a-zA-Z0-9-_]+\\.)*)(${domain})(/.*)?`)
|
|
|
|
maps.forEach((map) => {
|
2018-07-30 13:15:14 +00:00
|
|
|
const [
|
|
|
|
key,
|
|
|
|
desc,
|
|
|
|
f,
|
|
|
|
subOpts = {},
|
|
|
|
] = map
|
|
|
|
mapsitekey(domainRegex, key, desc, f, Object.assign({}, opts, subOpts))
|
2017-12-02 02:48:58 +00:00
|
|
|
})
|
2017-11-14 05:46:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 11:22:41 +00:00
|
|
|
const fakeSpot = () => tabOpenLink(`http://fakespot.com/analyze?url=${window.location.href}`)
|
2018-08-19 11:15:00 +00:00
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
mapsitekeys("amazon.com", [
|
|
|
|
["fs", "Fakespot", fakeSpot],
|
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("yelp.com", [
|
|
|
|
["fs", "Fakespot", fakeSpot],
|
|
|
|
])
|
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const ytFullscreen = () => document
|
|
|
|
.querySelector(".ytp-fullscreen-button.ytp-button")
|
|
|
|
.click()
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
mapsitekeys("youtube.com", [
|
2018-07-30 13:15:14 +00:00
|
|
|
["A", "Open video", Hint("*[id='video-title']")],
|
|
|
|
["C", "Open channel", Hint("*[id='byline']")],
|
|
|
|
["gH", "Goto homepage", () => window.location.assign("https://www.youtube.com/feed/subscriptions?flow=2")],
|
|
|
|
["F", "Toggle fullscreen", ytFullscreen],
|
|
|
|
["<Space>", "Play/pause", Hint(".ytp-play-button")],
|
|
|
|
], { leader: "" })
|
2017-12-02 02:48:58 +00:00
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
|
|
|
|
const vimeoFullscreen = () => document
|
|
|
|
.querySelector(".fullscreen-icon")
|
|
|
|
.click()
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
mapsitekeys("vimeo.com", [
|
|
|
|
["F", "Toggle fullscreen", vimeoFullscreen],
|
|
|
|
])
|
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const ghStar = toggle => () => {
|
|
|
|
const repo = window.location.pathname.slice(1).split("/").slice(0, 2).join("/")
|
|
|
|
const container = document.querySelector("div.starring-container")
|
|
|
|
const status = container.classList.contains("on")
|
|
|
|
|
|
|
|
let star = "★"
|
|
|
|
let statusMsg = "starred"
|
|
|
|
let verb = "is"
|
|
|
|
|
|
|
|
if ((status && toggle) || (!status && !toggle)) {
|
|
|
|
statusMsg = `un${statusMsg}`
|
|
|
|
star = "☆"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toggle) {
|
|
|
|
verb = "has been"
|
|
|
|
if (status) {
|
|
|
|
container.querySelector(".starred>button").click()
|
|
|
|
} else {
|
|
|
|
container.querySelector(".unstarred>button").click()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Front.showBanner(`${star} Repository ${repo} ${verb} ${statusMsg}!`)
|
|
|
|
}
|
|
|
|
|
|
|
|
const viewGodoc = () => tabOpenLink(`https://godoc.org/${getURLPath(2, true)}`)
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
mapsitekeys("github.com", [
|
2018-07-27 03:49:59 +00:00
|
|
|
["s", "Toggle Star", ghStar(true)],
|
|
|
|
["S", "Check Star", ghStar(false)],
|
|
|
|
["y", "Copy Project Path", copyURLPath(2)],
|
|
|
|
["Y", "Copy Project Path (including domain)", copyURLPath(2, true)],
|
2017-12-02 02:48:58 +00:00
|
|
|
["D", "View GoDoc for Project", viewGodoc],
|
|
|
|
])
|
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const glToggleStar = () => {
|
|
|
|
const repo = window.location.pathname.slice(1).split("/").slice(0, 2).join("/")
|
|
|
|
const btn = document.querySelector(".btn.star-btn > span")
|
|
|
|
btn.click()
|
|
|
|
const action = `${btn.textContent.toLowerCase()}red`
|
|
|
|
let star = "☆"
|
|
|
|
if (action === "starred") {
|
|
|
|
star = "★"
|
|
|
|
}
|
|
|
|
Front.showBanner(`${star} Repository ${repo} ${action}`)
|
|
|
|
}
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
mapsitekeys("gitlab.com", [
|
|
|
|
["s", "Toggle Star", glToggleStar],
|
2018-07-27 03:49:59 +00:00
|
|
|
["y", "Copy Project Path", copyURLPath(2)],
|
|
|
|
["Y", "Copy Project Path (including domain)", copyURLPath(2, true)],
|
2017-12-02 02:48:58 +00:00
|
|
|
["D", "View GoDoc for Project", viewGodoc],
|
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("twitter.com", [
|
2018-07-27 03:49:59 +00:00
|
|
|
["f", "Follow user", Hint(".follow-button")],
|
|
|
|
["s", "Like tweet", Hint(".js-actionFavorite")],
|
2018-07-27 03:51:25 +00:00
|
|
|
["R", "Retweet", Hint(".js-actionRetweet")],
|
2018-07-27 03:49:59 +00:00
|
|
|
["c", "Comment/Reply", Hint(".js-actionReply")],
|
|
|
|
["t", "New tweet", Hint(".js-global-new-tweet")],
|
|
|
|
["T", "Tweet to", Hint(".NewTweetButton")],
|
2018-07-27 03:51:25 +00:00
|
|
|
["r", "Load new tweets", Hint(".new-tweets-bar")],
|
2018-07-27 03:49:59 +00:00
|
|
|
["g", "Goto user", Hint(".js-user-profile-link")],
|
2017-12-02 02:48:58 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("reddit.com", [
|
2018-07-27 03:49:59 +00:00
|
|
|
["x", "Collapse comment", Hint(".expand")],
|
2018-08-09 23:42:57 +00:00
|
|
|
// Not supported by the QuerySelector API
|
|
|
|
// ["X", "Collapse next comment", Hint(".expand:visible:not(:contains('[+]')):nth(0)")],
|
2018-07-27 03:49:59 +00:00
|
|
|
["s", "Upvote", Hint(".arrow.up")],
|
|
|
|
["S", "Downvote", Hint(".arrow.down")],
|
|
|
|
["e", "Expand expando", Hint(".expando-button")],
|
|
|
|
["a", "View post (link)", Hint(".title")],
|
|
|
|
["c", "View post (comments)", Hint(".comments")],
|
2017-12-02 02:48:58 +00:00
|
|
|
])
|
|
|
|
|
2018-08-19 11:15:00 +00:00
|
|
|
const hnGoParent = () => {
|
|
|
|
const par = document.querySelector(".par>a")
|
|
|
|
if (!par) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
window.location.assign(par.href)
|
|
|
|
}
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
mapsitekeys("news.ycombinator.com", [
|
2018-07-27 03:49:59 +00:00
|
|
|
["x", "Collapse comment", Hint(".togg")],
|
2018-08-09 23:42:57 +00:00
|
|
|
// Not supported by the QuerySelector API
|
|
|
|
// ["X", "Collapse next comment", Hint(".togg:visible:contains('[-]'):nth(0)")],
|
2018-07-27 03:49:59 +00:00
|
|
|
["s", "Upvote", Hint(".votearrow[title='upvote']")],
|
|
|
|
["S", "Downvote", Hint(".votearrow[title='downvote']")],
|
|
|
|
["a", "View post (link)", Hint(".storylink")],
|
|
|
|
["c", "View post (comments)", Hint("td > a[href*='item']:not(.storylink)")],
|
2018-02-13 03:46:52 +00:00
|
|
|
["p", "Go to parent", hnGoParent],
|
2017-12-02 02:48:58 +00:00
|
|
|
])
|
|
|
|
|
2018-08-19 10:53:30 +00:00
|
|
|
const dribbbleAttachment = cb =>
|
|
|
|
Hint(".attachments .thumb", a => cb(a.src.replace("/thumbnail/", "/")))
|
|
|
|
|
2018-07-12 09:46:13 +00:00
|
|
|
mapsitekeys("dribbble.com", [
|
2018-07-27 03:49:59 +00:00
|
|
|
["s", "Heart Shot", Hint(".toggle-fav, .like-shot")],
|
2018-08-22 03:09:45 +00:00
|
|
|
["a", "View shot", Hint(".dribbble-over, .gif-target, .more-thumbs a")],
|
|
|
|
["A", "View shot", Hint(".dribbble-over, .gif-target, .more-thumbs a")],
|
|
|
|
["v", "View attachment image", dribbbleAttachment(a => tabOpenLink(a))],
|
|
|
|
["V", "Yank attachment image source URL", dribbbleAttachment(a => Clipboard.write(a))],
|
2018-08-23 08:17:31 +00:00
|
|
|
["z", "Zoom shot", Hint(".single-img picture, .detail-shot img")],
|
2018-07-12 09:46:13 +00:00
|
|
|
])
|
|
|
|
|
2018-08-23 09:15:43 +00:00
|
|
|
const wpToggleSimple = () => {
|
|
|
|
window.location.hostname = window.location.hostname.split(".")
|
|
|
|
.map((s, i) => {
|
|
|
|
if (i === 0) {
|
|
|
|
return s === "simple" ? "" : "simple"
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}).filter(s => s !== "").join(".")
|
|
|
|
}
|
|
|
|
|
|
|
|
mapsitekeys("wikipedia.org", [
|
|
|
|
["s", "Toggle simple version of current article", wpToggleSimple],
|
|
|
|
])
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
// ---- Search & completion ----//
|
|
|
|
// Search leader
|
|
|
|
const sl = "a"
|
|
|
|
|
|
|
|
// Register Search Engine Completions
|
|
|
|
// The `completions` variable is defined in `completions.js` and
|
|
|
|
// is prepended to this file by gulp-concat.
|
|
|
|
Object.keys(completions).forEach((k) => {
|
|
|
|
const s = completions[k] // Search Engine object
|
|
|
|
const la = sl + s.alias // Search leader + alias
|
|
|
|
|
|
|
|
addSearchAliasX(s.alias, s.name, s.search, sl, s.compl, s.callback)
|
2018-08-09 21:37:14 +00:00
|
|
|
mapkey(la, `#8Search ${s.name}`, () => Front.openOmnibar({ type: "SearchEngine", extra: s.alias }))
|
2017-12-02 02:48:58 +00:00
|
|
|
})
|
|
|
|
|
2017-08-28 03:24:24 +00:00
|
|
|
// vim: set ft=javascript expandtab:
|