mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 17:11:40 -05:00
added timeout flag for automatically closing displayed qr code
This commit is contained in:
parent
a467747057
commit
cb29ce41a5
3 changed files with 21 additions and 2 deletions
|
@ -5907,6 +5907,7 @@ export async function text2qr(...args: string[]) {
|
|||
let text: string = null
|
||||
let isParsed = false
|
||||
let openMode = null
|
||||
let timeout = "-1"
|
||||
while (!isParsed) {
|
||||
switch (args[0]) {
|
||||
case "--window":
|
||||
|
@ -5921,6 +5922,11 @@ export async function text2qr(...args: string[]) {
|
|||
openMode = open
|
||||
args.shift()
|
||||
break
|
||||
case "--timeout":
|
||||
args.shift()
|
||||
timeout = args[0]
|
||||
args.shift()
|
||||
break
|
||||
default:
|
||||
isParsed = true
|
||||
break
|
||||
|
@ -5937,6 +5943,7 @@ export async function text2qr(...args: string[]) {
|
|||
const urlEncodedText = encodeURIComponent(text)
|
||||
const url = new URL(browser.runtime.getURL("static/qrcode.html"))
|
||||
url.searchParams.append("data", btoa(urlEncodedText))
|
||||
url.searchParams.append("timeout", timeout)
|
||||
openMode(url.href)
|
||||
}
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ export class default_config {
|
|||
T: "current_url tabopen",
|
||||
yy: "clipboard yank",
|
||||
ys: "clipboard yankshort",
|
||||
yq: "text2qr",
|
||||
yq: "text2qr --timeout 5",
|
||||
yc: "clipboard yankcanon",
|
||||
ym: "clipboard yankmd",
|
||||
yo: "clipboard yankorg",
|
||||
|
@ -394,7 +394,7 @@ export class default_config {
|
|||
w: 'js document.getSelection().modify("extend","forward","word"); document.getSelection().modify("extend","forward","word"); document.getSelection().modify("extend","backward","word"); document.getSelection().modify("extend","forward","character")',
|
||||
b: 'js document.getSelection().modify("extend","backward","character"); document.getSelection().modify("extend","backward","word"); document.getSelection().modify("extend","forward","character")',
|
||||
j: 'js document.getSelection().modify("extend","forward","line")',
|
||||
q: "composite js document.getSelection().toString() | text2qr",
|
||||
q: "composite js document.getSelection().toString() | text2qr --timeout 5",
|
||||
// "j": 'js document.getSelection().modify("extend","forward","paragraph")', // not implemented in Firefox
|
||||
k: 'js document.getSelection().modify("extend","backward","line")',
|
||||
$: 'js document.getSelection().modify("extend","forward","lineboundary")',
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import QRCode from "../vendor/qrcode"
|
||||
import * as Logging from "@src/lib/logging"
|
||||
import {browserBg, activeTab} from "./lib/webext"
|
||||
|
||||
const logger = new Logging.Logger("qrcode-display")
|
||||
|
||||
|
@ -16,6 +17,7 @@ function setUpPage() {
|
|||
|
||||
const url = new URL(window.location.href)
|
||||
let data = url.searchParams.get("data")
|
||||
const timeout = parseInt(url.searchParams.get("timeout"), 10)
|
||||
data = decodeURIComponent(atob(data))
|
||||
const opts = {
|
||||
scale: 10,
|
||||
|
@ -29,6 +31,16 @@ function setUpPage() {
|
|||
imgElem.src = url
|
||||
}
|
||||
})
|
||||
|
||||
if (timeout && timeout > 0) {
|
||||
setTimeout(function() {
|
||||
activeTab().then((tabInfo) => {
|
||||
browserBg.tabs.remove(tabInfo.id)
|
||||
}).catch((error) => {
|
||||
logger.error("Unable to close tab" + error)
|
||||
})
|
||||
}, timeout * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("load", setUpPage)
|
||||
|
|
Loading…
Add table
Reference in a new issue