From e8d333e399364c5783b723d712702f3bae1505dd Mon Sep 17 00:00:00 2001 From: gnat Date: Fri, 4 Oct 2024 02:33:36 -0700 Subject: [PATCH] add fun features! --- src/lib/patchers.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib/patchers.py b/src/lib/patchers.py index de5e1a9..9994e0e 100644 --- a/src/lib/patchers.py +++ b/src/lib/patchers.py @@ -47,6 +47,20 @@ def uwuify_text(text): return '. '.join(uwuified_sentences) +def apply_url_params(body, params: str): + body = body.decode('utf-8') + soup = BeautifulSoup(body, 'html.parser') + + for a_tag in soup.find_all('a', href=True): + original_href = a_tag['href'] + if '?' in original_href: + new_href = f"{original_href}&{params}" + else: + new_href = f"{original_href}?{params}" + a_tag['href'] = new_href + + return str(soup) + def uwuify(body): body = body.decode('utf-8') soup = BeautifulSoup(body, 'html.parser') @@ -91,5 +105,16 @@ patchers: List[Patcher] = [ response.code, response.headers, re.sub(r'sludge', lambda match: 'sludge' + ' (/slʌd͡ʒ/)' if random.randint(0, 5) < 1 else 'sludge', response.body.decode('utf-8')).encode('utf-8') - ) if 'text/html' in response.headers.values() else response + ) if 'text/html' in response.headers.values() else response, + lambda response, request: Response( + response.code, + response.headers, + apply_url_params(response.body.replace(b'', b''), 'swing=true').encode('utf-8') + ) if 'text/html' in response.headers.values() and (random.randint(0, 100) < 1 or is_subdict({'swing': 'true'}, request.path.params)) else response, + # spiin! + lambda response, request: Response( + response.code, + response.headers, + apply_url_params(response.body.replace(b'', b''), 'spin=true').encode('utf-8') + ) if 'text/html' in response.headers.values() and (random.randint(0, 1000) < 1 or is_subdict({'spiin': 'true'}, request.path.params)) else response ]