Scanning URL All the time - Chrome Extension
I need to develop extension, where everytime i write url and in chrome and press enter. My url is first scanned, if it matches some pattern say like if the url patter has youtube in it, redi开发者_Python百科rect it to facebook
This should be done automatically - not everytime i have press the icon of (chrome extension), meaning this script or piece of code will not be running on-click event, rather once installed it will always scan the url entered and do the require change and reload the tab.
Please help me out. I reach this far
<html>
<script>
function getname()
{
chrome.tabs.getSelected( null , function(tab) {
var rawurl="http://www.youtube.com/watch?";
var newurl= "http://www.youtube.com/watch?feature=player_leanback&"
if (0 === tab.url.indexOf(rawurl))
chrome.tabs.update(tab.id, {url: tab.url.replace(rawurl,newurl)});
});
}
</script>
<body onload="getname();">
</body>
</html>
I achieve this but you onload event in J-Script - is there anyway I can do this all the time without using onload() as onload require explicit click all the time.
Rewriting the code
<html>
<script>
function getname()
{
chrome.tabs.getSelected( null , function(tab) {
var rawurl="http://www.youtube.com/watch?";
var newurl= "http://www.youtube.com/watch?feature=player_leanback&"
if (0 === tab.url.indexOf(rawurl))
chrome.tabs.update(tab.id, {url: tab.url.replace(rawurl,newurl)});
});
}
</script>
<body onload="getname();">
</body>
</html>
You should consider APIs such like chrome.webRequest
or chrome.webNavigation
.
Besides, I believe this extension has implemented everything you mentioned.
精彩评论