Skip to content

Commit

Permalink
Migrate customization from use-pre-1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stepnem committed Feb 14, 2023
1 parent 7c7ceaa commit 48633c8
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 39 deletions.
56 changes: 56 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1204,4 +1204,60 @@ actions.doi.getLink = (provider) => {
return priv.doi_handler(doi)
}

// SN
// ==
const gistUrl = `https://gist.githubusercontent.com/stepnem/7d5ae5a5c6f8d356b3b9ee03ebcbe7ea/raw/settings.js?flushcachebogusparam=${Math.random()}`

actions.reloadSettings = () => RUNTIME("loadSettingsFromUrl", {
url: gistUrl,
}, (res) => {
Front.showPopup(`${res.status} to load settings from ${gistUrl}`)
})

actions.duplicateTab = () =>
actions.openLink(util.getCurrentLocation("href"), { newTab: true, active: false })()

// Org Protocol
// ------------

actions.orgProtocol = {
storeLink: () => {
document.location.href = `org-protocol://store-link${util.buildQuery()}`
},
capture: () => {
document.location.href = `org-protocol://capture${util.buildQuery()}`
},
elfeed: (url) => {
document.location.href = `org-protocol://capture${util.buildQuery({ template: "f", url })}`
},
}

// Style
// -----

actions.snMaxwidthCss = "body { max-width: 730px; }"
actions.snMaxwidthEnsureStyle = (enable) => {
if (!actions.snStyleMaxwidth) {
actions.snStyleMaxwidth = document.createElement("style")
actions.snStyleMaxwidth.innerText = enable ? actions.snMaxwidthCss : ""
document.head.appendChild(actions.snStyleMaxwidth)
}
}
actions.snWideSites = "https://gist.githubusercontent.com/stepnem/116607569044837247f92169098186a6/raw/wide-sites.txt?flushcachebogusparam=apsodifj"
fetch(actions.snWideSites)
.then((response) => response.text())
.then((text) => {
for (const line of text.split(/\n/)) {
if (!line.match(/^#|^\s*$/) && window.location.href.match(line)) {
actions.snMaxwidthEnsureStyle(true)
}
}
})

actions.limitTextWidth = () => {
actions.snMaxwidthEnsureStyle()
actions.snStyleMaxwidth.innerText = actions.snStyleMaxwidth.innerText
? "" : actions.snMaxwidthCss
}

export default actions
16 changes: 11 additions & 5 deletions src/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ import keys from "./keys.js"
import searchEngines from "./search-engines.js"

export default {
// https://github.com/brookhong/Surfingkeys/wiki/Example-Configurations
settings: {
hintAlign: "left",
hintCharacters: "qwertasdfgzxcvb",
clickablePat: /(https?:\/\/|thunder:\/\/|magnet:)[^<>,'"\s]+/ig,
defaultSearchEngine: "dd",
focusAfterClosed: "last",
hintAlign: "left",
omnibarSuggestionTimeout: 500,
richHintsForKeystroke: 1,
defaultSearchEngine: "dd",
pageUrlRegex: [/(.*?)(\d+)([^0-9]*$)/, /(.*)(\d+)([^.]*?$)/],
richHintsForKeystroke: 100,
// this is needed, --disable-smooth-scrolling doesn't suffice
smoothScroll: false,
tabsMRUOrder: false,
theme,
},

keys,
searchEngines,

// Leader for site-specific mappings
siteleader: "<Space>",
siteleader: "\\",

// Leader for OmniBar searchEngines
searchleader: "a",
Expand Down
144 changes: 114 additions & 30 deletions src/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@ import util from "./util.js"

const { categories } = help

const { Clipboard, Front } = api
const { Clipboard, Front, Hints } = api

// Remove undesired default mappings
const unmaps = {
mappings: [
"sb",
"sw",
"ob",
"oe",
"ow",
"oy",
"cp",
";cp",
";ap",
"spa",
"spb",
"spd",
"sps",
"spc",
"spi",
"sfr",
"zQ",
"zz",
"zR",
"ab",
"Q",
"q",
"ag",
// "sb",
// "sw",
// "ob",
// "oe",
// "ow",
// "oy",
// "cp",
// ";cp",
// ";ap",
// "spa",
// "spb",
// "spd",
// "sps",
// "spc",
// "spi",
// "sfr",
// "zQ",
// "zz",
// "zR",
// "ab",
// "Q",
// "q",
// "ag",
"af",
";s",
"yp",
"p",
"<Ctrl-j>",
"<Ctrl-h>",
// ";s",
// "yp",
// "p",
// "<Ctrl-j>",
// "<Ctrl-h>",
],
searchAliases: {
s: ["g", "d", "b", "e", "w", "s", "h", "y"],
// s: ["g", "d", "b", "e", "w", "s", "h", "y"],
},
}

Expand Down Expand Up @@ -296,6 +296,90 @@ maps.global = [
// description: "Open AWS service",
// callback: actions.omnibar.aws,
// },
{
alias: "F",
category: categories.mouseClick,
description: "Open a link in active new tab",
callback: () => Hints.create("", Hints.dispatchMouseClick, { tabbed: true, active: true }),
},
{
alias: "y#",
category: categories.clipboard,
description: "Copy anchor URL to clipboard",
callback: () => util.createHints("[id]", (e) => {
const url = new URL(window.location.href)
url.hash = e.id || e.name
Clipboard.write(url.href)
}),
},
{
alias: "yu",
category: categories.misc,
description: "Send URL to mpv",
callback: () => util.createHints("*[href]", (e) => {
const message = {
kind: "native",
data: { kind: "spawn", command: ["mpv", e.href] },
}
// console.log("yu: sending " + message)
browser.runtime.sendMessage("omnibus@stepnem", message)
// .then(console.log, console.error)
}),
},
{
alias: "<Ctrl-Insert>",
map: "<Alt-s>",
category: categories.help,
description: "Toggle SurfingKeys on current site",
},
{
alias: "<BS>",
map: "2u",
category: categories.scroll,
description: "Scroll a page up",
},
{
alias: ",",
map: "<Ctrl-6>",
category: categories.tabs,
description: "Go to last used tab",
},
{
alias: ";;",
category: categories.mouseClick,
description: "Focus element",
callback: () => util.createHints("*[href]", (e) => e.focus()),
},
{
alias: ";pu",
category: categories.settings,
description: "Reload settings from gist",
callback: () => actions.reloadSettings(),
},
{
alias: ";oc",
category: categories.misc,
description: "Org capture",
callback: () => actions.orgProtocol.capture(),
},
{
alias: ";of",
category: categories.misc,
description: "Add elfeed link",
callback: () => util.createHints("*[href]", (e) => actions.orgProtocol.elfeed(e.href)),
},
{
alias: ";ol",
category: categories.misc,
description: "Org store link",
callback: () => actions.orgProtocol.storeLink(),
},
{
alias: ";v",
category: categories.misc,
description: "Limit max text width",
callback: () => actions.limitTextWidth(),
},
]

maps["amazon.com"] = [
Expand Down
84 changes: 80 additions & 4 deletions src/search-engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,10 @@ completions.wa.callback = (response, { query }) => {

// DuckDuckGo
completions.dd = {
alias: "dd",
name: "duckduckgo",
search: "https://duckduckgo.com/?q=",
compl: "https://duckduckgo.com/ac/?q=",
alias: "dd",
name: "duckduckgo",
search: "https://html.duckduckgo.com/html?q=",
compl: "https://duckduckgo.com/ac/?q=",
}

completions.dd.callback = (response) =>
Expand Down Expand Up @@ -1286,4 +1286,80 @@ completions.hf.callback = (response) => {
]
}

completions.dw = {
alias: "dw",
name: "dwds",
search: "https://www.dwds.de/?q=",
// compl: "https://www.dwds.de/opensearch/suggest?q=",
compl: "https://www.dwds.de/wb/typeahead?q=",
}
completions.dw.callback = (res) =>
JSON.parse(res.text).map((o) =>
createSuggestionItem(`
<div class="title"><strong>${o.value}</strong> (${o.pos})</div>
`))

completions.pr = {
alias: "pr",
name: "repology",
search: "https://repology.org/projects/?search=",
}

completions.sp = {
alias: "sp",
name: "startpage",
search: "https://www.startpage.com/do/dsearch?prfe=36c84513558a2d34bf0d89ea505333ad8572cfaa3e9208e97c6a33f2d1323e6d5c431b4299889bafd598b949d91446c9&query=",
compl: "https://www.startpage.com/do/suggest?limit=10&lang=english&format=json&query=",
callback: (res) => JSON.parse(res.text)[1],
}

completions.mc = {
alias: "mc",
name: "mapy",
search: "https://mapy.cz/?q=",
compl: "https://pro.mapy.cz/suggest/?count=5&enablecategories=1&phrase=",
}
completions.mc.callback = (res) => JSON.parse(res.text)
.result.map((e) => createSuggestionItem(`
<div>
<div class="title"><strong>${e.userData.suggestFirstRow}</strong></div>
<div>${e.userData.suggestSecondRow}</div>
</div>
`))

completions.ra = {
alias: "ra",
name: "racket",
search: "https://docs.racket-lang.org/search/index.html?q=",
}

completions.jw = {
alias: "jw",
name: "jwiki",
search: "https://code.jsoftware.com/mediawiki/index.php?title=Special%3ASearch&go=Go&search=",
compl: "https://code.jsoftware.com/mediawiki/api.php?action=opensearch&format=json&formatversion=2&namespace=0|2&limit=10&suggest=true&search=",
callback: (res) => JSON.parse(res.text)[1],
}

completions.jf = {
alias: "jf",
name: "jforums",
search: "https://www.jsoftware.com/cgi-bin/forumsearch.cgi?all=",
}

completions.ut = {
alias: "ut",
name: "uloz.to",
search: "https://uloz.to/hledej?q=",
compl: "https://uloz.to/searchSuggest.php?term=",
callback: (res) => JSON.parse(res.text).map((el) => el.term),
}

// https://www.mail-archive.com/search?l=pacman-dev%40archlinux.org&q=stuff
completions.ma = {
alias: "ma",
name: "mail-archive",
search: "https://www.mail-archive.com/search?l=all&q=",
}

export default completions
19 changes: 19 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,23 @@ util.prettyDate = (date) => {
}${count ? " ago" : ""}`
}

// buildQuery: (overrides = {
// url = document.location.href,
// title = document.title,
// body = window.getSelection(),
// template,
// } = {}) =>
util.buildQuery = (overrides = {}) => {
const params = {
url: document.location.href,
title: document.title,
body: window.getSelection(),
...overrides,
}
// eslint-disable-next-line prefer-template
return "?" + Object.entries(params)
.flatMap(([key, val]) => `${key}=${encodeURIComponent(val)}`)
.join("&")
}

export default util

0 comments on commit 48633c8

Please sign in to comment.