Skip to content

Commit

Permalink
First pass at migrating to manifest v3 for #86.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvermeer committed May 25, 2024
1 parent 2a03390 commit 430cd68
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 54 deletions.
31 changes: 0 additions & 31 deletions chrome-extension/src/background.js

This file was deleted.

9 changes: 5 additions & 4 deletions chrome-extension/src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
56 changes: 37 additions & 19 deletions chrome-extension/src/manifest.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
40 changes: 40 additions & 0 deletions chrome-extension/src/service_worker.js
Original file line number Diff line number Diff line change
@@ -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'});
}
});

0 comments on commit 430cd68

Please sign in to comment.