add cookie on web
This commit is contained in:
@@ -8,12 +8,16 @@ import * as pluginApi from "./test_web/api/plugins";
|
|||||||
import localizedFormat from "dayjs/plugin/localizedFormat";
|
import localizedFormat from "dayjs/plugin/localizedFormat";
|
||||||
interface GlobalState {
|
interface GlobalState {
|
||||||
UserAgent?: string,
|
UserAgent?: string,
|
||||||
|
Cookie?: string,
|
||||||
}
|
}
|
||||||
let globalState: GlobalState = {
|
let globalState: GlobalState = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getUserAgent = () => {
|
export const getHeaders = () => {
|
||||||
return globalState.UserAgent;
|
return {
|
||||||
|
'User-Agent': globalState.UserAgent,
|
||||||
|
'Cookie': globalState.Cookie,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -22,15 +26,29 @@ const host = "localhost";
|
|||||||
|
|
||||||
const dirname = path.join(__dirname, "..");
|
const dirname = path.join(__dirname, "..");
|
||||||
|
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
globalState.UserAgent = req.headers["user-agent"];
|
||||||
|
console.log('---------');
|
||||||
|
console.log('default headers: ', globalState);
|
||||||
|
console.log('---------');
|
||||||
|
console.log();
|
||||||
|
next();
|
||||||
|
});
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use("/static", express.static(path.join(dirname, "test_web", "static")));
|
app.use("/static", express.static(path.join(dirname, "test_web", "static")));
|
||||||
app.use("/icons", express.static(path.join(dirname, "icons")));
|
app.use("/icons", express.static(path.join(dirname, "icons")));
|
||||||
app.get("/all_plugins", (req, res) => {
|
app.get("/all_plugins", (req, res) => {
|
||||||
globalState.UserAgent = req.headers["user-agent"];
|
|
||||||
console.log(globalState);
|
|
||||||
const allPlugins = pluginApi.all_plugins();
|
const allPlugins = pluginApi.all_plugins();
|
||||||
res.json(allPlugins);
|
res.json(allPlugins);
|
||||||
});
|
});
|
||||||
|
app.post("/add_cookie", async (req, res) => {
|
||||||
|
globalState.Cookie = req.body['cookie'];
|
||||||
|
console.log('---------');
|
||||||
|
console.log('default headers: ', globalState);
|
||||||
|
console.log('---------');
|
||||||
|
console.log();
|
||||||
|
res.json({});
|
||||||
|
});
|
||||||
app.post("/filters", async (req, res) => {
|
app.post("/filters", async (req, res) => {
|
||||||
const filters = await pluginApi.getFilter(req.body['pluginRequirePath']);
|
const filters = await pluginApi.getFilter(req.body['pluginRequirePath']);
|
||||||
res.json(filters || []);
|
res.json(filters || []);
|
||||||
|
|||||||
+22
-22
@@ -5,35 +5,35 @@ export async function fetchApi(
|
|||||||
[x: string]: string | Record<string,string> | undefined | FormData | Headers;
|
[x: string]: string | Record<string,string> | undefined | FormData | Headers;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
let userAgent: string | undefined;
|
let defaultHeaders: {
|
||||||
|
'User-Agent'?: string,
|
||||||
|
'Cookie'?: string,
|
||||||
|
} = {};
|
||||||
try {
|
try {
|
||||||
// get your user agent when you open localhost:3000
|
const getHeaders = (await import('../index.js')).getHeaders;
|
||||||
const getUserAgent = (await import('../index.js')).getUserAgent;
|
defaultHeaders = getHeaders();
|
||||||
userAgent = getUserAgent();
|
|
||||||
}catch{
|
}catch{
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
// there're 2 type of Headers, plain object {} or Headers instance
|
if(init?.headers) {
|
||||||
if(userAgent) {
|
if(init.headers instanceof Headers){
|
||||||
if(init?.headers) {
|
if(!init.headers.get('User-Agent') && defaultHeaders['User-Agent']){
|
||||||
if(init.headers instanceof Headers){
|
init.headers.set('User-Agent', defaultHeaders['User-Agent']);
|
||||||
if(!init.headers.get('User-Agent')){
|
}
|
||||||
init.headers.set('User-Agent', userAgent);
|
if(defaultHeaders.Cookie) {
|
||||||
}
|
init.headers.set('Cookie', defaultHeaders.Cookie);
|
||||||
}else{
|
|
||||||
init.headers = {
|
|
||||||
"User-agent": userAgent,
|
|
||||||
...init.headers
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
init = {
|
init.headers = {
|
||||||
...init,
|
...defaultHeaders,
|
||||||
headers: {
|
...init.headers,
|
||||||
"User-Agent": userAgent
|
};
|
||||||
}
|
}
|
||||||
}
|
}else{
|
||||||
|
init = {
|
||||||
|
...init,
|
||||||
|
headers: defaultHeaders
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,14 @@
|
|||||||
</script>
|
</script>
|
||||||
</nav>
|
</nav>
|
||||||
<div id="test-container">
|
<div id="test-container">
|
||||||
|
<div class="test-wrapper" id="add-cookie">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="cookie">Cookie 🍪</label> <span id="cookie-content"></span>
|
||||||
|
<input type="email" class="form-control" id="cookie" aria-describedby="cookieHelp" placeholder="cf_clearance=abcxyzblalba">
|
||||||
|
<small id="cookieHelp" class="form-text text-muted">Add cookie into headers to bypass cloudflare</small>
|
||||||
|
<button type="button" class="btn btn-primary" id="add-cookie-btn">Add</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="test-wrapper" id="popularNovels">
|
<div class="test-wrapper" id="popularNovels">
|
||||||
<div class="modal-container">
|
<div class="modal-container">
|
||||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#filtersModal">
|
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#filtersModal">
|
||||||
|
|||||||
@@ -922,6 +922,23 @@ class PluginWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#add-cookie-btn").on("click", () => {
|
||||||
|
const cookie = $('#cookie').val();
|
||||||
|
fetch('/add_cookie', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
'cookie': cookie,
|
||||||
|
}),
|
||||||
|
}).then(() => {
|
||||||
|
$('#cookie').val('');
|
||||||
|
$('#cookie-content').text(`: ${cookie}`);
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
$(".popularNovels-btn").on("click", () =>
|
$(".popularNovels-btn").on("click", () =>
|
||||||
state.current_plugin?.getPopularNovels()
|
state.current_plugin?.getPopularNovels()
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user