diff --git a/chrome-extension/src/background.js b/chrome-extension/src/background.js deleted file mode 100644 index 80e64ce..0000000 --- a/chrome-extension/src/background.js +++ /dev/null @@ -1,31 +0,0 @@ -// Send message to content.js when URL changes -chrome.tabs.onUpdated.addListener(function - (tabId, changeInfo, tab) { - if (changeInfo.url) { - chrome.tabs.sendMessage(tabId, { - message: 'URL has changed', - url: changeInfo.url - }) - } - }); - -chrome.runtime.onInstalled.addListener(function(details) { - if (details.reason == "install") { - if (chrome.runtime.setUninstallURL) { - chrome.runtime.setUninstallURL('https://forms.gle/Cgv34WVhgms9MChv7'); - } - } -}); - -chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { - console.log(message); - if (message.srmStatus === 'ON') { - chrome.pageAction.setIcon({tabId: sender.tab.id, path: 'icon128.png'}); - } - if (message.srmStatus === 'OK') { - chrome.pageAction.setIcon({tabId: sender.tab.id, path: 'icon128green.png'}); - } - if (message.srmStatus === 'SRM') { - chrome.pageAction.setIcon({tabId: sender.tab.id, path: 'icon128red.png'}); - } -}); diff --git a/chrome-extension/src/content.js b/chrome-extension/src/content.js index 1a64cbe..2aed886 100644 --- a/chrome-extension/src/content.js +++ b/chrome-extension/src/content.js @@ -13,12 +13,13 @@ const platforms = { // SRM Checker Chrome Extension microsite // TODO Remove this once we support more than one real platform. - 'lukasvermeer.nl': { + 'www.lukasvermeer.nl': { init() { document.querySelectorAll('input').forEach(i => i.addEventListener('input', () => { - const a = parseInt(document.getElementById('atraffic').value, 10); - const b = parseInt(document.getElementById('btraffic').value, 10); - const e = parseFloat(document.getElementById('expectedprop').value, 10) * 100; + const numbers = document.querySelectorAll("input"); + const a = parseInt(numbers[0].value, 10); + const b = parseInt(numbers[2].value, 10); + const e = parseFloat(numbers[1].value, 10) * 100; checkSRM([a, b], [100 - e, e]); }, false)); diff --git a/chrome-extension/src/manifest.json b/chrome-extension/src/manifest.json index 2c73947..5f05994 100644 --- a/chrome-extension/src/manifest.json +++ b/chrome-extension/src/manifest.json @@ -1,32 +1,50 @@ { "name": "Sample Ratio Mismatch (SRM) Checker", "short_name": "SRM Check", - "version": "0.0.8", + "version": "0.1.0", "description": "Automatically performs Sample Ratio Mismatch (SRM) test and flags potential issues on supported experimentation platforms.", "permissions": [ - "tabs" + "activeTab", + "scripting" + ], + "host_permissions": [ + "https://*.lukasvermeer.nl/srm/*", + "https://app.optimizely.com/*", + "https://app.vwo.com/*", + "https://*.sitegainer.com/*", + "https://conversion.symplify.com/*", + "https://app.convert.com/*", + "https://web.omniconvert.com/*", + "https://pagesense.zoho.eu/*", + "https://pagesense.zoho.com/*" ], "content_scripts": [ - { - "matches": ["https://lukasvermeer.nl/srm/*", - "https://app.optimizely.com/*", - "https://app.vwo.com/*", - "https://sitegainer.com/*", - "https://conversion.symplify.com/*", - "https://app.convert.com/*", - "https://web.omniconvert.com/*", - "https://pagesense.zoho.eu/*", - "https://pagesense.zoho.com/*"], - "js": ["lib/statistics-distributions.js", "srm.js", "content.js"] - } - ], + { + "matches": [ + "https://*.lukasvermeer.nl/srm/*", + "https://app.optimizely.com/*", + "https://app.vwo.com/*", + "https://*.sitegainer.com/*", + "https://conversion.symplify.com/*", + "https://app.convert.com/*", + "https://web.omniconvert.com/*", + "https://pagesense.zoho.eu/*", + "https://pagesense.zoho.com/*" + ], + "js": [ + "lib/statistics-distributions.js", + "srm.js", + "content.js" + ] + } + ], "background": { - "scripts": [ "background.js" ] - }, - "page_action": { + "service_worker": "service_worker.js" }, "icons": { "128": "icon128.png" }, - "manifest_version": 2 + "manifest_version": 3, + "action": {}, + "content_security_policy": {} } diff --git a/chrome-extension/src/service_worker.js b/chrome-extension/src/service_worker.js new file mode 100644 index 0000000..7bfdfd0 --- /dev/null +++ b/chrome-extension/src/service_worker.js @@ -0,0 +1,40 @@ +// Send message to content.js when URL changes +chrome.tabs.onActivated.addListener(function (tab) { + console.log("TAB CHANGED") + // TODO only do this on pages where we have permission + chrome.scripting.executeScript({ + target: { tabId: tab.tabId }, + files: ["content.js"] + }); +}) + +// Fired when a tab is updated. +chrome.tabs.onUpdated.addListener(async function (tab) { + console.log("TAB UPDATED") + // TODO only do this on pages where we have permission + chrome.scripting.executeScript({ + target: { tabId: tab }, + files: ["content.js"] + }); +}) + +chrome.runtime.onInstalled.addListener(function(details) { + if (details.reason == "install") { + if (chrome.runtime.setUninstallURL) { + chrome.runtime.setUninstallURL('https://forms.gle/Cgv34WVhgms9MChv7'); + } + } +}); + +chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { + console.log(message); + if (message.srmStatus === 'ON') { + chrome.action.setIcon({tabId: sender.tab.id, path: 'icon128.png'}); + } + if (message.srmStatus === 'OK') { + chrome.action.setIcon({tabId: sender.tab.id, path: 'icon128green.png'}); + } + if (message.srmStatus === 'SRM') { + chrome.action.setIcon({tabId: sender.tab.id, path: 'icon128red.png'}); + } +});