poc
This commit is contained in:
parent
ca555fb628
commit
f8ef9ee252
|
@ -0,0 +1,31 @@
|
|||
import { LoginMessage, Message, MessageType } from './message';
|
||||
|
||||
const COOKIE_NAME = 'sid';
|
||||
|
||||
chrome.runtime.onMessage.addListener(
|
||||
(message: Message, sender, sendResponse) => {
|
||||
switch (message.type) {
|
||||
case MessageType.LOGIN:
|
||||
handleLogin(message);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const handleLogin = async (message: LoginMessage) => {
|
||||
const cookie = await chrome.cookies.get({
|
||||
name: COOKIE_NAME,
|
||||
url: message.url,
|
||||
});
|
||||
|
||||
console.log(cookie);
|
||||
|
||||
const url = new URL(message.url);
|
||||
url.pathname = '/game.php';
|
||||
url.searchParams.set('screen', 'overview_villages');
|
||||
const resp = await fetch(url.toString(), {
|
||||
method: 'GET',
|
||||
credentials: 'include',
|
||||
redirect: 'manual',
|
||||
});
|
||||
console.log(resp.status, resp.redirected);
|
||||
};
|
|
@ -1,12 +1,4 @@
|
|||
const handleClick = (e: MouseEvent) => {
|
||||
if (!(e.currentTarget instanceof HTMLAnchorElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
console.log(e.currentTarget.href);
|
||||
};
|
||||
import { LoginMessage, MessageType } from './message';
|
||||
|
||||
const renderUI = () => {
|
||||
document
|
||||
|
@ -29,6 +21,30 @@ const renderUI = () => {
|
|||
});
|
||||
};
|
||||
|
||||
const handleClick = (e: MouseEvent) => {
|
||||
if (!(e.currentTarget instanceof HTMLAnchorElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
const url = new URL(e.currentTarget.href);
|
||||
const server = extractServerFromURL(url);
|
||||
chrome.runtime.sendMessage({
|
||||
type: MessageType.LOGIN,
|
||||
server,
|
||||
url: url.protocol + '//' + url.host.replace('www', server),
|
||||
} as LoginMessage);
|
||||
};
|
||||
|
||||
const extractServerFromURL = (url: URL): string => {
|
||||
const split = url.pathname.split('/');
|
||||
if (split.length <= 0) {
|
||||
throw new Error(`invalid path: ${url.pathname}`);
|
||||
}
|
||||
return split[split.length - 1];
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
renderUI();
|
||||
};
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
export enum MessageType {
|
||||
LOGIN,
|
||||
}
|
||||
|
||||
export type LoginMessage = {
|
||||
type: MessageType.LOGIN;
|
||||
url: string;
|
||||
server: string;
|
||||
};
|
||||
|
||||
export type Message = LoginMessage;
|
Loading…
Reference in New Issue