Created
June 2, 2019 06:24
-
-
Save ursi/03893a3d017e7104fabed36e856c7ddf to your computer and use it in GitHub Desktop.
Open Bookmarks Bar In New Tab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function openInNewTab(url) { | |
chrome.tabs.create({url: url}) | |
} | |
function callback(e) { | |
if (callback.skip) { | |
callback.skip = false; | |
} else { | |
callback.skip = true; | |
openInNewTab(e.url); | |
return {redirectUrl: "http://google.com/gen_204"}; | |
} | |
} | |
let reStr = ''; | |
[ | |
'http://', | |
'https://', | |
'ftp://', | |
'file://', | |
'ws://', | |
'wss://', | |
].forEach(scheme => { | |
reStr += `^${scheme}|`; | |
}); | |
let filterFilter = new RegExp(reStr.slice(0, -1), 'm'); | |
function updateBookmarks() { | |
let filter = []; | |
chrome.bookmarks.getChildren('1', bms => { | |
for (let bm of bms) { | |
if (filterFilter.test(bm.url)) filter.push(bm.url); | |
} | |
chrome.webRequest.onBeforeRequest.removeListener(callback); | |
chrome.webRequest.onBeforeRequest.addListener(callback, {urls: filter}, ['blocking']); | |
}); | |
} | |
updateBookmarks(); | |
[ | |
'onCreated', | |
'onRemoved', | |
'onMoved', | |
].forEach(event => chrome.bookmarks[event].addListener(updateBookmarks)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "", | |
"version": "1", | |
"background": { | |
"scripts": ["background.js"] | |
}, | |
"permissions": [ | |
"bookmarks", | |
"webRequest", | |
"webRequestBlocking", | |
"<all_urls>" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment