/** * Default config * https://github.com/brookhong/Surfingkeys/blob/d96246d3a37abead7899d2b197b7f0dbe050cc95/pages/default.js#L258 */ function alias(key, target, replace = false) { api.map(key, target) if (replace) api.unmap(target) } function addProvider(key, name, url, ...args) { api.addSearchAlias(key, name, url, ...args) api.mapkey(`o${key}`, `#8Open Search with alias ${key}`, () => api.Front.openOmnibar({ type: 'SearchEngine', extra: key }) ) } function scroll(amount = 0) { window.scrollTo(0, window.pageYOffset + amount) } function options() { // api.Hints.setCharacters('asdfghjkl;') chrome.storage.local.set({ noPdfViewer: 1 }) settings.caseSensitive = true // settings.smartCase = true; } function mappings() { // DEBUG api.mapkey('', '#0 debug', () => { console.log('api', api) console.log('settings', settings) }) // TODO RJH // Disable surfing keys for page // map('', '') // HISTORY alias('H', 'S', true) alias('L', 'D', true) // TABS // close alias('D', 'x', true) // reopen alias('u', 'X', true) // mute alias('gM', '', true) // pin alias('gp', '', true) alias('', '', true) // TODO RJH // mapp('', '#2 Unpin tab', () => { // RUNTIME('togglePinTab') // }) // alt-tab (pun) alias('', 'gt') api.mapkey(',r', '#4 Reload the page uncached', () => api.RUNTIME('reloadTab', { nocache: true }) ) api.mapkey('p', '#7 Paste URL in current tab', () => { api.Clipboard.read(({ data }) => (window.location.href = data)) }) api.mapkey('P', '#7 Paste URL in new tab', () => { api.Clipboard.read(({ data }) => api.tabOpenLink(data)) }) // SCROLLING api.mapkey('', '#2 page up', () => scroll(-1 * 0.9 * window.innerHeight) ) api.mapkey('', '#2 page down', () => scroll(1 * 0.9 * window.innerHeight) ) api.mapkey('', '#2 half page up', () => scroll(-1 * 0.45 * window.innerHeight) ) api.mapkey('', '#2 half page down', () => scroll(1 * 0.45 * window.innerHeight) ) // INPUT api.mapkey('ga', '#1 Go to last input', () => api.Hints.create( 'input[type=text]:last-of-type', api.Hints.dispatchMouseClick ) ) // TODO RJH // alias('', '', true) // alias('', '', true) alias('', '') alias('', '') } function unmappings() { api.unmap('C') api.unmap('d') // disable emojis api.iunmap(':') } function providers() { addProvider('T', 'twitch', 'https://twitch.tv/') addProvider('r', 'reddit', 'https://www.reddit.com/r/') addProvider( 'w', 'wikipedia', 'https://en.wikipedia.org/wiki/', 's', 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&formatversion=2&namespace=0&limit=40&search=', (response) => { return JSON.parse(response.text)[1] } ) } function exceptions() { api.unmapAllExcept([], /\/mail.google.com\//) } ;(function main() { options() mappings() unmappings() providers() exceptions() })()