From b8e11312815e31bc1ed0d338ff5470b7cd783f00 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Sun, 11 Mar 2018 12:53:02 +0000 Subject: [PATCH 1/6] Add hint window/private (untested) --- src/hinting.ts | 38 ++++++++++++++++++++++++++++++++++++++ src/hinting_background.ts | 7 +++++++ 2 files changed, 45 insertions(+) diff --git a/src/hinting.ts b/src/hinting.ts index c6f7498d..fe9ae857 100644 --- a/src/hinting.ts +++ b/src/hinting.ts @@ -527,6 +527,44 @@ function hintPageOpenInBackground() { }) } +// lazily copied from excmds.ts - really ought to be moved to lib/webext +async function winopen(...args: string[]) { + let address: string + const createData = {} + if (args[0] === "-private") { + createData["incognito"] = true + address = args.slice(1,args.length).join(' ') + } else address = args.join(' ') + browser.windows.create(createData) +} + + +function hintPageWindow() { + hintPage(hintables(), hint=>{ + hint.target.focus() + if (hint.target.href) { + winopen(hint.target.href) + } else { + // This is to mirror vimperator behaviour. + simulateClick(hint.target) + } + }) +} + +function hintPageWindowPrivate() { + hintPage(hintables(), hint=>{ + hint.target.focus() + if (hint.target.href) { + // Try to open with the webext API. + winopen("--private",hint.target.href) + } else { + // Private window, so never fall back to opening in current tab + // This is to mirror vimperator behaviour. + // simulateClick(hint.target) + } + }) +} + function hintPageSimple(selectors=HINTTAGS_selectors) { hintPage(hintables(selectors), hint=>{ simulateClick(hint.target) diff --git a/src/hinting_background.ts b/src/hinting_background.ts index 3f471bdf..f16f27f4 100644 --- a/src/hinting_background.ts +++ b/src/hinting_background.ts @@ -32,6 +32,13 @@ export async function hintPageOpenInBackground() { return await messageActiveTab('hinting_content', 'hintPageOpenInBackground') } +export async function hintPageWindow() { + return await messageActiveTab('hinting_content', 'hintPageWindow') +} + +export async function hintPageWindowPrivate() { + return await messageActiveTab('hinting_content', 'hintPageWindowPrivate') +} export async function hintImage(inBackground) { return await messageActiveTab('hinting_content', 'hintImage', [inBackground]) } From 31824d8127ca0befdf8086eee4f979a52ee7f4b3 Mon Sep 17 00:00:00 2001 From: Isaac Khor Date: Mon, 12 Mar 2018 22:10:01 +0800 Subject: [PATCH 2/6] Remove link_hinting.coffee --- src/link_hinting.coffee | 47 ----------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 src/link_hinting.coffee diff --git a/src/link_hinting.coffee b/src/link_hinting.coffee deleted file mode 100644 index 224f9651..00000000 --- a/src/link_hinting.coffee +++ /dev/null @@ -1,47 +0,0 @@ -# Inspired by QuantumVim: https://github.com/shinglyu/QuantumVim - -BACKGROUND_COLOUR = "yellow" - -highlight_links = () -> - links = document.querySelectorAll('a') # Just handles links, not buttons/inputs etc. - code = 0 - for link in links - link_highlight(link, code) - code +=1 - - console.log(LINK_CODES) - return code - -LINK_CODES = {} - -link_highlight = (elem, code) -> - elem._background = elem.style.backgroundColor - elem._position = elem.style.position - # Why are these being saved? - elem.style.backgroundColor = BACKGROUND_COLOUR - elem.style.position="relative" - codehint = generate_codehint(code) - elem.appendChild(codehint) - LINK_CODES[String(code)] = { - element: elem - codehint - } - -generate_codehint = (code) -> - codehint = document.createElement('span') - codehint.textContent = "" + code - codehint.style.border = "solid 1 px black" - codehint.style.backgroundColor="white" - codehint.style.font="12px/14px bold sans-serif" - codehint.style.color="darkred" - codehint.style.position="absolute" - codehint.style.top="0" - codehint.style.left="0" - codehint.style.padding="0.1em" - codehint - -linkMessageHandler = (message) -> - switch(message.command) - when "hint" then highlight_links() - -browser.runtime.onMessage.addListener(linkMessageHandler) From c042fd14b3fa75766dd8e05c8d2854d4684c29b4 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Mon, 12 Mar 2018 17:07:42 +0000 Subject: [PATCH 3/6] Add winopen equivalent to webext.ts, add and document private and window hints --- src/excmds.ts | 4 ++++ src/hinting.ts | 23 +++++------------------ src/hinting_background.ts | 1 + src/lib/webext.ts | 6 ++++++ 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/excmds.ts b/src/excmds.ts index 0bc8a2c8..0611e3b7 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -1623,6 +1623,8 @@ import * as hinting from './hinting_background' - -# yank an element's anchor URL to clipboard - -c [selector] hint links that match the css selector - `bind ;c hint -c [class*="expand"],[class="togg"]` works particularly well on reddit and HN + - -w open in new window + -wp open in new private window Excepting the custom selector mode and background hint mode, each of these hint modes is available by default as `;