Last active
November 7, 2019 13:40
-
-
Save ClassicOldSong/2849baadb61a4218e2950dd0ca7bd9de to your computer and use it in GitHub Desktop.
My SurfingKeys Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Original gist from deluxghost | |
* https://gist.github.com/deluxghost/f15e304ab18214e6a39587e17b63dd4d | |
*/ | |
unmap('cp'); | |
unmap('spa'); | |
unmap('spb'); | |
unmap('spd'); | |
unmap('sps'); | |
unmap('spc'); | |
unmap('spi'); | |
unmap('sfr'); | |
unmap('<Ctrl-h>'); | |
unmap('<Ctrl-j>'); | |
unmap('ab'); | |
unmap('af'); | |
// unmap('gt'); | |
// unmap('[['); | |
// unmap(']]'); | |
// unmap('B'); | |
settings.prevLinkRegex = /(((?:上|前)一?(?:页|章|頁)|(?:较|較|稍)新的?文章|prev(ious)?|newer|back|<<)+)/i; | |
settings.nextLinkRegex = /(((?:下|后)一?(?:页|章|頁)|早期的?文章|(?:较|較|稍)(?:早|旧|舊)的?文章|next|older|forward|>>)+)/i; | |
// mapkey('F', '#1Open a link in new tab', 'Hints.create("", Hints.dispatchMouseClick, {tabbed: true})'); | |
mapkey('a', '#1Mouse over elements.', () => Hints.create('', Hints.dispatchMouseClick, {mouseEvents: ['mouseover']})); | |
mapkey('A', '#1Mouse out elements.', () => Hints.create('', Hints.dispatchMouseClick, {mouseEvents: ['mouseout']})); | |
mapkey('<Ctrl-b>', '#8Bookmark current page to selected folder', function() { | |
var page = { | |
url: window.location.href, | |
title: document.title | |
}; | |
Front.openOmnibar(({type: 'AddBookmark', extra: page})); | |
}); | |
// mapkey('[[', '#1Click on the previous link on current page', function() { | |
// var prevLinks = $('a').regex(/(((?:上|前)一?(?:页|章|頁)|(?:较|較|稍)新的?文章|prev(ious)?|newer|back|<<)+)/i); | |
// if (prevLinks.length) { | |
// clickOn(prevLinks); | |
// } else { | |
// walkPageUrl(-1); | |
// } | |
// }); | |
// mapkey(']]', '#1Click on the next link on current page', function() { | |
// var nextLinks = $('a').regex(/(((?:下|后)一?(?:页|章|頁)|早期的?文章|(?:较|較|稍)(?:早|旧|舊)的?文章|next|older|forward|>>)+)/i); | |
// if (nextLinks.length) { | |
// clickOn(nextLinks); | |
// } else { | |
// walkPageUrl(1); | |
// } | |
// }); | |
map('u', 'X'); | |
map('gt', 'R'); | |
map('gT', 'E'); | |
// steam search | |
addSearchAliasX('t', 'steam', 'http://store.steampowered.com/search/?term=', '', 'http://store.steampowered.com/search/suggest?f=games&term=', function(response) { | |
var res = response.text; | |
var element = document.createElement('html'); | |
element.innerHTML = res; | |
var match = element.getElementsByClassName('match_name'); | |
var game = Array(); | |
for (var i = 0; i < match.length; i++) { | |
game.push(match[i].innerText); | |
} | |
return game; | |
}); | |
// iciba search | |
addSearchAliasX('c', 'iciba', 'http://www.iciba.com/', 's', 'http://dict-mobile.iciba.com/interface/index.php?c=word&m=getsuggest&nums=10&client=6&word=', (resp) => { | |
resp = JSON.parse(resp.text); | |
if (resp.status !== 1) return ['No results found.']; | |
const wordList = resp.message.map(i => i.key); | |
return wordList; | |
}); | |
// iciba quick open | |
mapkey('oc', '#8Open Search with iciba', () => Front.openOmnibar({type: "SearchEngine", extra: "c"})); | |
const browserFactory = () => { | |
try { | |
console.log('[Surfingkeys]', 'trying browser'); | |
return browser; | |
} catch(e) { | |
console.log('[Surfingkeys]', 'error:', e.message); | |
console.log('[Surfingkeys]', 'using chrome'); | |
return chrome; | |
} | |
}; | |
const b = browserFactory(); | |
// iciba quick search | |
const extBaseURL = b.runtime.getURL(''); | |
const extractMeans = (key, means, mdWordList) => { | |
mdWordList.push(`## [${key}](http://www.iciba.com/${key}) \n\n${means.map(i => `${i.part ? `*${i.part}*\n\n` : ''}${i.means.map(j => `- ${j}`).join('\n')}`).join('\n\n')}`); | |
if (means.length === 0) return [key]; | |
return means.map(i => `${key} ${i.part ? `[${i.part}] ` : ''}${i.means.join(' / ')}`); | |
}; | |
addSearchAlias( | |
'cq', | |
'iciba quick', | |
`${extBaseURL}/pages/markdown.html?s=data:text/plain;charset=UTF-8,`, | |
'https://dict-mobile.iciba.com/interface/index.php?c=word&m=getsuggest&nums=10&client=6&is_need_mean=1&word=', | |
(resp) => { | |
resp = JSON.parse(resp.text); | |
if (resp.status !== 1) return ['No result found.']; | |
let mdWordList = ['# Quick Search Results']; | |
const wordList = ['*Preview with Markdown with the last selection.*'].concat(...resp.message.map(i => extractMeans(i.key, i.means, mdWordList))); | |
wordList.push(encodeURIComponent(mdWordList.join('\n\n'))); | |
return wordList; | |
} | |
); | |
// iciba quick search quick open | |
mapkey('oq', '#8Quick Search with iciba', () => Front.openOmnibar({type: "SearchEngine", extra: "cq"})); | |
// MDN search | |
addSearchAliasX('n', 'MDN', 'https://mdn.io/'); | |
// MDN search quick open | |
mapkey('om', '#8Open Search with MDN', () => Front.openOmnibar({type: "SearchEngine", extra: "n"})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment