Skip to content

Commit

Permalink
feat: add custom injection rule settings for ffz and bttv
Browse files Browse the repository at this point in the history
See #2
  • Loading branch information
strumswell committed Dec 7, 2022
1 parent e3816e9 commit 0a06b76
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
14 changes: 14 additions & 0 deletions Shared (Extension)/Resources/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
// Store action for settings change
if (request.type === "SetStoreExecution") {
browser.storage.local.set({[request.id]: request.value}).then(res => {
sendResponse({ result: {[request.id]: request.value} })
})
// Retrieve action for settings change
} else if (request.type === "GetStoreExecution"){
browser.storage.local.get(request.id).then((res) => {
sendResponse({ checked: res[request.id] })
})
}
return true;
});
32 changes: 20 additions & 12 deletions Shared (Extension)/Resources/content.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
// Inject BBTV Script
const bttvScript = document.createElement('script');
bttvScript.type = 'text/javascript';
bttvScript.src = 'https://cdn.betterttv.net/betterttv.js';
// Head to append scripts to
const head = document.getElementsByTagName('head')[0];

// Inject FFZ script
const ffzScript = document.createElement('script');
ffzScript.type = 'text/javascript';
ffzScript.src = 'https://cdn.frankerfacez.com/static/ffz_injector.user.js';
// Inject BTTV if enabled
browser.runtime.sendMessage({ type: "GetStoreExecution", id: "bttvEnabled" }).then((response) => {
if (response.checked) {
const bttvScript = document.createElement('script');
bttvScript.type = 'text/javascript';
bttvScript.src = 'https://cdn.betterttv.net/betterttv.js';
head.appendChild(bttvScript);
}
});

// Append scripts to head
const head = document.getElementsByTagName('head')[0];
head.appendChild(bttvScript);
head.appendChild(ffzScript);
// Inject FFZ if enabled
browser.runtime.sendMessage({ type: "GetStoreExecution", id: "ffzEnabled" }).then((response) => {
if (response.checked) {
const ffzScript = document.createElement('script');
ffzScript.type = 'text/javascript';
ffzScript.src = 'https://cdn.frankerfacez.com/static/ffz_injector.user.js';
head.appendChild(ffzScript);
}
});
16 changes: 9 additions & 7 deletions Shared (Extension)/Resources/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"name": "__MSG_extension_name__",
"description": "__MSG_extension_description__",
"version": "1.0",

"icons": {
"48": "images/48.png",
"32": "images/32.png",
"64": "images/64.png",
"96": "images/96.png",
"128": "images/128.png",
"256": "images/256.png",
"512": "images/512.png"
"512": "images/512.png",
"1024": "images/1024.png"
},
"background": {
"service_worker": "background.js"
},

"content_scripts": [{
Expand All @@ -21,13 +23,13 @@
}],

"browser_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/toolbar-icon-16.png",
"19": "images/toolbar-icon-19.png",
"32": "images/toolbar-icon-32.png",
"38": "images/toolbar-icon-38.png"
"64": "images/toolbar-icon-64.png"
}
},

"permissions": [ ]
"permissions": [ "storage", "tabs" ]
}
1 change: 1 addition & 0 deletions Shared (Extension)/Resources/tailwind.css

Large diffs are not rendered by default.

0 comments on commit 0a06b76

Please sign in to comment.