Replace uBlock Origin with uBlock Origin Lite (#866)

This commit is contained in:
Sascha Ißbrücker 2024-09-29 14:42:50 +02:00 committed by GitHub
parent d4c348cc5a
commit 5cd6d773db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 50 additions and 41 deletions

2
.gitignore vendored
View file

@ -192,7 +192,7 @@ typings/
# Database file # Database file
/data /data
# ublock + chromium # ublock + chromium
/uBlock0.chromium /uBOLite.chromium.mv3
/chromium-profile /chromium-profile
# direnv # direnv
/.direnv /.direnv

View file

@ -66,7 +66,7 @@ class SingleFileServiceTestCase(TestCase):
'--browser-arg="--headless=new"', '--browser-arg="--headless=new"',
'--browser-arg="--user-data-dir=./chromium-profile"', '--browser-arg="--user-data-dir=./chromium-profile"',
'--browser-arg="--no-sandbox"', '--browser-arg="--no-sandbox"',
'--browser-arg="--load-extension=uBlock0.chromium"', '--browser-arg="--load-extension=uBOLite.chromium.mv3"',
"http://example.com", "http://example.com",
self.html_filepath + ".tmp", self.html_filepath + ".tmp",
] ]
@ -88,7 +88,7 @@ class SingleFileServiceTestCase(TestCase):
'--browser-arg="--headless=new"', '--browser-arg="--headless=new"',
'--browser-arg="--user-data-dir=./chromium-profile"', '--browser-arg="--user-data-dir=./chromium-profile"',
'--browser-arg="--no-sandbox"', '--browser-arg="--no-sandbox"',
'--browser-arg="--load-extension=uBlock0.chromium"', '--browser-arg="--load-extension=uBOLite.chromium.mv3"',
"--some-option", "--some-option",
"some value", "some value",
"--another-option", "--another-option",

View file

@ -88,18 +88,20 @@ CMD ["./bootstrap.sh"]
FROM node:18-alpine AS ublock-build FROM node:18-alpine AS ublock-build
WORKDIR /etc/linkding WORKDIR /etc/linkding
# Install necessary tools # Install necessary tools
RUN apk add --no-cache curl jq unzip # Download and unzip the latest uBlock Origin Lite release
# Fetch the latest release tag # Patch manifest to enable annoyances by default
# Download the library # Patch ruleset-manager.js to use rulesets enabled in manifest by default
# Unzip the library RUN apk add --no-cache curl jq unzip && \
RUN TAG=$(curl -sL https://api.github.com/repos/gorhill/uBlock/releases/latest | jq -r '.tag_name') && \ TAG=$(curl -sL https://api.github.com/repos/uBlockOrigin/uBOL-home/releases/latest | jq -r '.tag_name') && \
DOWNLOAD_URL=https://github.com/gorhill/uBlock/releases/download/$TAG/uBlock0_$TAG.chromium.zip && \ DOWNLOAD_URL=https://github.com/uBlockOrigin/uBOL-home/releases/download/$TAG/$TAG.chromium.mv3.zip && \
curl -L -o uBlock0.zip $DOWNLOAD_URL && \ echo "Downloading $DOWNLOAD_URL" && \
unzip uBlock0.zip curl -L -o uBOLite.zip $DOWNLOAD_URL && \
# Patch assets.json to enable easylist-cookies by default unzip uBOLite.zip -d uBOLite.chromium.mv3 && \
RUN curl -L -o ./uBlock0.chromium/assets/thirdparties/easylist/easylist-cookies.txt https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt rm uBOLite.zip && \
RUN jq '."assets.json" |= del(.cdnURLs) | ."assets.json".contentURL = ["assets/assets.json"] | ."fanboy-cookiemonster" |= del(.off) | ."fanboy-cookiemonster".contentURL += ["assets/thirdparties/easylist/easylist-cookies.txt"]' ./uBlock0.chromium/assets/assets.json > temp.json && \ jq '.declarative_net_request.rule_resources |= map(if .id == "annoyances-overlays" or .id == "annoyances-cookies" or .id == "annoyances-social" or .id == "annoyances-widgets" or .id == "annoyances-others" then .enabled = true else . end)' \
mv temp.json ./uBlock0.chromium/assets/assets.json uBOLite.chromium.mv3/manifest.json > temp.json && \
mv temp.json uBOLite.chromium.mv3/manifest.json && \
sed -i 's/const out = \[ '\''default'\'' \];/const out = await dnr.getEnabledRulesets();/' uBOLite.chromium.mv3/js/ruleset-manager.js
FROM linkding AS linkding-plus FROM linkding AS linkding-plus
@ -107,8 +109,8 @@ FROM linkding AS linkding-plus
RUN apk update && apk add nodejs npm chromium RUN apk update && apk add nodejs npm chromium
# install single-file from fork for now, which contains several hotfixes # install single-file from fork for now, which contains several hotfixes
RUN npm install -g https://github.com/sissbruecker/single-file-cli/tarball/4c54b3bc704cfb3e96cec2d24854caca3df0b3b6 RUN npm install -g https://github.com/sissbruecker/single-file-cli/tarball/4c54b3bc704cfb3e96cec2d24854caca3df0b3b6
# copy uBlock0 # copy uBlock
COPY --from=ublock-build /etc/linkding/uBlock0.chromium uBlock0.chromium/ COPY --from=ublock-build /etc/linkding/uBOLite.chromium.mv3 uBOLite.chromium.mv3/
# create chromium profile folder for user running background tasks # create chromium profile folder for user running background tasks
RUN mkdir -p chromium-profile && chown -R www-data:www-data chromium-profile RUN mkdir -p chromium-profile && chown -R www-data:www-data chromium-profile
# enable snapshot support # enable snapshot support

