Skip to content

Commit

Permalink
[injectors/mv3] rewrite with csp workaround (#22)
Browse files Browse the repository at this point in the history
* [injectors/mv3] use csp workaround

* [injectors/mv3] append script to documentElement because head doesn't exist yet

* [injectors/mv3] bump version to 1.2
  • Loading branch information
ioj4 authored Feb 22, 2024
1 parent 5967aa8 commit e7ea194
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 182 deletions.
5 changes: 4 additions & 1 deletion injectors/mv3/content.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
chrome.runtime.sendMessage("pwnme");
const script = document.createElement("script");
script.src = chrome.runtime.getURL("shelter-loader.js");

document.documentElement.append(script);
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
]
},
"condition": {
"regexFilter": "https?://discord.com/.*",
"resourceTypes": ["main_frame"]
"resourceTypes": ["main_frame", "sub_frame"]
}
}
]
57 changes: 0 additions & 57 deletions injectors/mv3/loader.js

This file was deleted.

22 changes: 11 additions & 11 deletions injectors/mv3/manifest.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"name": "Shelter MV3 Inj",
"version": "1.1",
"version": "1.2",
"homepage_url": "https://github.com/uwu/shelter",
"description": "Injects shelter on discord.com/app - for MV3 browsers",
"manifest_version": 3,
"permissions": ["debugger", "storage", "declarativeNetRequestWithHostAccess"],
"host_permissions": ["https://*/*"],
"background": {
"service_worker": "worker.js"
},
"permissions": ["declarativeNetRequest"],
"host_permissions": ["*://*.discord.com/*"],
"content_scripts": [
{
"matches": ["https://discord.com/*", "https://*.discord.com/*"],
"matches": ["*://*.discord.com/*"],
"js": ["content.js"],
"run_at": "document_start"
}
],
"icons": {},
"externally_connectable": {
"matches": ["https://discord.com/*", "https://*.discord.com/*"]
},
"web_accessible_resources": [
{
"resources": ["shelter-loader.js"],
"matches": ["*://*.discord.com/*"]
}
],
"declarative_net_request": {
"rule_resources": [
{
"id": "discord_nocsp",
"enabled": true,
"path": "dnr_rules.json"
"path": "dnr-rules.json"
}
]
}
Expand Down
27 changes: 27 additions & 0 deletions injectors/mv3/shelter-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const SHELTER_URL = "https://raw.githubusercontent.com/uwu/shelter-builds/main/shelter.js";

// discord removes localStorage later, so hold onto it
const localStorage = window.localStorage;

async function fetchShelter() {
const shelter = await (await fetch(SHELTER_URL)).text();
return `${shelter}\n//# sourceMappingURL=${SHELTER_URL}.map`;
}

async function initShelter() {
const localShelter = localStorage.getItem("shelter-bundle");

if (localShelter) {
const script = document.createElement("script");
script.innerText = localShelter;
document.documentElement.append(script);
}

const remoteShelter = await fetchShelter();
if (remoteShelter === localShelter) return;

localStorage.setItem("shelter-bundle", remoteShelter);
window.location.reload();
}

initShelter();
111 changes: 0 additions & 111 deletions injectors/mv3/worker.js

This file was deleted.

0 comments on commit e7ea194

Please sign in to comment.