From 4d69eb84028d20eb8da0bf35401e37be438a53a7 Mon Sep 17 00:00:00 2001 From: Foxix Date: Tue, 15 Jul 2025 12:11:29 +0000 Subject: [PATCH] Delete useless code --- src/utils/adblock.js | 54 -------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 src/utils/adblock.js diff --git a/src/utils/adblock.js b/src/utils/adblock.js deleted file mode 100644 index 3d06f94..0000000 --- a/src/utils/adblock.js +++ /dev/null @@ -1,54 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const cheerio = require('cheerio'); - -// Lazy-loaded in-memory set of ad domains -let adDomains = null; - -function loadAdDomains() { - if (adDomains) return adDomains; - adDomains = new Set(); - try { - const listPath = path.join(__dirname, '..', '..', 'easylist.txt'); - const data = fs.readFileSync(listPath, 'utf8'); - const lines = data.split('\n'); - const domainRegex = /^\|\|([^\/^]+)\^/; // matches ||domain.com^ - for (const line of lines) { - const m = domainRegex.exec(line.trim()); - if (m) { - adDomains.add(m[1].replace(/^www\./, '')); - } - } - console.log(`Adblock: loaded ${adDomains.size} domains from easylist.txt`); - } catch (e) { - console.error('Adblock: failed to load easylist.txt', e); - adDomains = new Set(); - } - return adDomains; -} - -function cleanHtml(html) { - const domains = loadAdDomains(); - const $ = cheerio.load(html); - const removed = []; - $('script[src], iframe[src], img[src], link[href]').each((_, el) => { - const attr = $(el).attr('src') || $(el).attr('href'); - if (!attr) return; - try { - const host = new URL(attr, 'https://dummy-base/').hostname.replace(/^www\./, ''); - if (domains.has(host)) { - removed.push(host); - $(el).remove(); - } - } catch (_) { - // ignore invalid URLs - } - }); - if (removed.length) { - const unique = [...new Set(removed)]; - console.log(`Adblock removed resources from: ${unique.join(', ')}`); - } - return $.html(); -} - -module.exports = { cleanHtml };