View file

@ -86,18 +86,20 @@ CMD ["./bootstrap.sh"]
FROM node:18-alpine AS ublock-build FROM node:18-alpine AS ublock-build
WORKDIR /etc/linkding WORKDIR /etc/linkding
# Install necessary tools # Install necessary tools
RUN apk add --no-cache curl jq unzip # Download and unzip the latest uBlock Origin Lite release
# Fetch the latest release tag # Patch manifest to enable annoyances by default
# Download the library # Patch ruleset-manager.js to use rulesets enabled in manifest by default
# Unzip the library RUN apk add --no-cache curl jq unzip && \
RUN TAG=$(curl -sL https://api.github.com/repos/gorhill/uBlock/releases/latest | jq -r '.tag_name') && \ TAG=$(curl -sL https://api.github.com/repos/uBlockOrigin/uBOL-home/releases/latest | jq -r '.tag_name') && \
DOWNLOAD_URL=https://github.com/gorhill/uBlock/releases/download/$TAG/uBlock0_$TAG.chromium.zip && \ DOWNLOAD_URL=https://github.com/uBlockOrigin/uBOL-home/releases/download/$TAG/$TAG.chromium.mv3.zip && \
curl -L -o uBlock0.zip $DOWNLOAD_URL && \ echo "Downloading $DOWNLOAD_URL" && \
unzip uBlock0.zip curl -L -o uBOLite.zip $DOWNLOAD_URL && \
# Patch assets.json to enable easylist-cookies by default unzip uBOLite.zip -d uBOLite.chromium.mv3 && \
RUN curl -L -o ./uBlock0.chromium/assets/thirdparties/easylist/easylist-cookies.txt https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt rm uBOLite.zip && \
RUN jq '."assets.json" |= del(.cdnURLs) | ."assets.json".contentURL = ["assets/assets.json"] | ."fanboy-cookiemonster" |= del(.off) | ."fanboy-cookiemonster".contentURL += ["assets/thirdparties/easylist/easylist-cookies.txt"]' ./uBlock0.chromium/assets/assets.json > temp.json && \ jq '.declarative_net_request.rule_resources |= map(if .id == "annoyances-overlays" or .id == "annoyances-cookies" or .id == "annoyances-social" or .id == "annoyances-widgets" or .id == "annoyances-others" then .enabled = true else . end)' \
mv temp.json ./uBlock0.chromium/assets/assets.json uBOLite.chromium.mv3/manifest.json > temp.json && \
mv temp.json uBOLite.chromium.mv3/manifest.json && \
sed -i 's/const out = \[ '\''default'\'' \];/const out = await dnr.getEnabledRulesets();/' uBOLite.chromium.mv3/js/ruleset-manager.js
FROM linkding AS linkding-plus FROM linkding AS linkding-plus
@ -111,9 +113,9 @@ RUN apt-get install -y gnupg2 apt-transport-https ca-certificates && \
apt-get update && apt-get install -y nodejs apt-get update && apt-get install -y nodejs
# install single-file from fork for now, which contains several hotfixes # install single-file from fork for now, which contains several hotfixes
RUN npm install -g https://github.com/sissbruecker/single-file-cli/tarball/4c54b3bc704cfb3e96cec2d24854caca3df0b3b6 RUN npm install -g https://github.com/sissbruecker/single-file-cli/tarball/4c54b3bc704cfb3e96cec2d24854caca3df0b3b6
# copy uBlock
COPY --from=ublock-build /etc/linkding/uBOLite.chromium.mv3 uBOLite.chromium.mv3/
# create chromium profile folder for user running background tasks # create chromium profile folder for user running background tasks
RUN mkdir -p chromium-profile && chown -R www-data:www-data chromium-profile RUN mkdir -p chromium-profile && chown -R www-data:www-data chromium-profile
# copy uBlock0
COPY --from=ublock-build /etc/linkding/uBlock0.chromium uBlock0.chromium/
# enable snapshot support # enable snapshot support
ENV LD_ENABLE_SNAPSHOTS=True ENV LD_ENABLE_SNAPSHOTS=True

