fix yandex pagination

This commit is contained in:
lolcat committed 2026-12-04 00:38:00 -05:00
1 parent 2b06b1cf64
commit 6a0ea4c00f
3 files changed
+361 -22

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
{
"port_4play": 3030,
"port_webserver": 3000,
"timeout": 30000,
"password": "cnc"
}
+140 -15
View File
@@ -1,17 +1,13 @@
const fplay = require("@lawlers/4play");
const http = require("http");
const fs = require("fs");
// 4play settings
var port = 3030;
var timeout = 30000;
var password = "cnc";
// ==================================================
// import 4play settings
var config = JSON.parse(fs.readFileSync("config.json"));
// webserver
var global_ws = null;
const webserver_port = 3000;
var callback_q = new Map();
@@ -26,6 +22,11 @@ const server = http.createServer(async function(req, res){
const content_match = parsed.searchParams.get("content_match");
const fail_url_match = parsed.searchParams.get("fail_url_match");
const fail_content_match = parsed.searchParams.get("fail_content_match");
var return_cookies = parsed.searchParams.get("return_cookies");
const js_eval_url_match = parsed.searchParams.get("js_eval_url_match");
const js_eval_content_match = parsed.searchParams.get("js_eval_content_match");
const js_eval = parsed.searchParams.get("js_eval");
var js_eval_isolated = parsed.searchParams.get("js_eval_isolated");
var container = parsed.searchParams.get("container");
@@ -46,7 +47,7 @@ const server = http.createServer(async function(req, res){
if(
pw === null ||
pw != password
pw != config.password
){
errors.push("pw");
@@ -68,6 +69,75 @@ const server = http.createServer(async function(req, res){
return;
}
if(
js_eval_url_match === null &&
js_eval_content_match === null &&
js_eval !== null
){
res.writeHead(
400,
{
"Content-Type": "text/plain"
}
);
res.end("Missing &js_eval_url_match or &js_eval_content_match directive while &js_eval is present");
return;
}
if(js_eval !== null){
switch(js_eval_isolated){
case "true":
case "1":
js_eval_isolated = true;
break;
case "false":
case "0":
js_eval_isolated = false;
break;
default:
res.writeHead(
400,
{
"Content-Type": "text/plain"
}
);
res.end("Invalid &js_eval_isolated value provided while &js_eval is present");
return;
}
}
switch(return_cookies){
case "true":
case "1":
return_cookies = true;
break;
case null:
case "false":
case "0":
return_cookies = false;
break;
default:
res.writeHead(
400,
{
"Content-Type": "text/plain"
}
);
res.end("Invalid &return_cookies value provided");
return;
}
console.log("Rendering " + url);
if(
@@ -122,7 +192,13 @@ const server = http.createServer(async function(req, res){
url_match: url_match,
content_match: content_match,
fail_url_match: fail_url_match,
fail_content_match: fail_content_match
fail_content_match: fail_content_match,
return_cookies: return_cookies,
newtab: newtab,
js_eval_url_match: js_eval_url_match,
js_eval_content_match: js_eval_content_match,
js_eval: js_eval,
js_eval_isolated: js_eval_isolated
}
);
@@ -131,9 +207,9 @@ const server = http.createServer(async function(req, res){
await fplay.tab_close(global_ws, newtab);
});
server.listen(webserver_port, function(){
server.listen(config.port_webserver, function(){
console.log("http server running");
console.log("http server running on port " + config.port_webserver);
});
function get_proxy(proxy_line){
@@ -206,7 +282,7 @@ function get_proxy(proxy_line){
fplay.event.on("server_ready", function(){
console.log("listening on port " + port + " (timeout=" + timeout + ")");
console.log("listening on port " + config.port + " (timeout=" + config.timeout + ")");
});
fplay.event.on("browser_connect", async function(ws){
@@ -236,9 +312,44 @@ fplay.event.on("web_response", async function(page){
var url_match = callback_data.url_match !== null ? page.url.match(new RegExp(callback_data.url_match, "i")) : null;
var content_match = callback_data.content_match !== null ? body.match(new RegExp(callback_data.content_match, "i")) : null;
var fail_url_match = callback_data.fail_url_match !== null ? page.url.match(new RegExp(callback_data.fail_url_match, "i")) : null;
var fail_content_match = callback_data.fail_content_match !== null ? body.match(new RegExp(callback_data.fail_content_match, "i")) : null;
var js_eval_url_match = callback_data.js_eval_url_match !== null ? page.url.match(new RegExp(callback_data.js_eval_url_match, "i")) : null;
var js_eval_content_match = callback_data.js_eval_content_match !== null ? body.match(new RegExp(callback_data.js_eval_content_match, "i")) : null;
var return_cookies = callback_data.return_cookies;
// run javascript on match
if(
(
callback_data.js_eval_url_match !== null &&
callback_data.js_eval_content_match !== null &&
js_eval_url_match &&
js_eval_content_match
) ||
(
callback_data.js_eval_url_match === null &&
callback_data.js_eval_content_match !== null &&
js_eval_content_match
) ||
(
callback_data.js_eval_url_match !== null &&
callback_data.js_eval_content_match === null &&
js_eval_url_match
)
){
// @todo: find a way to return js in headers later
var js = await fplay.tab_inject_js(
global_ws,
callback_data.newtab,
callback_data.js_eval,
callback_data.js_eval_isolated
);
}
// handle negative response
if(
(
@@ -256,7 +367,7 @@ fplay.event.on("web_response", async function(page){
{
"Content-Type": "text/plain",
"X-Proxy": callback_data.proxy.raw,
"X-Container-ID": callback_data.container.id
"X-Container-ID": typeof callback_data.container.id == "undefined" ? callback_data.container : callback_data.container.id
}
);
@@ -294,12 +405,26 @@ fplay.event.on("web_response", async function(page){
)
){
// get cookies if applicable
var cookies = [];
if(return_cookies){
cookies = await fplay.get_cookies(
global_ws,
{
storeId: callback_data.container.id
}
);
}
callback_data.http_res.writeHead(
200,
{
"Content-Type": "text/plain;charset=UTF-8",
"X-Proxy": callback_data.proxy.raw,
"X-Container-ID": typeof callback_data.container.id == "undefined" ? callback_data.container : callback_data.container.id
"X-Container-ID": typeof callback_data.container.id == "undefined" ? callback_data.container : callback_data.container.id,
...(return_cookies && { "X-Cookies": JSON.stringify(cookies) })
}
);
@@ -334,4 +459,4 @@ fplay.event.on("dom_load_fail", async function(page){
await fplay.container_delete(global_ws, callback_data.container);
});
fplay.init(port, password, timeout);
fplay.init(config.port_4play, config.password, config.timeout);