I am developed one chrome extension basic of current page url. Below are listed my file of chrome extension.
My manifest.json file is
{
"name": "Domain Name",
"description": "http://stackoverflow.com/questions/14796722/javascript-google-chrome-extension-getting-domain-name",
"version": "1",
"manifest_version": 2,
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"myscript.js"
]
}
],
"browser_action": {
"default_popup": "popup.html",
"default_icon": {
"38": "icon.png"
}
},
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"tabs",
"<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["myscript.js","popup.js"]
}
]
}
My background.js file
chrome.tabs.onUpdated.addListener(function (tabId, change, tab) {
if (tab.url == "https://www.facebook.com/") {
chrome.browserAction.setIcon({ path: 'BGicon.png' });
}
else {
chrome.browserAction.setIcon({ path: 'icon.png' });
}
});
myscript.js
console.log(document.domain);
var domainURL = document.domain;
if (document.domain == "facebook.com") {
alert("Succes");
}
popup.js
document.addEventListener("DOMContentLoaded", function () {
console.log(document.domain);//It outputs id of extension to console
renderStatus('Search term: Google image search result: ');
chrome.tabs.query({ //This method output active URL
"active": true,
"currentWindow": true,
"status": "complete",
"windowType": "normal"
}, function (tabs) {
for (tab in tabs) {
console.log(tabs[tab].url);
}
});
});
function renderStatus(statusText) {
document.getElementById('status').textContent = statusText;
}
I want to set msg text as per open page. I mean if i am open facebook.com then popup msg set and display otherwise popup msg not displayed.