Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local
.output
stats.html
stats-*.json
.wxt
web-ext.config.ts

# Editor directories and files
.vscode/*
Expand All @@ -22,10 +24,3 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Config files
.webextrc
.webextrc.*

*.zip
tmp/*
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nodejs 18.13.0
yarn 1.22.10
nodejs lts
pnpm 10.13.1
143 changes: 143 additions & 0 deletions entrypoints/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
export default defineBackground(() => {
const RSI_BASE_URL = "https://robertsspaceindustries.com";

async function getRSIToken(): Promise<string | null> {
const cookie = await browser.cookies.get({
url: RSI_BASE_URL,
name: "Rsi-Token",
});

if (cookie) {
return cookie.value;
}

return null;
}

type RSIApiParams = {
url: string;
payload: any;
rsiToken: string;
};

async function fetchRSIApi(params: RSIApiParams) {
var url = params.url;
var payload = params.payload;
var rsiToken = params.rsiToken;

return fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "*/*",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"X-Rsi-Token": rsiToken,
},
credentials: "include",
body: JSON.stringify(payload),
});
}

function identify(token: string) {
return fetchRSIApi({
url: `${RSI_BASE_URL}/api/spectrum/auth/identify`,
payload: {},
rsiToken: token,
});
}

async function fetchPledges(token: string, page = 1) {
return fetch(`${RSI_BASE_URL}/account/pledges?page=${page}`, {
method: "GET",
headers: {
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "max-age=0",
"X-Rsi-Token": token,
},
credentials: "include",
});
}

async function onMessage(
rawMessage: string,
sendResponse: (message: string) => void
) {
const message = JSON.parse(rawMessage || "{}");

if (message?.action == "health") {
console.info("FY Sync: Health check");

sendResponse(JSON.stringify({ code: 200, action: message.action }));
} else if (message?.action == "identify") {
console.info("FY Sync: Fetching Identity");

const token = await getRSIToken();
if (!token) {
sendResponse(
JSON.stringify({
code: 400,
action: message.action,
error: "Token not found" + message?.action,
})
);
} else {
const response = await identify(token);
const body = await response.json();

sendResponse(
JSON.stringify({
code: response.status,
action: message.action,
payload: {
handle: body.data?.member?.nickname,
},
})
);
}
} else if (message?.action == "sync") {
const token = await getRSIToken();
if (!token) {
sendResponse(
JSON.stringify({
code: 400,
action: message.action,
error: "Token not found" + message?.action,
})
);
} else {
const response = await fetchPledges(token, message.page);
const payload = await response.text();

sendResponse(
JSON.stringify({
code: response.status,
action: message.action,
payload,
})
);
}
} else {
console.info("FY Sync: Unknown Action");

sendResponse(
JSON.stringify({
code: 500,
action: message.action,
error: "Unknown Action",
})
);
}
}

browser.runtime.onMessage.addListener(function (
message,
_sender,
sendResponse
) {
onMessage(message, sendResponse);

return true;
});
});
48 changes: 48 additions & 0 deletions entrypoints/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export default defineContentScript({
matches: import.meta.env.PROD
? ["*://*.fleetyards.net/*"]
: ["*://fleetyards.test/*", "*://fleetyards.dev/*"],
main() {
function handleResponse(response: any) {
const origin = window.parent.location.origin;

if (origin === "https://fleetyards.dev") {
window.postMessage(
{
direction: "fy-sync",
message: response,
},
"https://fleetyards.dev"
);
} else if (origin === "https://fleetyards.net") {
window.postMessage(
{
direction: "fy-sync",
message: response,
},
"https://fleetyards.net"
);
} else if (origin === "http://fleetyards.test") {
window.postMessage(
{
direction: "fy-sync",
message: response,
},
"http://fleetyards.test"
);
}
}

window.addEventListener("message", async (event) => {
if (
event.source == window &&
event.data &&
event.data.direction == "fy"
) {
const response = await browser.runtime.sendMessage(event.data.message);

handleResponse(response);
}
});
},
});
27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
"version": "1.0.5",
"type": "module",
"scripts": {
"compile": "tsc --noEmit",
"dev": "vite",
"dev:chrome": "TARGET=chrome vite build",
"dev:firefox": "TARGET=firefox vite build",
"build": "./scripts/build.sh",
"build:staging": "ENVIRONMENT=staging ./scripts/build.sh",
"build:production": "ENVIRONMENT=production ./scripts/build.sh"
"dev": "wxt",
"dev:firefox": "wxt -b firefox",
"build": "wxt build",
"build:firefox": "wxt build -b firefox",
"zip": "wxt zip",
"zip:firefox": "wxt zip -b firefox",
"compile": "vue-tsc --noEmit",
"postinstall": "wxt prepare"
},
"dependencies": {
"vue": "^3.5.21"
},
"devDependencies": {
"@types/webextension-polyfill": "^0.10.7",
"typescript": "^5.3.3",
"vite": "^4.5.2",
"vite-plugin-web-extension": "^3.0.1",
"webextension-polyfill": "^0.10.0"
"@wxt-dev/module-vue": "^1.0.2",
"typescript": "^5.9.2",
"vue-tsc": "^3.0.6",
"wxt": "^0.20.6"
}
}
Loading