Last active
March 7, 2025 01:29
-
-
Save swcho/36a9a36ca5631acb4cba1f3386591df9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
settings.showModeStatus = false; | |
settings.editableBodyCare = false; | |
// console.log('SurfingKeys', api) | |
// getEventListeners(window).copy?.forEach(({ listener }) => window.removeEventListener('copy', listener)) | |
// chrome.debugger.sendCommand({ tabId }, "Target.setAutoAttach", { | |
// autoAttach: true, | |
// waitForDebuggerOnStart: false, | |
// flatten: true, | |
// filter: [{ type: "iframe", exclude: false }] | |
// }).then(console.log); | |
function cleanUrl(url) { | |
try { | |
// URL 객체 생성 | |
const urlObj = new URL(url); | |
// 제거할 파라미터 목록 | |
const paramsToRemove = [ | |
'utm_source', | |
'utm_medium', | |
'utm_campaign', | |
'utm_term', | |
'utm_content', | |
'fbclid', | |
'gclid', | |
'dclid', | |
'_ga', | |
'igshid', | |
'mc_cid', | |
'mc_eid' | |
]; | |
// URLSearchParams 객체 생성 | |
const searchParams = new URLSearchParams(urlObj.search); | |
// 지정된 파라미터 제거 | |
paramsToRemove.forEach(param => { | |
searchParams.delete(param); | |
}); | |
// 새로운 search string 생성 | |
const newSearch = searchParams.toString(); | |
// 기본 URL 구성 (protocol + hostname + pathname) | |
let cleanedUrl = `${urlObj.protocol}//${urlObj.hostname}${urlObj.pathname}`; | |
// search params가 있으면 추가 | |
if (newSearch) { | |
cleanedUrl += `?${newSearch}`; | |
} | |
// hash가 있으면 추가 | |
if (urlObj.hash) { | |
cleanedUrl += urlObj.hash; | |
} | |
return cleanedUrl; | |
} catch (e) { | |
console.error('URL 정리 중 오류 발생:', e); | |
return url; // 오류 발생 시 원본 URL 반환 | |
} | |
} | |
api.mapkey('ymd', 'Copy a link as markdown', function () { | |
api.Hints.create('*[href]', function (element) { | |
api.Clipboard.write(`[${element.innerText}](${cleanUrl(element.href)})`); | |
}); | |
}); | |
api.mapkey('ymt', 'Copy current tab as markdown', function () { | |
api.Clipboard.write(`[${document.title}](${cleanUrl(location.href)})`); | |
}); | |
// api.mapkey('h', 'Hover item', function() { | |
// api.Hints.create('*[href]', function(element) { | |
// }); | |
// }); | |
api.mapkey('af', 'Active focuse', function () { | |
const targets = [...document.querySelectorAll('*')].filter((elem) => { | |
return elem.scrollHeight > elem.clientHeight + 10; | |
}); | |
// const targets = Mode.getScrollableElements() | |
api.Hints.create(targets, function (elm) { | |
// console.log({ elm, api }); | |
elm = elm.children[0]; | |
if (elm.scrollIntoViewIfNeeded) { | |
elm.scrollIntoViewIfNeeded(); | |
} else if (!api.isElementPartiallyInViewport(elm, ignoreSize)) { | |
elm.scrollIntoView(); | |
} | |
}); | |
}); | |
api.map('i', 'ii'); | |
api.unmap('i'); | |
api.map('d', 'j'); | |
api.map('e', 'k'); | |
api.imap(';;', '<Esc>'); // press comma twice to leave current input box. | |
api.iunmap('<Esc>'); // press comma twice to leave current input box. | |
api.mapkey('ii', 'Input', function () { | |
api.Hints.create( | |
'input:not([type=submit]), textarea, *[contenteditable=true], *[role=textbox], select, div.ace_cursor', | |
api.Hints.dispatchMouseClick, | |
); | |
}); | |
api.mapkey('im', 'Monaco input', function () { | |
const selector = 'textarea.monaco-mouse-cursor-text'; | |
const target = document.querySelector(selector); | |
api.Hints.dispatchMouseClick(target); | |
}); | |
api.mapkey('in', 'Monaco input with vim', function () { | |
const selector = 'textarea.monaco-mouse-cursor-text'; | |
const target = document.querySelector(selector); | |
api.Front.showEditor(target); | |
}); | |
let el_prev_open; | |
// api.map('F', 'gf'); | |
api.mapkey('F', 'custom', function () { | |
// api.Hints.create("", api.Hints.dispatchMouseClick, {tabbed: true, active: true}); | |
api.Hints.create( | |
'', | |
(...args) => { | |
if (el_prev_open) { | |
el_prev_open.classList.remove('sk_opened'); | |
el_prev_open.style.borderBottom = '1px solid rgba(255, 0, 0, 0.3)'; | |
} | |
const el = args[0]; | |
// console.log(el) | |
el.style.borderBottom = '2px solid red'; | |
el.classList.add('sk_opened'); | |
el_prev_open = el; | |
api.Hints.dispatchMouseClick(...args); | |
// RUNTIME("nextTab"); | |
}, | |
{ tabbed: true, active: true }, | |
); | |
}); | |
// returns true if the element or one of its parents has the class classname | |
function hasSomeParentTheClass(element, classname) { | |
if ((element.className?.split(' ').indexOf(classname) ?? -1)>=0) return true; | |
return element.parentNode && hasSomeParentTheClass(element.parentNode, classname); | |
} | |
api.mapkey('f', '#1Open a link, press SHIFT to flip overlapped hints, hold SPACE to hide hints', function () { | |
api.Hints.create( | |
'', | |
(...args) => { | |
const el = args[0] | |
// 메일 앱에서 더블클릭하자. | |
if (location.host === 'mail.navercorp.com' && hasSomeParentTheClass(el, 'menu_cover')) { | |
api.Hints.dispatchMouseClick(...args); | |
} | |
api.Hints.dispatchMouseClick(...args); | |
}, | |
); | |
}); | |
api.mapkey('C', '#1Open a link in non-active new tab', function() { | |
api.Hints.create("", (...args) => { | |
const el = args[0]; | |
el.style.borderBottom = '2px solid rgba(0, 255, 0, 1)'; | |
api.Hints.dispatchMouseClick(...args) | |
}, {tabbed: true, active: false}); | |
}); | |
api.mapkey('cf', '#1Open multiple links in a new tab', function() { | |
api.Hints.create("", (...args) => { | |
const el = args[0]; | |
el.style.borderBottom = '2px solid rgba(0, 255, 0, 1)'; | |
api.Hints.dispatchMouseClick(...args) | |
}, {multipleHits: true}); | |
}); | |
api.unmap('1', /flash-man-9d6a2.web.app/); | |
api.unmap('2', /flash-man-9d6a2.web.app/); | |
api.unmap('3', /flash-man-9d6a2.web.app/); | |
api.unmap('4', /flash-man-9d6a2.web.app/); | |
api.unmap('w', /flash-man-9d6a2.web.app/); | |
api.unmap('a', /flash-man-9d6a2.web.app/); | |
api.unmap('s', /flash-man-9d6a2.web.app/); | |
api.unmap('d', /flash-man-9d6a2.web.app/); | |
api.unmap('d', /mail.navercorp.com/); | |
api.unmap('t', /youtube.com/); | |
api.unmap('f', /youtube.com/); | |
api.unmap('>', /youtube.com/); | |
api.unmap('<', /youtube.com/); | |
api.unmap('x', /mail.google.com/); | |
api.unmapAllExcept([], /colab.research.google.com/); | |
// api.unmapAllExcept([], /localhost/); | |
// api.unmapAllExcept([], /.*.aida.navercorp.com/) | |
// an example to create a new mapping `ctrl-y` | |
api.mapkey('<ctrl-y>', 'Show me the money', function () { | |
Front.showPopup( | |
'a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).', | |
); | |
}); | |
settings.digitForRepeat = false; | |
// an example to replace `T` with `gt`, click `Default mappings` to see how `T` works. | |
// api.map('gt', 'T'); | |
// an example to remove mapkey `Ctrl-i` | |
// api.unmap('<ctrl-i>'); | |
// set theme | |
settings.theme = ` | |
.sk_theme { | |
font-family: Input Sans Condensed, Charcoal, sans-serif; | |
font-size: 10pt; | |
background: #24272e; | |
color: #abb2bf; | |
} | |
.sk_theme tbody { | |
color: #fff; | |
} | |
.sk_theme input { | |
color: #d0d0d0; | |
} | |
.sk_theme .url { | |
color: #61afef; | |
} | |
.sk_theme .annotation { | |
color: #56b6c2; | |
} | |
.sk_theme .omnibar_highlight { | |
color: #528bff; | |
} | |
.sk_theme .omnibar_timestamp { | |
color: #e5c07b; | |
} | |
.sk_theme .omnibar_visitcount { | |
color: #98c379; | |
} | |
.sk_theme #sk_omnibarSearchResult ul li:nth-child(odd) { | |
background: #303030; | |
} | |
.sk_theme #sk_omnibarSearchResult ul li.focused { | |
background: #3e4452; | |
} | |
#sk_status, #sk_find { | |
font-size: 20pt; | |
} | |
#sk_status { | |
opacity: 0.3; | |
} | |
.sk_opened { | |
border-bottom: 2px solid red; | |
} | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment