当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript config.getAsync函数代码示例

本文整理汇总了TypeScript中@src/lib/config.getAsync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getAsync函数的具体用法?TypeScript getAsync怎么用?TypeScript getAsync使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getAsync函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: init

/** Initialise the cmdline_iframe element unless the window location is included in a value of config/noiframe */
async function init() {
    const noiframe = await config.getAsync("noiframe")
    if (noiframe === "false" && !enabled) {
        hide()
        document.documentElement.appendChild(cmdline_iframe)
        enabled = true
        // first theming of page root
        await theme(window.document.querySelector(":root"))
    }
}
开发者ID:antonva,项目名称:tridactyl,代码行数:11,代码来源:commandline_content.ts

示例2: theme

export async function theme(element) {
    // Remove any old theme
    for (const theme of THEMES.map(prefixTheme)) {
        element.classList.remove(theme)
    }
    if (insertedCSS) {
        // Typescript doesn't seem to be aware than remove/insertCSS's tabid
        // argument is optional
        await browserBg.tabs.removeCSS(await ownTabId(), customCss)
        insertedCSS = false
    }

    const newTheme = await config.getAsync("theme")

    // Add a class corresponding to config.get('theme')
    if (newTheme !== "default") {
        element.classList.add(prefixTheme(newTheme))
    }

    // Insert custom css if needed
    if (newTheme !== "default" && !THEMES.includes(newTheme)) {
        customCss.code = await config.getAsync("customthemes", newTheme)
        if (customCss.code) {
            await browserBg.tabs.insertCSS(await ownTabId(), customCss)
            insertedCSS = true
        } else {
            logger.error("Theme " + newTheme + " couldn't be found.")
        }
    }

    // Record for re-theming
    // considering only elements :root (page and cmdline_iframe)
    // TODO:
    //     - Find ways to check if element is already pushed
    if (
        THEMED_ELEMENTS.length < 2 &&
        element.tagName.toUpperCase() === "HTML"
    ) {
        THEMED_ELEMENTS.push(element)
    }
}
开发者ID:antonva,项目名称:tridactyl,代码行数:41,代码来源:styling.ts

示例3:

window.addEventListener("load", _ => {
    const spoilerbutton = document.getElementById("spoilerbutton")
    if (!spoilerbutton) {
        console.error("Couldn't find spoiler button!")
        return
    }
    spoilerbutton.addEventListener("click", readChangelog)
    config.getAsync("newtabfocus").then(f => {
        if (f === "page") {
            window.focus()
        }
    })
})
开发者ID:antonva,项目名称:tridactyl,代码行数:13,代码来源:newtab.ts

示例4:

 const onKeyUp = async ev => {
     const input = ev.target
     if (ev.key === "Enter") {
         (window as any).tri.messaging.message(
             "controller_background",
             "acceptExCmd",
             ["set " + input.name + " " + input.value],
         )
     } else {
         if (input.value === (await config.getAsync(input.name.split(".")))) {
             input.className = inputClassName
         } else {
             input.className = inputClassNameModified
         }
     }
 }
开发者ID:antonva,项目名称:tridactyl,代码行数:16,代码来源:help.ts

示例5:

browser.runtime.onStartup.addListener(_ => {
    config.getAsync("autocmds", "TriStart").then(aucmds => {
        const hosts = Object.keys(aucmds)
        // If there's only one rule and it's "all", no need to check the hostname
        if (hosts.length === 1 && hosts[0] === ".*") {
            controller.acceptExCmd(aucmds[hosts[0]])
        } else {
            native.run("hostname").then(hostname => {
                for (const host of hosts) {
                    if (hostname.content.match(host)) {
                        controller.acceptExCmd(aucmds[host])
                    }
                }
            })
        }
    })
})
开发者ID:antonva,项目名称:tridactyl,代码行数:17,代码来源:background.ts

示例6: addCSPListener

// {{{ Clobber CSP

// This should be removed once https://bugzilla.mozilla.org/show_bug.cgi?id=1267027 is fixed
function addCSPListener() {
    browser.webRequest.onHeadersReceived.addListener(
        request.clobberCSP,
        { urls: ["<all_urls>"], types: ["main_frame"] },
        ["blocking", "responseHeaders"],
    )
}

function removeCSPListener() {
    browser.webRequest.onHeadersReceived.removeListener(request.clobberCSP)
}

config.getAsync("csp").then(csp => csp === "clobber" && addCSPListener())

config.addChangeListener("csp", (old, cur) => {
    if (cur === "clobber") {
        addCSPListener()
    } else {
        removeCSPListener()
    }
})

// }}}

// Prevent Tridactyl from being updated while it is running in the hope of fixing #290
browser.runtime.onUpdateAvailable.addListener(_ => undefined)

browser.runtime.onStartup.addListener(_ => {
开发者ID:antonva,项目名称:tridactyl,代码行数:31,代码来源:background.ts

示例7:

const cb = async mutationList => {
    const theme = await config.getAsync("theme")
    mutationList
        .filter(m => m.target.className.search(prefixTheme("")) === -1)
        .forEach(m => m.target.classList.add(prefixTheme(theme)))
}
开发者ID:antonva,项目名称:tridactyl,代码行数:6,代码来源:styling.ts

示例8: listen

        ContentController.canceller.cancelKeyPress,
        true,
    )
    elem.addEventListener(
        "keyup",
        ContentController.canceller.cancelKeyUp,
        true,
    )
}
listen(window)
document.addEventListener("readystatechange", _ =>
    getAllDocumentFrames().forEach(f => listen(f)),
)

// Prevent pages from automatically focusing elements on load
config.getAsync("preventautofocusjackhammer").then(allowautofocus => {
    if (allowautofocus === "false") {
        return
    }
    const preventAutoFocus = () => {
        // First, blur whatever element is active. This will make sure
        // activeElement is the "default" active element
        ; (document.activeElement as any).blur()
        const elem = document.activeElement as any
        // ???: We need to set tabIndex, otherwise we won't get focus/blur events!
        elem.tabIndex = 0
        const focusElem = () => elem.focus()
        elem.addEventListener("blur", focusElem)
        elem.addEventListener("focusout", focusElem)
        // On top of blur/focusout events, we need to periodically check the
        // activeElement is the one we want because blur/focusout events aren't
开发者ID:antonva,项目名称:tridactyl,代码行数:31,代码来源:content.ts


注:本文中的@src/lib/config.getAsync函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。