以编程方式(或可选)覆盖 Chrome 的新标签页 [英] Programmatically (or optionally) override Chrome's New Tab page
问题描述
我编写了一个 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屋!