I have this so far:
chrome.tabs.getSelected(null, function(tab)
{
var title = tab.title;
var btn = '<a href="' + tab.url + '" onclick="save(\'' + title + '\');"> ' + title + '</a>';
if(tab.url.match('/http:\/\/www.example.com\/version.php/i'))
{
document.getElementById('link').innerHTML = '<p>' + btn + '</p>';
}
});
Basically it should match the domain within this:
http://www.example.com/version.php?*
Anything that matches that even when it includes something like version.php?ver=1, etc
When I used the code above of mine, it doesn't display anything, but when I remove the if statement, it's fine but it shows on other pages which it shouldn't only on the matched URL.
EDIT:
if(tab.url.match(/http:\/\/www.example.com\/version.php/i))
{
document.getElementById('link').innerHTML = '<p>' + btn + '</p>';
}
Doesn't even work somehow...
URL regular expressions can be used to verify if a string has a valid URL format as well as to extract an URL from a string.
regex = “((http|https)://)(www.)?
You can use the URLConstructor to check if a string is a valid URL. URLConstructor ( new URL(url) ) returns a newly created URL object defined by the URL parameters. A JavaScript TypeError exception is thrown if the given URL is not valid.
To check links at any other time, select the Links - Validate Links menu item or select Validate Links from the Page Tools left panel. CommonSpot differentiates between link types, validating http and verifying syntax for https and mailto.
Try this:
if(tab.url.match(/http\:\/\/www\.example\.com\/version\.php/i))
{
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With