diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a79944 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.zip +web-ext-artifacts \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..fb75512 --- /dev/null +++ b/package.json @@ -0,0 +1,7 @@ +{ + "scripts": { + "build": "web-ext build --filename wordpress-detector.zip --overwrite-dest --source-dir ./src/", + "sign": "web-ext sign --source-dir ./src/", + "start:firefox": "web-ext run --source-dir ./src/" + } +} \ No newline at end of file diff --git a/src/background.js b/src/background.js index 30b7b52..e0614fa 100644 --- a/src/background.js +++ b/src/background.js @@ -3,28 +3,33 @@ // terms we will search in to detect WordPress const clues = ["wp-content", "wp-includes"] -// reset icon -updateIcon(false) - // updates the icon in the toolbar -const updateIcon = (state) => { +const updateIcon = (state, tabId = null) => { const path = state ? "icon_on_32.png" : "icon_off_32.png"; - chrome.browserAction.setIcon({ path }) + const title = state ? "WordPress Detector (detected)" : "WordPress Detector (not detected)"; + chrome.action.setIcon({ path, tabId }) + chrome.action.setTitle({ title, tabId }) } // detect wordpress in a pages -const detectWordPress = (head) => { - updateIcon(head && head != null && head !== "" && clues.some(v => head.includes(v))) +const detectWordPress = (head, tabId) => { + if ( typeof head !== "undefined" ) { + const state = head && head != null && head !== "" && clues.some(v => head.includes(v)) + updateIcon( state, tabId ) + } } -const onTabUpdate = () => { +const onTabUpdate = (activeInfo) => { // reset - updateIcon(false) + updateIcon(false, activeInfo.tabId) - // get current tab's and detect WordPress - chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { - chrome.tabs.sendMessage(tabs[0].id, { text: "send_head_inner" }, function (response) { - detectWordPress(response) + // get each window's active tab's and detect WordPress + chrome.tabs.query({ active: true, windowType: 'normal', url: ['*://*/*'] }, function (tabs) { + tabs.forEach( function( tab, index, arr ) { + const tabId = tab.id; + chrome.tabs.sendMessage(tabId, { tabId: tabId, text: "send_head_inner" }, function (response) { + detectWordPress( response?.response, response?.tabId ) + }); }); }); } @@ -32,7 +37,4 @@ const onTabUpdate = () => { // listen for tab updates chrome.tabs.onActivated.addListener(onTabUpdate) chrome.tabs.onUpdated.addListener(onTabUpdate) -chrome.tabs.onCreated.addListener(onTabUpdate) -chrome.windows.onFocusChanged.addListener(onTabUpdate) -chrome.tabs.onRemoved.addListener(onTabUpdate) -chrome.tabs.onReplaced.addListener(onTabUpdate) \ No newline at end of file +chrome.windows.onFocusChanged.addListener(onTabUpdate) \ No newline at end of file diff --git a/src/content.js b/src/content.js index b7ff7dc..6cd9505 100644 --- a/src/content.js +++ b/src/content.js @@ -1,5 +1,5 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { if (msg.text === 'send_head_inner') { - sendResponse(document.head.innerHTML) + sendResponse( { response: document.head.innerHTML, tabId: msg.tabId } ) } }); \ No newline at end of file diff --git a/src/icon_off_128.png b/src/icon_off_128.png index 948fc50..d66b2f1 100644 Binary files a/src/icon_off_128.png and b/src/icon_off_128.png differ diff --git a/src/icon_off_16.png b/src/icon_off_16.png index 2f0a167..5720153 100644 Binary files a/src/icon_off_16.png and b/src/icon_off_16.png differ diff --git a/src/icon_off_32.png b/src/icon_off_32.png index bc7debc..82a24b1 100644 Binary files a/src/icon_off_32.png and b/src/icon_off_32.png differ diff --git a/src/icon_off_48.png b/src/icon_off_48.png index 166e317..9e2c1d2 100644 Binary files a/src/icon_off_48.png and b/src/icon_off_48.png differ diff --git a/src/icon_on_128,png.png b/src/icon_on_128.png similarity index 100% rename from src/icon_on_128,png.png rename to src/icon_on_128.png diff --git a/src/manifest.json b/src/manifest.json index c574d69..7718305 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,12 +1,25 @@ { "name": "WordPress Detector", "author": "bensaine", - "version": "1.0", + "version": "1.0.3", "description": "WordPress Detector will detect instantly if the site in your current tab is made using WordPress!", - "permissions": ["activeTab"], + "minimum_chrome_version": "121", + "browser_specific_settings": { + "gecko": { + "id": "{21a16015-26a5-4449-92ae-633e2b960be7}", + "strict_min_version": "121.0" + }, + "gecko_android": { + "strict_min_version": "121.0" + }, + "safari": { + "strict_min_version": "15.4" + } + }, + "permissions": ["activeTab", "tabs"], "background": { - "scripts": ["background.js"], - "persistent": false + "service_worker": "background.js", + "scripts": ["background.js"] }, "content_scripts": [ { @@ -20,8 +33,8 @@ "48": "icon_48.png", "128": "icon_128.png" }, - "manifest_version": 2, - "browser_action": { + "manifest_version": 3, + "action": { "default_icon": "icon_off_32.png", "default_title": "WordPress Detector" } diff --git a/wordpress-detector.zip b/wordpress-detector.zip deleted file mode 100644 index 3097897..0000000 Binary files a/wordpress-detector.zip and /dev/null differ