2017-12-02 02:48:58 +00:00
|
|
|
// ---- Cleanup ----//
|
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.hintGroups = true
|
2017-11-14 05:46:09 +00:00
|
|
|
// settings.hintGroupStart = "middle";
|
2017-12-02 02:48:58 +00:00
|
|
|
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
|
|
|
`
|
|
|
|
|
|
|
|
// ---- Site-Specific Settings ----//
|
|
|
|
if (/github\.com/.test(window.location.hostname)) {
|
|
|
|
settings.theme += `
|
|
|
|
sk_theme {
|
|
|
|
background: #000;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
.sk_theme tbody {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
.sk_theme input {
|
|
|
|
color: #d9dce0;
|
|
|
|
}
|
|
|
|
.sk_theme .url {
|
|
|
|
color: #2173c5;
|
|
|
|
}
|
|
|
|
.sk_theme .annotation {
|
|
|
|
color: #38f;
|
|
|
|
}
|
|
|
|
.sk_theme .omnibar_highlight {
|
|
|
|
color: #fbd60a;
|
|
|
|
}
|
|
|
|
.sk_theme ul>li:nth-child(odd) {
|
|
|
|
background: #1e211d;
|
|
|
|
}
|
|
|
|
.sk_theme ul>li.focused {
|
|
|
|
background: #4ec10d;
|
|
|
|
}`
|
|
|
|
}
|
2017-08-28 03:24:24 +00:00
|
|
|
|
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
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
// ---- Functions ----//
|
2017-08-28 03:24:24 +00:00
|
|
|
function fakeSpot() {
|
2017-12-02 02:48:58 +00:00
|
|
|
const url = `http://fakespot.com/analyze?url=${window.location.href}`
|
|
|
|
window.open(url, "_blank").focus()
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ytFullscreen() {
|
2017-12-02 02:48:58 +00:00
|
|
|
$(".ytp-fullscreen-button.ytp-button").click()
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function vimeoFullscreen() {
|
2017-12-02 02:48:58 +00:00
|
|
|
$(".fullscreen-icon").click()
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 08:14:46 +00:00
|
|
|
function ghStar(toggle) {
|
2017-12-02 02:48:58 +00:00
|
|
|
const repo = window.location.pathname.slice(1).split("/").slice(0, 2).join("/")
|
|
|
|
const cur = $("div.starring-container > form").filter(function filter() {
|
|
|
|
return $(this).css("display") === "block"
|
|
|
|
})
|
2017-08-28 03:24:24 +00:00
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
let star = "★"
|
|
|
|
let status = "starred"
|
|
|
|
let verb = "is"
|
2017-11-14 08:14:46 +00:00
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
const starred = $(cur).attr("class").indexOf("unstarred") === -1
|
2017-11-20 16:27:52 +00:00
|
|
|
if (starred && toggle) {
|
2017-12-02 02:48:58 +00:00
|
|
|
status = `un${status}`
|
|
|
|
star = "☆"
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 08:14:46 +00:00
|
|
|
if (toggle) {
|
2017-12-02 02:48:58 +00:00
|
|
|
$(cur).find("button").click()
|
|
|
|
verb = "has been"
|
2017-11-14 08:14:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
Front.showBanner(`${star} Repository ${repo} ${verb} ${status}!`)
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function glToggleStar() {
|
2017-12-02 02:48:58 +00:00
|
|
|
const repo = window.location.pathname.slice(1).split("/").slice(0, 2).join("/")
|
|
|
|
const action = `${$(".btn.star-btn > span").click().text().toLowerCase()}red`
|
|
|
|
let star = "☆"
|
2017-08-28 03:24:24 +00:00
|
|
|
if (action === "starred") {
|
2017-12-02 02:48:58 +00:00
|
|
|
star = "★"
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
2017-12-02 02:48:58 +00:00
|
|
|
Front.showBanner(`${star} Repository ${repo} ${action}`)
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function vimEditURL() {
|
2017-12-02 02:48:58 +00:00
|
|
|
Front.showEditor(window.location.href, (data) => {
|
|
|
|
window.location.href = data
|
|
|
|
}, "url")
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function whois() {
|
2017-12-02 02:48:58 +00:00
|
|
|
const url = `http://centralops.net/co/DomainDossier.aspx?dom_whois=true&addr=${window.location.hostname}`
|
|
|
|
window.open(url, "_blank").focus()
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dns() {
|
2017-12-02 02:48:58 +00:00
|
|
|
const url = `http://centralops.net/co/DomainDossier.aspx?dom_dns=true&addr=${window.location.hostname}`
|
|
|
|
window.open(url, "_blank").focus()
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dnsVerbose() {
|
2017-12-02 02:48:58 +00:00
|
|
|
const url = `http://centralops.net/co/DomainDossier.aspx?dom_whois=true&dom_dns=true&traceroute=true&net_whois=true&svc_scan=true&addr=${window.location.hostname}`
|
|
|
|
window.open(url, "_blank").focus()
|
2017-08-28 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 01:19:54 +00:00
|
|
|
function 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-16 01:19:54 +00:00
|
|
|
}
|
2017-09-17 23:26:02 +00:00
|
|
|
|
2017-11-14 05:46:09 +00:00
|
|
|
function getURLPath(count, domain) {
|
2017-12-02 02:48:58 +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}`
|
|
|
|
}
|
|
|
|
return path
|
2017-11-14 05:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyURLPath(count, domain) {
|
2017-12-02 02:48:58 +00:00
|
|
|
Front.writeClipboard(getURLPath(count, domain))
|
2017-11-14 05:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function viewGodoc() {
|
2017-12-02 02:48:58 +00:00
|
|
|
const repo = getURLPath(2, true)
|
|
|
|
tabOpenLink(`https://godoc.org/${repo}`)
|
2017-11-06 07:57:39 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 23:26:02 +00:00
|
|
|
function editSettings() {
|
2017-12-02 02:48:58 +00:00
|
|
|
tabOpenLink("/pages/options.html")
|
2017-09-17 23:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function redditCollapseComment() {
|
2018-07-27 02:59:08 +00:00
|
|
|
Hints.create(".expand", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function redditCollapseNextComment() {
|
|
|
|
Hints.create(".expand:visible:not(:contains('[+]')):nth(0)", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function redditExpando() {
|
|
|
|
Hints.create(".expando-button", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function redditUpvote() {
|
|
|
|
Hints.create(".arrow.up", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function redditDownvote() {
|
|
|
|
Hints.create(".arrow.down", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function redditViewLink() {
|
|
|
|
Hints.create(".title", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function redditViewComments() {
|
|
|
|
Hints.create(".comments", Hints.dispatchMouseClick)
|
2017-09-17 23:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hnCollapseComment() {
|
2018-07-27 02:59:08 +00:00
|
|
|
Hints.create(".togg", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function hnCollapseNextComment() {
|
|
|
|
Hints.create(".togg:visible:contains('[-]'):nth(0)", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function hnUpvote() {
|
|
|
|
Hints.create(".votearrow[title='upvote']", Hints.dispatchMouseClick)
|
2017-09-17 23:26:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 02:59:08 +00:00
|
|
|
function hnDownvote() {
|
|
|
|
Hints.create(".votearrow[title='downvote']", Hints.dispatchMouseClick)
|
2017-09-17 23:26:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 02:59:08 +00:00
|
|
|
function hnViewLink() {
|
|
|
|
Hints.create(".storylink", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function hnViewComments() {
|
|
|
|
Hints.create("td > a[href*='item']:not(.storylink)", Hints.dispatchMouseClick)
|
2017-09-17 23:26:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 05:46:09 +00:00
|
|
|
function twitterFollowUser() {
|
2017-12-02 02:48:58 +00:00
|
|
|
Hints.create(".follow-button", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
2018-07-27 02:59:08 +00:00
|
|
|
function twitterLikeTweet() {
|
|
|
|
Hints.create(".js-actionFavorite", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function twitterRetweet() {
|
|
|
|
Hints.create(".js-actionRetweet", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function twitterReply() {
|
|
|
|
Hints.create(".js-actionReply", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function twitterTweet() {
|
|
|
|
Hints.create(".js-global-new-tweet", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function twitterTweetTo() {
|
|
|
|
Hints.create(".NewTweetButton", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function twitterReload() {
|
|
|
|
Hints.create(".new-tweets-bar", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
function twitterGotoUser() {
|
|
|
|
Hints.create(".js-user-profile-link", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
2018-02-13 03:46:52 +00:00
|
|
|
function hnGoParent() {
|
|
|
|
const par = $(".par>a")
|
|
|
|
if (par.length <= 0) return
|
|
|
|
window.location.href = par[0].href
|
|
|
|
}
|
|
|
|
|
2018-07-12 09:46:13 +00:00
|
|
|
function dribbleHeartShot() {
|
|
|
|
Hints.create(".toggle-fav, .like-shot", Hints.dispatchMouseClick)
|
|
|
|
}
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
// ---- Mapkeys ----//
|
|
|
|
const ri = { repeatIgnore: true }
|
|
|
|
|
|
|
|
mapkey("=w", "Lookup whois information for domain", whois, ri)
|
|
|
|
mapkey("=d", "Lookup dns information for domain", dns, ri)
|
|
|
|
mapkey("=D", "Lookup all information for domain", dnsVerbose, ri)
|
|
|
|
mapkey(";se", "#11Edit Settings", editSettings, ri)
|
|
|
|
mapkey(";pd", "Toggle PDF viewer from SurfingKeys", togglePdfViewer, ri)
|
|
|
|
mapkey("gi", "Edit current URL with vim editor", vimEditURL, ri)
|
|
|
|
mapkey("yp", "Copy URL path of current page", () => copyURLPath(), ri)
|
|
|
|
|
|
|
|
const siteleader = "<Space>"
|
|
|
|
|
|
|
|
function mapsitekey(domainRegex, key, desc, f, o) {
|
|
|
|
const opts = o || {}
|
|
|
|
mapkey(`${siteleader}${key}`, desc, f, Object.assign({}, opts, { domain: domainRegex }))
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapsitekeys(d, maps) {
|
|
|
|
const domain = d.replace(".", "\\.")
|
|
|
|
const domainRegex = new RegExp(`^http(s)?://(([a-zA-Z0-9-_]+\\.)*)(${domain})(/.*)?`)
|
|
|
|
maps.forEach((map) => {
|
|
|
|
mapsitekey(domainRegex, map[0], map[1], map[2])
|
|
|
|
})
|
2017-11-14 05:46:09 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 02:48:58 +00:00
|
|
|
mapsitekeys("amazon.com", [
|
|
|
|
["fs", "Fakespot", fakeSpot],
|
|
|
|
// TODO: Add to cart
|
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("yelp.com", [
|
|
|
|
["fs", "Fakespot", fakeSpot],
|
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("youtube.com", [
|
|
|
|
["F", "Toggle fullscreen", ytFullscreen],
|
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("vimeo.com", [
|
|
|
|
["F", "Toggle fullscreen", vimeoFullscreen],
|
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("github.com", [
|
|
|
|
["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)],
|
|
|
|
["D", "View GoDoc for Project", viewGodoc],
|
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("gitlab.com", [
|
|
|
|
["s", "Toggle Star", glToggleStar],
|
|
|
|
["y", "Copy Project Path", () => copyURLPath(2)],
|
|
|
|
["Y", "Copy Project Path (including domain)", () => copyURLPath(2, true)],
|
|
|
|
["D", "View GoDoc for Project", viewGodoc],
|
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("twitter.com", [
|
2018-07-27 02:59:08 +00:00
|
|
|
["t", "New tweet", twitterTweet],
|
2017-12-02 02:48:58 +00:00
|
|
|
["f", "Follow user", twitterFollowUser],
|
2018-07-27 02:59:08 +00:00
|
|
|
["g", "Goto user", twitterGotoUser],
|
|
|
|
["s", "Like tweet", twitterLikeTweet],
|
|
|
|
["r", "Retweet", twitterRetweet],
|
|
|
|
["c", "Comment/Reply", twitterReply],
|
|
|
|
["T", "Tweet to", twitterTweetTo],
|
|
|
|
["R", "Load new tweets", twitterReload],
|
2017-12-02 02:48:58 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("reddit.com", [
|
2018-07-27 02:59:08 +00:00
|
|
|
["x", "Collapse comment", redditCollapseComment],
|
|
|
|
["X", "Collapse next comment", redditCollapseNextComment],
|
|
|
|
["s", "Upvote", redditUpvote],
|
|
|
|
["S", "Downvote", redditDownvote],
|
|
|
|
["e", "Expand expando", redditExpando],
|
|
|
|
["a", "View post (link)", redditViewLink],
|
|
|
|
["c", "View post (comments)", redditViewComments],
|
2017-12-02 02:48:58 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
mapsitekeys("news.ycombinator.com", [
|
2018-07-27 02:59:08 +00:00
|
|
|
["x", "Collapse comment", hnCollapseComment],
|
|
|
|
["X", "Collapse next comment", hnCollapseNextComment],
|
|
|
|
["s", "Upvote", hnUpvote],
|
|
|
|
["S", "Downvote", hnDownvote],
|
2018-02-13 03:46:52 +00:00
|
|
|
["p", "Go to parent", hnGoParent],
|
2018-07-27 02:59:08 +00:00
|
|
|
["a", "View post (link)", hnViewLink],
|
|
|
|
["c", "View post (comments)", hnViewComments],
|
2017-12-02 02:48:58 +00:00
|
|
|
])
|
|
|
|
|
2018-07-12 09:46:13 +00:00
|
|
|
mapsitekeys("dribbble.com", [
|
|
|
|
["s", "Heart Shot", dribbleHeartShot],
|
|
|
|
])
|
|
|
|
|
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)
|
|
|
|
mapkey(la, `#8Search ${s.name}`, `Front.openOmnibar({type: "SearchEngine", extra: "${s.alias}"})`)
|
|
|
|
})
|
|
|
|
|
2017-08-28 03:24:24 +00:00
|
|
|
// vim: set ft=javascript expandtab:
|