• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript config.getAsync函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript controller.acceptExCmd函数代码示例发布时间:2022-05-28
下一篇:
TypeScript config.get函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap