以编程方式(或可选)覆盖 Chrome 的新标签页 [英] Programmatically (or optionally) override Chrome's New Tab page

查看:17
本文介绍了以编程方式(或可选)覆盖 Chrome 的新标签页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 Chrome 扩展程序,它 项目没有选项显示本机新标签.

解决方案

Google 制作了一个 星球大战新标签替换,它允许您查看默认的新标签页.它使用的 url 是 chrome-search://local-ntp/local-ntp.html.

示例:

options.html:

使用默认的新标签页

options.js:

var checkbox = document.querySelector("input[type=checkbox]")checkbox.addEventListener(点击",函数(){chrome.storage.sync.set({ defaultnewtab: checkbox.checked })})

newtab.js:

chrome.storage.sync.get("defaultnewtab", function(storage) {如果(存储.默认新标签){chrome.tabs.update({ url: "chrome-search://local-ntp/local-ntp.html" })}})

I've written a Chrome extension that overrides the New Tab page:

manifest.json:

  "chrome_url_overrides": {
    "newtab": "new-tab.html"
  },

Is there a way to make this override optional? That is, I'd like to enable the user to uncheck a checkbox in the options page and disable the New Tab override. This must be possible because when I open a new tab for the first time, there's a popup informing of an extension changing the New Tab settings and asking whether to keep changes or restore settings:

I couldn't find any API for controlling overrides. The New Tab Redirect project doesn't have an option to display the native New Tab.

解决方案

Google made a Star Wars new tab replacement which allows you to view the default new tab page. The url it uses is chrome-search://local-ntp/local-ntp.html.

Example:

options.html:

<input type="checkbox"> Use default new tab page

options.js:

var checkbox = document.querySelector("input[type=checkbox]")
checkbox.addEventListener("click", function() {
 chrome.storage.sync.set({ defaultnewtab: checkbox.checked })
})

newtab.js:

chrome.storage.sync.get("defaultnewtab", function(storage) {
 if(storage.defaultnewtab) {
  chrome.tabs.update({ url: "chrome-search://local-ntp/local-ntp.html" })
 }
})

这篇关于以编程方式(或可选)覆盖 Chrome 的新标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