Merge branch 'main' into feat/status-page-and-bypass-fallbacks

This commit is contained in:
Wasi Master
2026-05-12 00:06:04 +06:00
committed by GitHub
9 changed files with 62 additions and 283 deletions
+14 -3
View File
@@ -1,5 +1,12 @@
# syntax=docker/dockerfile:1
FROM python:3.13.7-alpine FROM python:3.13.7-alpine
ARG UID=1000
ARG GID=1000
RUN addgroup -g $GID thirteener
RUN adduser -D -g '' -u $UID -G thirteener thirteener
# Generic labels # Generic labels
LABEL maintainer="Arian Mollik Wasi <arianmollik323@gmail.com>" LABEL maintainer="Arian Mollik Wasi <arianmollik323@gmail.com>"
LABEL version="0.3.4" LABEL version="0.3.4"
@@ -18,9 +25,13 @@ LABEL org.opencontainers.image.description="My own custom 12ft.io replacement"
LABEL org.opencontainers.image.documentation="https://github.com/wasi-master/13ft/blob/main/README.md" LABEL org.opencontainers.image.documentation="https://github.com/wasi-master/13ft/blob/main/README.md"
LABEL org.opencontainers.image.licenses=MIT LABEL org.opencontainers.image.licenses=MIT
RUN python -m pip install --upgrade pip
USER thirteener
COPY . . COPY . .
RUN pip install -r requirements.txt RUN --mount=type=cache,mode=0755,target=/home/thirteener/.cache/pip \
pip install -U -r requirements.txt
WORKDIR /app WORKDIR /app
EXPOSE 5000 EXPOSE 5000
ENTRYPOINT [ "python" ] CMD [ "python", "-m", "gunicorn", "portable:app" ]
CMD [ "portable.py" ]
+13 -6
View File
@@ -15,6 +15,7 @@ It pretends to be GoogleBot (Google's web crawler) and gets the same content tha
### Using Docker ### Using Docker
Requirements: Requirements:
- docker - docker
- Docker Compose (available as `docker compose`) - Docker Compose (available as `docker compose`)
@@ -47,7 +48,13 @@ Then run `portable.py`, click [this link](https://realpython.com/run-python-scri
python portable.py python portable.py
``` ```
Then open the link shown in the terminal in the browser and you'll be able to use this Or you can also run via gunicorn as follows:
```sh
python -m gunicorn 'portable:app'
```
Then open the link shown in the terminal in the browser and you'll be able to use this script
### Installation using venv and running under specific bind address / port ### Installation using venv and running under specific bind address / port
@@ -58,16 +65,18 @@ python -m pip install -r requirements.txt
FLASK_APP=app/portable.py flask run --host=127.0.0.1 --port=9982 FLASK_APP=app/portable.py flask run --host=127.0.0.1 --port=9982
``` ```
## Using as a Bookmarklet in Chrome: ## Using as a Bookmarklet in Chrome:
You can create a bookmarklet that performs the URL transformation by writing a small JavaScript snippet. Below is the JavaScript code for your bookmarklet: You can create a bookmarklet that performs the URL transformation by writing a small JavaScript snippet. Below is the JavaScript code for your bookmarklet:
```javascript ```javascript
javascript:(function(){window.location.href='https://13ft.wasimaster.me/'+encodeURIComponent(window.location.href);})(); javascript: (function () {window.location.href="https://13ft.wasimaster.me/" + encodeURIComponent(window.location.href);})();
``` ```
You can replace https://13ft.wasimaster.me with your own 13ft instance if desired. You can replace https://13ft.wasimaster.me with your own 13ft instance if desired.
Steps: Steps:
1. Open Bookmarks Manager: 1. Open Bookmarks Manager:
2. Click on the three dots (menu) in the top-right corner of Chrome. 2. Click on the three dots (menu) in the top-right corner of Chrome.
@@ -75,9 +84,7 @@ Go to Bookmarks > Bookmark manager, or simply press Ctrl+Shift+O on Windows/Linu
Create a New Bookmark: Create a New Bookmark:
3. In the Bookmark Manager, click the three-dot menu in the top-right corner of the window and select Add new bookmark. 3. In the Bookmark Manager, click the three-dot menu in the top-right corner of the window and select Add new bookmark.
Enter Bookmark Details: Enter Bookmark Details: - Name: Enter a name for your bookmarklet, such as "13ft-ize". This name will show as a bookmark title in the bookmarks bar - URL: Paste the JavaScript code provided above into the URL field.
- Name: Enter a name for your bookmarklet, such as "13ft-ize". This name will show as a bookmark title in the bookmarks bar
- URL: Paste the JavaScript code provided above into the URL field.
4. Click Save. 4. Click Save.
Using the Bookmarklet: Using the Bookmarklet:
+4
View File
@@ -0,0 +1,4 @@
from os import environ
# https://docs.gunicorn.org/en/stable/settings.html#settings
bind = f"0.0.0.0:{environ.get('PORT', 5000)}"
-177
View File
@@ -1,177 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>13ft Ladder</title>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet" async>
<style>
body {
font-family: 'Open Sans', sans-serif;
background-color: #FFF;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 90vh;
transition: background-color 0.3s, color 0.3s;
}
h1 {
font-size: 1.5rem;
margin-bottom: 20px;
text-align: center;
color: #333;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type=text] {
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
width: 100%;
font-size: 1rem;
box-sizing: border-box;
}
input[type="submit"] {
padding: 16px;
background-color: #a327f0;
color: #fff;
border: none;
border-radius: 5px;
width: 100%;
text-transform: uppercase;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease;
}
input[type="submit"]:hover {
background-color: #821fc0;
}
/* Toggle switch styles */
.dark-mode-toggle {
position: absolute;
top: 10px;
right: 10px;
}
.dark-mode-toggle input {
display: none;
}
.dark-mode-toggle label {
cursor: pointer;
text-indent: -9999px;
width: 52px;
height: 27px;
background: grey;
display: block;
border-radius: 100px;
position: relative;
}
.dark-mode-toggle label:after {
content: '';
position: absolute;
top: 2px;
left: 2px;
width: 23px;
height: 23px;
background: #fff;
border-radius: 90px;
transition: 0.3s;
}
.dark-mode-toggle input:checked+label {
background: #7359f8;
}
.dark-mode-toggle input:checked+label:after {
left: calc(100% - 2px);
transform: translateX(-100%);
}
/* Responsive adjustments */
@media only screen and (max-width: 600px) {
form {
padding: 10px;
}
h1 {
font-size: 1.2rem;
}
}
/* Dark mode styles */
body.dark-mode {
background-color: #191a21;
color: #FFF;
}
body.dark-mode h1 {
color: #FFF;
}
body.dark-mode input[type=text] {
background-color: #555;
border: 1px solid #777;
color: #FFF;
}
body.dark-mode input[type="submit"] {
background-color: #7359f8;
}
body.dark-mode input[type="submit"]:hover {
background-color: #5c47c6;
}
</style>
</head>
<body>
<div class="dark-mode-toggle">
<input type="checkbox" id="dark-mode-toggle">
<label for="dark-mode-toggle" title="Toggle Dark Mode"></label>
</div>
<form action="/article" method="post">
<h1>Enter Website Link</h1>
<label for="link">Link of the website you want to remove paywall for:</label>
<input type="text" id="link" name="link" required autofocus>
<input type="submit" value="Submit">
</form>
<script>
const toggleSwitch = document.getElementById('dark-mode-toggle');
const currentTheme = localStorage.getItem('theme') || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
if (currentTheme === "dark") {
document.body.classList.add("dark-mode");
toggleSwitch.checked = true;
}
toggleSwitch.addEventListener('change', function () {
if (this.checked) {
document.body.classList.add("dark-mode");
localStorage.setItem('theme', 'dark');
} else {
document.body.classList.remove("dark-mode");
localStorage.setItem('theme', 'light');
}
});
</script>
</body>
</html>
-82
View File
@@ -1,82 +0,0 @@
import flask
import requests
from flask import request
from bs4 import BeautifulSoup
from urllib.parse import urlparse, urljoin
app = flask.Flask(__name__)
googlebot_headers = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.119 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
}
def add_base_tag(html_content, original_url):
soup = BeautifulSoup(html_content, 'html.parser')
parsed_url = urlparse(original_url)
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}/"
# Handle paths that are not root, e.g., "https://x.com/some/path/w.html"
if parsed_url.path and not parsed_url.path.endswith('/'):
base_url = urljoin(base_url, parsed_url.path.rsplit('/', 1)[0] + '/')
base_tag = soup.find('base')
print(base_url)
if not base_tag:
new_base_tag = soup.new_tag('base', href=base_url)
if soup.head:
soup.head.insert(0, new_base_tag)
else:
head_tag = soup.new_tag('head')
head_tag.insert(0, new_base_tag)
soup.insert(0, head_tag)
return str(soup)
def bypass_paywall(url):
"""
Bypass paywall for a given url
"""
if url.startswith("http"):
response = requests.get(url, headers=googlebot_headers)
response.encoding = response.apparent_encoding
return add_base_tag(response.text, response.url)
try:
return bypass_paywall("https://" + url)
except requests.exceptions.RequestException as e:
return bypass_paywall("http://" + url)
@app.route("/")
def main_page():
return flask.send_from_directory(".", "index.html")
@app.route("/article", methods=["POST"])
def show_article():
link = flask.request.form["link"]
try:
return bypass_paywall(link)
except requests.exceptions.RequestException as e:
return str(e), 400
except Exception as exc:
raise exc
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>", methods=["GET"])
def get_article(path):
full_url = request.url
parts = full_url.split("/", 4)
if len(parts) >= 5:
actual_url = "https://" + parts[4].lstrip("/")
try:
return bypass_paywall(actual_url)
except requests.exceptions.RequestException as e:
return str(e), 400
except e:
raise e
else:
return "Invalid URL", 400
app.run(debug=False)
+14 -9
View File
@@ -1,3 +1,6 @@
import os
from urllib.parse import urljoin, urlparse
import flask import flask
import re import re
import requests import requests
@@ -408,20 +411,21 @@ html = """
def add_base_tag(html_content, original_url): def add_base_tag(html_content, original_url):
soup = BeautifulSoup(html_content, 'html.parser') soup = BeautifulSoup(html_content, "html.parser")
parsed_url = urlparse(original_url) parsed_url = urlparse(original_url)
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}/" base_url = f"{parsed_url.scheme}://{parsed_url.netloc}/"
if parsed_url.path and not parsed_url.path.endswith('/'):
base_url = urljoin(base_url, parsed_url.path.rsplit('/', 1)[0] + '/')
base_tag = soup.find('base')
# Handle paths that are not root, e.g., "https://x.com/some/path/w.html"
if parsed_url.path and not parsed_url.path.endswith("/"):
base_url = urljoin(base_url, parsed_url.path.rsplit("/", 1)[0] + "/")
base_tag = soup.find("base")
if not base_tag: if not base_tag:
new_base_tag = soup.new_tag('base', href=base_url) new_base_tag = soup.new_tag("base", href=base_url)
if soup.head: if soup.head:
soup.head.insert(0, new_base_tag) soup.head.insert(0, new_base_tag)
else: else:
head_tag = soup.new_tag('head') head_tag = soup.new_tag("head")
head_tag.insert(0, new_base_tag) head_tag.insert(0, new_base_tag)
soup.insert(0, head_tag) soup.insert(0, head_tag)
@@ -711,8 +715,8 @@ def show_article():
return bypass_paywall(link) return bypass_paywall(link)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
return str(e), 400 return str(e), 400
except Exception as exc: except Exception as e:
raise exc raise e
@app.route("/", defaults={"path": ""}) @app.route("/", defaults={"path": ""})
@@ -732,4 +736,5 @@ def get_article(path):
return "Invalid URL", 400 return "Invalid URL", 400
app.run(host="0.0.0.0", port=5000, debug=False) if __name__ == "__main__":
app.run(host="0.0.0.0", port=os.getenv("PORT") or 5000, debug=False)
+3 -2
View File
@@ -1,3 +1,4 @@
flask
requests
bs4 bs4
flask
gunicorn
requests
+9
View File
@@ -0,0 +1,9 @@
services:
13ft:
container_name: 13ft
hostname: 13ft
build:
context: .
restart: unless-stopped
ports:
- "5000:5000"
+3 -2
View File
@@ -1,3 +1,4 @@
flask
requests
bs4 bs4
flask
gunicorn
requests