我需要将某些特定的URL重定向到另一个特定的URL。例如,我要将“ https://www.youtube.com/watch?v=ABCDefgHIJK”重定向到“ https://zymernation.com/wp-content/uploads/2019/05/Internet-Access-Error- e1558967567821.jpg”
为此,我制作了一个脚本,可以在其中获取当前URL,但不能重定向URL。
我有一些代码,但是它们不能完美运行。
需要专家指导。
谢谢。
试试这个解决方案:
manifest.json
{
"manifest_version": 2,
"name": "test",
"description": "google chrome extension",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs"
]
}
background.js
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { // listener for tab opens
if (changeInfo.status == 'loading') { // when the page is loading (you can do info.status === 'complete' but you will see the page for a second or two)
if (tab.url === "https://www.youtube.com/watch?v=ABCDefgHIJK") {
chrome.tabs.query({ // change the tab url
currentWindow: true,
active: true
}, function (tab) {
chrome.tabs.update(tab.id, {
url: 'https://zymernation.com/wp-content/uploads/2019/05/Internet-Access-Error-e1558967567821.jpg'
});
});
}
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句