From c512b8780449dcb3a319bc09ce7adec9582687bb Mon Sep 17 00:00:00 2001 From: Hunter Date: Sun, 10 Nov 2024 10:54:29 -0500 Subject: [PATCH] first pass at browser-specific presets --- config.py.example | 212 ++++++++++++++++++ extensions/websimulator/websimulator.py | 57 +++-- presets/macweb2.py | 0 presets/macweb2/macweb2.py | 184 +++++++++++++++ .../wii_internet_channel.py | 195 ++++++++++++++++ proxy.py | 131 ++++++++++- utils/html_utils.py | 27 ++- utils/image_utils.py | 37 +-- 8 files changed, 786 insertions(+), 57 deletions(-) delete mode 100644 presets/macweb2.py create mode 100644 presets/macweb2/macweb2.py create mode 100644 presets/wii_internet_channel/wii_internet_channel.py diff --git a/config.py.example b/config.py.example index 866592d..e483703 100644 --- a/config.py.example +++ b/config.py.example @@ -28,3 +28,215 @@ ENABLED_EXTENSIONS = [ #"wiby", #"wikipedia", ] + +# While SIMPLIFY_HTML is True, you can use WHITELISTED_DOMAINS to disable post-processing for +# specific sites (only perform HTTPS -> HTTP conversion and character conversion (if CONVERT_CHARACTERS is True), +# without otherwise modifying the page's source code). +WHITELISTED_DOMAINS = [ + #"example.com", +] + +# Optionally, load a preset (.py file) from /presets, optimized for compatibility +# with a specific web browser. Enabling a preset may override one or more of the +# settings that follow below. +# The default values target compatability with the MacWeb 2.0 browser. +#PRESET = "wii_internet_channel" + +# -------------------------------------------------------------------------------------- +# *** One or more of the following settings may be overridden if you enable a preset *** +# -------------------------------------------------------------------------------------- + +# If True, parse HTML responses to strip specified tags and attributes. +# If False, always return the full, unmodified HTML as served by the requested site or extension +# (only perform HTTPS -> HTTP conversion and character conversion (if CONVERT_CHARACTERS is True), +# without otherwise modifying the page's source code). +SIMPLIFY_HTML = True + +# If SIMPLIFY_HTML is True, strip these HTML tags during processing: +TAGS_TO_STRIP = [ + "script", + "link", + "style", + "source", + "meta" +] + +# If SIMPLIFY_HTML is True, strip these HTML attributes during processing: +ATTRIBUTES_TO_STRIP = [ + "style", + "onclick", + "class", + "bgcolor", + "text", + "link", + "vlink" +] + +# Process images for optimal rendering on your device/browser: +CAN_RENDER_INLINE_IMAGES = False # Mostly used to conditionally enable landing page images (ex: waybackmachine.py) +RESIZE_IMAGES = True +MAX_IMAGE_WIDTH = 512 # Only used if RESIZE_IMAGES is True +MAX_IMAGE_HEIGHT = 342 # Only used if RESIZE_IMAGES is True +CONVERT_IMAGES = True +CONVERT_IMAGES_TO_FILETYPE = "gif" # Only used if CONVERT_IMAGES is True +DITHERING_ALGORITHM = "FLOYDSTEINBERG" # Only used if CONVERT_IMAGES is True and CONVERT_IMAGES_TO_FILETYPE == "gif" + +# In addition to the default web simulator prompt, add custom instructions to improve compatability with your web browser. +WEB_SIMULATOR_PROMPT_ADDENDUM = """ +IMPORTANT: The user's web browser only supports (most of) HTML 3.2 (you do not need to acknowledge this to the user, only understand it and use this knowledge to construct the HTML you respond with). +Their browser has NO CSS support and NO JavaScript support. Never include