View file

@ -1,13 +1,18 @@
rm -rf ublock0.chromium rm -rf uBOLite.chromium.mv3
TAG=$(curl -sL https://api.github.com/repos/gorhill/uBlock/releases/latest | jq -r '.tag_name') # Download uBlock Origin Lite
DOWNLOAD_URL=https://github.com/gorhill/uBlock/releases/download/$TAG/uBlock0_$TAG.chromium.zip TAG=$(curl -sL https://api.github.com/repos/uBlockOrigin/uBOL-home/releases/latest | jq -r '.tag_name')
curl -L -o uBlock0.zip $DOWNLOAD_URL DOWNLOAD_URL=https://github.com/uBlockOrigin/uBOL-home/releases/download/$TAG/$TAG.chromium.mv3.zip
unzip uBlock0.zip echo "Downloading $DOWNLOAD_URL"
rm uBlock0.zip curl -L -o uBOLite.zip $DOWNLOAD_URL
unzip uBOLite.zip -d uBOLite.chromium.mv3
rm uBOLite.zip
curl -L -o ./uBlock0.chromium/assets/thirdparties/easylist/easylist-cookies.txt https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt # Patch uBlock Origin Lite to respect rulesets enabled in manifest.json
jq '."assets.json" |= del(.cdnURLs) | ."assets.json".contentURL = ["assets/assets.json"] | ."fanboy-cookiemonster" |= del(.off) | ."fanboy-cookiemonster".contentURL += ["assets/thirdparties/easylist/easylist-cookies.txt"]' ./uBlock0.chromium/assets/assets.json > temp.json sed -i '' "s/const out = \[ 'default' \];/const out = await dnr.getEnabledRulesets();/" uBOLite.chromium.mv3/js/ruleset-manager.js
mv temp.json ./uBlock0.chromium/assets/assets.json
# Enable annoyances rulesets in manifest.json
jq '.declarative_net_request.rule_resources |= map(if .id == "annoyances-overlays" or .id == "annoyances-cookies" or .id == "annoyances-social" or .id == "annoyances-widgets" or .id == "annoyances-others" then .enabled = true else . end)' uBOLite.chromium.mv3/manifest.json > temp.json
mv temp.json uBOLite.chromium.mv3/manifest.json
mkdir -p chromium-profile mkdir -p chromium-profile

View file

@ -296,7 +296,7 @@ LD_SINGLEFILE_UBLOCK_OPTIONS = os.getenv(
'--browser-arg="--headless=new"', '--browser-arg="--headless=new"',
'--browser-arg="--user-data-dir=./chromium-profile"', '--browser-arg="--user-data-dir=./chromium-profile"',
'--browser-arg="--no-sandbox"', '--browser-arg="--no-sandbox"',
'--browser-arg="--load-extension=uBlock0.chromium"', '--browser-arg="--load-extension=uBOLite.chromium.mv3"',
] ]
), ),
) )