From 842dc708297437ed62b6656a42aad8a11ecf44fe Mon Sep 17 00:00:00 2001 From: Ujwal223 Date: Mon, 25 May 2026 22:12:38 +0545 Subject: [PATCH] V2 Release --- .github/workflows/codeql.yml | 54 ------- .github/workflows/release-apk.yml | 143 ++++++++++++++++++ .github/workflows/release.yml | 12 -- .gitignore | 3 +- CHANGELOG.md | 26 +++- README.md | 4 +- android/app/build.gradle.kts | 2 +- assets/scripts/fetch_interceptor.js | 2 +- decoded.jks | 0 lib/features/loading/skeleton_screen.dart | 12 +- .../native_nav/native_bottom_nav.dart | 20 +-- .../preloader/instagram_preloader.dart | 7 +- .../reels_history/reels_history_service.dart | 16 +- .../update_checker/update_banner.dart | 12 +- .../update_checker_service.dart | 5 +- lib/focus_settings.dart | 16 +- lib/main.dart | 7 +- lib/screens/extras_settings_page.dart | 34 ++++- lib/screens/main_webview_page.dart | 134 ++++++++++++++-- lib/screens/settings_page.dart | 56 ++----- lib/scripts/content_disabling.dart | 53 ++++++- lib/scripts/dm_keyboard_fix.dart | 1 - lib/scripts/focus_scripts.dart | 26 ++-- lib/scripts/haptic_bridge.dart | 1 - lib/scripts/scroll_smoothing.dart | 1 - lib/scripts/spa_navigation_monitor.dart | 1 - lib/scripts/video_downloader.dart | 2 +- lib/services/remote_popup_service.dart | 84 ++++++++++ lib/services/settings_service.dart | 7 +- lib/widgets/remote_popup_handler.dart | 36 +++++ pubspec.yaml | 2 +- ...main_webview_page_media_download_test.dart | 6 +- test/services/screen_time_service_test.dart | 41 ++--- v2/ad_blocker_dom.js | 8 +- v2/assets/scripts/fetch_interceptor.js | 2 +- v2/autoplay_blocker.js | 83 ---------- v2/fetch_interceptor.js | 29 ++-- v2/instagram_webview.dart | 28 +++- 38 files changed, 642 insertions(+), 334 deletions(-) delete mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/release-apk.yml delete mode 100644 .github/workflows/release.yml create mode 100644 decoded.jks create mode 100644 lib/services/remote_popup_service.dart create mode 100644 lib/widgets/remote_popup_handler.dart delete mode 100644 v2/autoplay_blocker.js diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 88666a0..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - schedule: - - cron: '15 14 * * 5' - -jobs: - analyze: - name: Analyze (${{ matrix.language }}) - runs-on: ubuntu-latest - permissions: - security-events: write - packages: read - actions: read - contents: read - - strategy: - fail-fast: false - matrix: - include: - - language: java-kotlin - build-mode: manual - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Flutter - uses: subosito/flutter-action@v2 - with: - flutter-version: '3.38.7' - channel: 'stable' - cache: true - - - name: Install dependencies - run: flutter pub get - - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - build-mode: ${{ matrix.build-mode }} - - - name: Build Android (for CodeQL) - run: flutter build apk --debug - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{ matrix.language }}" \ No newline at end of file diff --git a/.github/workflows/release-apk.yml b/.github/workflows/release-apk.yml new file mode 100644 index 0000000..210ad9b --- /dev/null +++ b/.github/workflows/release-apk.yml @@ -0,0 +1,143 @@ +name: Build APK and Create GitHub Release + +on: + workflow_dispatch: + inputs: + version: + description: "Release version without leading v. Example: 1.0.0. Leave empty to read the top CHANGELOG heading." + required: false + type: string + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v5.0.0 + with: + fetch-depth: 0 + + - name: Set up Java 17 + uses: actions/setup-java@v5.2.0 + with: + distribution: temurin + java-version: "17" + + - name: Set up Android SDK + uses: android-actions/setup-android@v4.0.1 + + - name: Set up Flutter + uses: subosito/flutter-action@v2.23.0 + with: + channel: stable + cache: true + + - name: Install required Android SDK packages + shell: bash + run: | + set -euo pipefail + sdkmanager \ + "platform-tools" \ + "platforms;android-35" \ + "build-tools;34.0.0" \ + "build-tools;35.0.0" \ + "ndk;28.2.12676356" + + - name: Get dependencies + run: flutter pub get + + - name: Resolve version and tag + id: meta + shell: bash + run: | + set -euo pipefail + + INPUT_VERSION="${{ github.event.inputs.version }}" + + if [[ -n "${INPUT_VERSION}" ]]; then + VERSION="${INPUT_VERSION#v}" + else + VERSION="$(python3 - <<'PY' +from pathlib import Path +import re + +text = Path("CHANGELOG.md").read_text(encoding="utf-8") +m = re.search(r'^##\s+FocusGram\s+([0-9]+\.[0-9]+\.[0-9]+)\s*$', text, re.M) +if not m: + raise SystemExit("Could not find a top changelog heading like: ## FocusGram 2.0.0") +print(m.group(1)) +PY +)" + fi + + TAG="v${VERSION}" + + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + + - name: Extract release notes from CHANGELOG.md + shell: bash + env: + VERSION: ${{ steps.meta.outputs.version }} + run: | + set -euo pipefail + + python3 - <<'PY' +from pathlib import Path +import os +import re + +version = os.environ["VERSION"] +text = Path("CHANGELOG.md").read_text(encoding="utf-8") + +pattern = rf'(?ms)^##\s+FocusGram\s+{re.escape(version)}\s*$.*?(?=^##\s+|\Z)' +m = re.search(pattern, text) +if not m: + raise SystemExit(f"Could not find changelog section for version {version}") + +Path("release_notes.md").write_text(m.group(0).strip() + "\n", encoding="utf-8") +PY + + - name: Build release APK + run: flutter build apk --release + + - name: Upload APK artifact + uses: actions/upload-artifact@v7.0.1 + with: + name: focusgram-apk-${{ steps.meta.outputs.tag }} + path: build/app/outputs/flutter-apk/app-release.apk + if-no-files-found: error + + - name: Create Git tag + shell: bash + env: + TAG: ${{ steps.meta.outputs.tag }} + run: | + set -euo pipefail + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then + echo "Tag already exists on remote: ${TAG}" + exit 1 + fi + + git tag -a "${TAG}" -m "Release ${TAG}" + git push origin "${TAG}" + + - name: Create GitHub Release + uses: softprops/action-gh-release@v3.0.0 + with: + tag_name: ${{ steps.meta.outputs.tag }} + name: FocusGram ${{ steps.meta.outputs.tag }} + body_path: release_notes.md + files: build/app/outputs/flutter-apk/app-release.apk + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 03e0358..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: release -on: - push: - tags: - - '*' -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: subosito/flutter-action@v2 - with: - flutter-version: '3.38.7' \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8fec584..faca3f5 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ PRD.md TODO.md v2/FOCUSGRAM_V2_PLAN.md v2/FocusGram_Feed_Filtering_Reference.docx -.codex + # IntelliJ related *.iml @@ -28,7 +28,6 @@ v2/FocusGram_Feed_Filtering_Reference.docx # VS Code which you may wish to be included in version control, so this line # is commented out by default. #.vscode/ -RELEASE_GUIDE.md android/key.properties android/app/*.jks upload-keystore.jks diff --git a/CHANGELOG.md b/CHANGELOG.md index cef1663..035a394 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,23 @@ -## FocusGram 1.0.0 +## FocusGram 2.0.0 ### What's new -- Reordered Settings Page. -- Added "Click to Unblur" for posts. -- Added Persistent Notification -- Improved Grayscale Scheduling. + +- NEW: Added Media Downloader for downloading images and videos +- NEW: Added Ghost Mode +- NEW: Added a toggle for scroll lock in minimal mode +- NEW: Added Option to Choose Duration of Mindfulness Gate +- NEW: Added ability to customize number of words in typing challenge +- UPDATED: Redesigned Focus Control Flyout +- UPDATED: Settings and Reordered items +- UPDATED: Added more time Choices for reels session +- UPDATED: Improved Permission Request invocation in onboarding page. +- UPDATED: Improved Notification Alerts + + ### Bug fixes -- Fixed a Bug Where Reels Werent playing despite Reels Sessions being ON. -- Fixed a Bug Where Session End Popup could be just dismissed and app ran Normally despite session already ended. +- Fixed: back button on homepage didnt exit the app. +- Fixed: Only First image of multiple imaged posts was blurred. +- FIxed: Couldn't scroll the home feed after enabling minimal mode - Perfomance Optimizations -- Other Minor Changes. \ No newline at end of file +- A lof of other Minor fixes . \ No newline at end of file diff --git a/README.md b/README.md index ebc5734..2a11f9a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ **Use social media on your terms.** [![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL_3.0-blue.svg)](LICENSE) -[![Flutter](https://img.shields.io/badge/Flutter-3.38-blue?logo=flutter&logoColor=white)](https://flutter.dev) +[![Version](https://img.shields.io/badge/version-2.0.0-white)](https://flutter.dev) [![Downloads](https://img.shields.io/github/downloads/ujwal223/focusgram/total?label=downloads&color=blue&cacheSeconds=30)](https://github.com/ujwal223/focusgram/releases) @@ -125,8 +125,6 @@ FocusGram uses a standard Android System WebView to load `instagram.com`. All fe - CSS injection (element hiding, grayscale, scroll behaviour) - URL interception via NavigationDelegate (Reels blocking, Explore blocking) -Nothing is modified server-side. The app never reads, intercepts, or stores Instagram content beyond what is explicitly listed - ### Permissions | Permission | Reason | diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 5400393..ae5e115 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -45,7 +45,7 @@ android { minSdk = 24 targetSdk = 35 versionCode = 4 - versionName = "1.1.0" + versionName = "2.0.0" } buildTypes { diff --git a/assets/scripts/fetch_interceptor.js b/assets/scripts/fetch_interceptor.js index 8853356..7eda3cf 100644 --- a/assets/scripts/fetch_interceptor.js +++ b/assets/scripts/fetch_interceptor.js @@ -243,7 +243,7 @@ let response = await _fetch(input, init); // Only intercept GraphQL feed queries - if (!url.includes('/graphql/query') && !url.includes('/api/v1/feed')) { + if (!url.includes('/graphql') && !url.includes('/api/v1/feed')) { return response; } diff --git a/decoded.jks b/decoded.jks new file mode 100644 index 0000000..e69de29 diff --git a/lib/features/loading/skeleton_screen.dart b/lib/features/loading/skeleton_screen.dart index e0ce254..f88b3a9 100644 --- a/lib/features/loading/skeleton_screen.dart +++ b/lib/features/loading/skeleton_screen.dart @@ -92,16 +92,16 @@ class _SkeletonScreenState extends State return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Container( + SizedBox( height: 80, - padding: const EdgeInsets.symmetric(vertical: 8), child: ListView.builder( scrollDirection: Axis.horizontal, - padding: const EdgeInsets.symmetric(horizontal: 12), + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), itemCount: 6, itemBuilder: (context, index) => Padding( padding: const EdgeInsets.only(right: 12), child: Column( + mainAxisSize: MainAxisSize.min, children: [ Container( width: 56, @@ -111,13 +111,13 @@ class _SkeletonScreenState extends State borderRadius: BorderRadius.circular(28), ), ), - const SizedBox(height: 4), + const SizedBox(height: 2), Container( width: 32, - height: 8, + height: 6, decoration: BoxDecoration( color: Colors.white, - borderRadius: BorderRadius.circular(4), + borderRadius: BorderRadius.circular(3), ), ), ], diff --git a/lib/features/native_nav/native_bottom_nav.dart b/lib/features/native_nav/native_bottom_nav.dart index 35c5b9c..270f5fd 100644 --- a/lib/features/native_nav/native_bottom_nav.dart +++ b/lib/features/native_nav/native_bottom_nav.dart @@ -35,12 +35,11 @@ class NativeBottomNav extends StatelessWidget { final theme = Theme.of(context); final isDark = theme.brightness == Brightness.dark; - final bgColor = - theme.colorScheme.surface.withValues(alpha: isDark ? 0.95 : 0.98); - final iconColorInactive = - isDark ? Colors.white70 : Colors.black54; - final iconColorActive = - theme.colorScheme.primary; + final bgColor = theme.colorScheme.surface.withValues( + alpha: isDark ? 0.95 : 0.98, + ); + final iconColorInactive = isDark ? Colors.white70 : Colors.black54; + final iconColorActive = theme.colorScheme.primary; final tabs = <_NavItem>[ _NavItem( @@ -103,8 +102,7 @@ class NativeBottomNav extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: tabs.map((item) { - final color = - item.active ? iconColorActive : iconColorInactive; + final color = item.active ? iconColorActive : iconColorInactive; final opacity = item.enabled ? 1.0 : 0.35; return Expanded( @@ -129,10 +127,7 @@ class NativeBottomNav extends StatelessWidget { const SizedBox(height: 2), Text( item.label, - style: TextStyle( - fontSize: 10, - color: color, - ), + style: TextStyle(fontSize: 10, color: color), ), ], ), @@ -164,4 +159,3 @@ class _NavItem { required this.enabled, }); } - diff --git a/lib/features/preloader/instagram_preloader.dart b/lib/features/preloader/instagram_preloader.dart index 57de8dd..741976f 100644 --- a/lib/features/preloader/instagram_preloader.dart +++ b/lib/features/preloader/instagram_preloader.dart @@ -14,12 +14,10 @@ class InstagramPreloader { static Future start(String userAgent) async { if (_headlessWebView != null) return; // don't start twice - + _headlessWebView = HeadlessInAppWebView( keepAlive: keepAlive, - initialUrlRequest: URLRequest( - url: WebUri('https://www.instagram.com/'), - ), + initialUrlRequest: URLRequest(url: WebUri('https://www.instagram.com/')), initialSettings: InAppWebViewSettings( userAgent: userAgent, mediaPlaybackRequiresUserGesture: true, @@ -69,4 +67,3 @@ class InstagramPreloader { isReady = false; } } - diff --git a/lib/features/reels_history/reels_history_service.dart b/lib/features/reels_history/reels_history_service.dart index 67dec87..6364902 100644 --- a/lib/features/reels_history/reels_history_service.dart +++ b/lib/features/reels_history/reels_history_service.dart @@ -18,12 +18,12 @@ class ReelsHistoryEntry { }); Map toJson() => { - 'id': id, - 'url': url, - 'title': title, - 'thumbnailUrl': thumbnailUrl, - 'visitedAt': visitedAt.toUtc().toIso8601String(), - }; + 'id': id, + 'url': url, + 'title': title, + 'thumbnailUrl': thumbnailUrl, + 'visitedAt': visitedAt.toUtc().toIso8601String(), + }; static ReelsHistoryEntry fromJson(Map json) { return ReelsHistoryEntry( @@ -31,7 +31,8 @@ class ReelsHistoryEntry { url: (json['url'] as String?) ?? '', title: (json['title'] as String?) ?? 'Instagram Reel', thumbnailUrl: (json['thumbnailUrl'] as String?) ?? '', - visitedAt: DateTime.tryParse((json['visitedAt'] as String?) ?? '') ?? + visitedAt: + DateTime.tryParse((json['visitedAt'] as String?) ?? '') ?? DateTime.now().toUtc(), ); } @@ -114,4 +115,3 @@ class ReelsHistoryService { await prefs.setString(_prefsKey, jsonEncode(jsonList)); } } - diff --git a/lib/features/update_checker/update_banner.dart b/lib/features/update_checker/update_banner.dart index 40fa7d3..69051f8 100644 --- a/lib/features/update_checker/update_banner.dart +++ b/lib/features/update_checker/update_banner.dart @@ -32,10 +32,7 @@ class _UpdateBannerState extends State { decoration: BoxDecoration( color: colorScheme.secondaryContainer, border: Border( - bottom: BorderSide( - color: colorScheme.outlineVariant, - width: 0.5, - ), + bottom: BorderSide(color: colorScheme.outlineVariant, width: 0.5), ), ), child: Column( @@ -121,10 +118,11 @@ class _UpdateBannerState extends State { text = text.replaceAll(RegExp(r'#{1,6}\s'), ''); text = text.replaceAll(RegExp(r'\*\*(.*?)\*\*'), r'\1'); text = text.replaceAll(RegExp(r'\*(.*?)\*'), r'\1'); - text = - text.replaceAll(RegExp(r'\[([^\]]+)\]\([^)]+\)'), r'\1'); // links -> text + text = text.replaceAll( + RegExp(r'\[([^\]]+)\]\([^)]+\)'), + r'\1', + ); // links -> text text = text.replaceAll(RegExp(r'`([^`]+)`'), r'\1'); return text.trim(); } } - diff --git a/lib/features/update_checker/update_checker_service.dart b/lib/features/update_checker/update_checker_service.dart index 9e14b18..077d973 100644 --- a/lib/features/update_checker/update_checker_service.dart +++ b/lib/features/update_checker/update_checker_service.dart @@ -56,8 +56,9 @@ class UpdateCheckerService extends ChangeNotifier { return; } - final cleanVersion = - gitVersionTag.startsWith('v') ? gitVersionTag.substring(1) : gitVersionTag; + final cleanVersion = gitVersionTag.startsWith('v') + ? gitVersionTag.substring(1) + : gitVersionTag; var trimmed = body.trim(); if (trimmed.length > 1500) { diff --git a/lib/focus_settings.dart b/lib/focus_settings.dart index 6e99e28..75d7692 100644 --- a/lib/focus_settings.dart +++ b/lib/focus_settings.dart @@ -1,17 +1,17 @@ class FocusSettings { - final bool ghostMode; // hide read receipts - final bool noAds; // strip ads and sponsored posts - final bool noStories; // hide story tray - final bool noReels; // hide reels tab - final bool noAutoplay; // stop videos autoplaying - final bool noDMs; // block direct messages + final bool ghostMode; // hide read receipts + final bool noAds; // strip ads and sponsored posts + final bool noStories; // hide story tray + final bool noReels; // hide reels tab + final bool noAutoplay; // stop videos autoplaying + final bool noDMs; // block direct messages const FocusSettings({ this.ghostMode = false, - this.noAds = false, + this.noAds = true, this.noStories = false, this.noReels = false, this.noAutoplay = false, this.noDMs = false, }); -} \ No newline at end of file +} diff --git a/lib/main.dart b/lib/main.dart index 38fe0c5..db01e20 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,6 +17,7 @@ import 'screens/cooldown_gate_screen.dart'; import 'services/notification_service.dart'; import 'features/update_checker/update_checker_service.dart'; import 'features/preloader/instagram_preloader.dart'; +import 'widgets/remote_popup_handler.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -88,7 +89,7 @@ class FocusGramApp extends StatelessWidget { /// 2. Cooldown Gate (if app-open cooldown active) /// 3. Breath Gate (if enabled in settings) /// 4. If an app session is already active, resume it -/// otherwise show App Session Picker +/// otherwise show App Session Picker /// 5. Main WebView class InitialRouteHandler extends StatefulWidget { const InitialRouteHandler({super.key}); @@ -108,6 +109,10 @@ class _InitialRouteHandlerState extends State { super.initState(); _appLinks = AppLinks(); _initDeepLinks(); + + WidgetsBinding.instance.addPostFrameCallback((_) { + RemotePopupHandler.checkAndShow(context); + }); } Future _initDeepLinks() async { diff --git a/lib/screens/extras_settings_page.dart b/lib/screens/extras_settings_page.dart index 7bb9998..209ae78 100644 --- a/lib/screens/extras_settings_page.dart +++ b/lib/screens/extras_settings_page.dart @@ -46,7 +46,39 @@ class ExtrasSettingsPage extends StatelessWidget { HapticFeedback.selectionClick(); }, ), + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 16, 16), + child: Container( + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: Colors.amber.withValues(alpha: 0.07), + borderRadius: BorderRadius.circular(8), + border: Border.all(color: Colors.amber.withValues(alpha: 0.12)), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(right: 8, top: 2), + child: Icon( + Icons.info_outline, + size: 14, + color: Colors.amber, + ), + ), + const Expanded( + child: Text( + 'NOTE: The seen indicator is not sent to the sender while you are active in the chat, but as soon as you close and reopen the chat, the seen indicator is sent.', + style: TextStyle(fontSize: 11, color: Colors.amber), + ), + ), + ], + ), + ), + ), + /* TRIED BUT IT DIDNT WORK 98% oF THE TIME) + const _SectionHeader(title: 'FOCUSGRAM V2'), _SwitchTile( title: 'Ad Blocker', @@ -66,7 +98,7 @@ class ExtrasSettingsPage extends StatelessWidget { HapticFeedback.selectionClick(); }, ), - +*/ const SizedBox(height: 40), ], ), diff --git a/lib/screens/main_webview_page.dart b/lib/screens/main_webview_page.dart index e7d3f8d..a77ea53 100644 --- a/lib/screens/main_webview_page.dart +++ b/lib/screens/main_webview_page.dart @@ -27,7 +27,7 @@ import '../v2_integration/script_engine_v2_overlay.dart'; import '../v2_integration/script_registry_v2_overlay.dart'; import '../scripts/focus_scripts.dart'; import '../focus_settings.dart'; -import 'package:http/http.dart' as http; + import '../services/adblock/adblock_content_blocker_loader.dart'; @@ -127,7 +127,10 @@ class _MainWebViewPageState extends State // Check for updates on launch context.read().checkForUpdates(); - unawaited(_loadAdblockerData()); + // Load adblock data early. If adblock is enabled, we wait for initial data + // to be loaded so the WebView can apply contentBlockers on first render. + // This prevents ads from loading before filters are applied. + unawaited(_loadAdblockerDataEarly()); WidgetsBinding.instance.addPostFrameCallback((_) { context.read().addListener(_onSessionChanged); @@ -155,6 +158,9 @@ class _MainWebViewPageState extends State _lastV2AutoplayBlockerEnabled = settings.blockAutoplay; _lastAdblockToggleValue = settings.v2AdBlockerDomEnabled; _onScreenTimeChanged(); + + // Load full adblock data with longer timeout after UI is initialized + unawaited(_loadAdblockerData()); }); FocusGramRouter.pendingUrl.addListener(_onPendingUrlChanged); @@ -581,6 +587,28 @@ class _MainWebViewPageState extends State return data; } + Future _loadAdblockerDataEarly() async { + final settings = context.read(); + if (!settings.v2AdBlockerDomEnabled) return; + + try { + final prefs = await SharedPreferences.getInstance(); + final loader = AdblockContentBlockerLoader(); + final data = await loader.loadOrUpdateIfNeeded( + enabled: true, + prefs: prefs, + timeoutMs: 5000, // Short timeout for early load + ); + + if (mounted) { + setState(() => _adblockData = data); + } + } catch (_) { + // If loading fails, continue without blocking app startup + // AdblockData will be retried in _loadAdblockerData() + } + } + bool _isBlockedByAdblockHostList(WebUri uri, Set? blockedHosts) { if (blockedHosts == null || blockedHosts.isEmpty) return false; @@ -911,6 +939,24 @@ class _MainWebViewPageState extends State pullToRefreshController: _pullToRefreshController, shouldInterceptRequest: (controller, request) async { final url = request.url.toString(); + + const adDomains = [ + 'an.facebook.com', + 'connect.facebook.net', + 'pixel.facebook.com', + 'graph.facebook.com/logging', + 'www.instagram.com/ajax/bz', + 'www.instagram.com/api/v1/web/comet/logcalls', + 'doubleclick.net', + 'googletagmanager.com', + 'scorecardresearch.com', + ]; + if (adDomains.any(url.contains)) { + return WebResourceResponse( + data: Uint8List(0), + ); + } + final referrer = request.headers?['Referer'] ?? request.headers?['referer']; @@ -919,7 +965,7 @@ class _MainWebViewPageState extends State _syncDirectThreadState(referrer); } - if (_isInDirectThread && + /*if (_isInDirectThread && _isFktmInstagramCdn(url)) { if (_dmThreadCdnBlockArmed) { return WebResourceResponse( @@ -928,7 +974,7 @@ class _MainWebViewPageState extends State } _dmThreadCdnBlockArmed = true; } - +*/ // Strict/high-priority domain blocking from uBlock-style lists. final adblockHosts = _adblockData?.blockedHosts; if (_isBlockedByAdblockHostList( @@ -983,11 +1029,11 @@ class _MainWebViewPageState extends State ); } - // Strip ads from feed + /* Strip ads from feed (JS handles it) if (settings.noAds && url.contains( 'instagram.com/graphql/query', - )) { + )) {/ try { final res = await http.post( Uri.parse(url), @@ -1006,10 +1052,76 @@ class _MainWebViewPageState extends State edges.removeWhere((e) { final node = e['node']; if (node == null) return false; - return node['ad'] != null || - node['explore_story'] != null || - node['media']?['inventory_source'] == - 'mixed_unconnected'; + // Strip ads from feed + if (settings.noAds && + url.contains( + 'instagram.com/graphql', + )) { + try { + final res = await http.post( + Uri.parse(url), + headers: Map.from( + request.headers ?? {}, + ), + ); + + final json = jsonDecode(res.body); + + void filterEdges(dynamic obj) { + if (obj == null) return; + if (obj is Map) { + if (obj['edges'] is List) { + (obj['edges'] as List).removeWhere(( + e, + ) { + final node = e is Map + ? e['node'] + : null; + if (node == null || + node is! Map) + return false; + return node['is_ad'] == + true || + node['ad_id'] != null || + node['ad_action_links'] != + null || + node['is_paid_partnership'] == + true || + node['sponsor_tags'] != + null || + node['commerciality_status'] == + 'ad' || + node['commerciality_status'] == + 'shoppable_feed_ad' || + (node['__typename'] + ?.toString() + .toLowerCase() + .contains( + 'ad', + ) ?? + false); + }); + } + obj.values.forEach(filterEdges); + } else if (obj is List) { + obj.forEach(filterEdges); + } + } + + filterEdges(json); + + return WebResourceResponse( + data: Uint8List.fromList( + utf8.encode(jsonEncode(json)), + ), + headers: res.headers, + statusCode: 200, + contentType: 'application/json', + ); + } catch (_) { + return null; + } + } }); } @@ -1025,7 +1137,7 @@ class _MainWebViewPageState extends State // if anything fails, pass through original request unmodified return null; } - } + }*/ return null; }, diff --git a/lib/screens/settings_page.dart b/lib/screens/settings_page.dart index 78db905..dbbb7b7 100644 --- a/lib/screens/settings_page.dart +++ b/lib/screens/settings_page.dart @@ -46,7 +46,7 @@ class SettingsPage extends StatelessWidget { title: 'Focus Mode', subtitle: settings.minimalModeEnabled ? 'Minimal mode on' - : 'Blocking, friction, media', + : 'Blocking, Content Hider, Feed Blur and more', onTap: () => Navigator.push( context, MaterialPageRoute(builder: (_) => const FocusSettingsPage()), @@ -71,7 +71,7 @@ class SettingsPage extends StatelessWidget { icon: Icons.download_rounded, iconColor: Colors.orangeAccent, title: 'Extras', - subtitle: 'Download media, Ghost Mode, Ad Blocker', + subtitle: 'Download media, Ghost Mode', enabled: true, onTap: () => Navigator.push( context, @@ -100,7 +100,7 @@ class SettingsPage extends StatelessWidget { icon: Icons.lock_outline, iconColor: Colors.tealAccent, title: 'Privacy & Notifications', - subtitle: 'Session end alerts', + subtitle: 'Manage Your Notifications', onTap: () => Navigator.push( context, MaterialPageRoute( @@ -379,12 +379,16 @@ class FocusSettingsPage extends StatelessWidget { ), const _SectionHeader(title: 'MEDIA'), + /* + ( I TRIED SO HARD, AND GOT SO FAR, BUT IN THE END... + IT DOESNT EVEN MATTER ..... (didnt work)) + _SwitchTile( title: 'Block Autoplay Videos', subtitle: 'Videos won\'t play until you tap them', value: settings.blockAutoplay, onChanged: (v) => settings.setBlockAutoplay(v), - ), + ),*/ _SwitchTile( title: 'Blur Feed & Explore', subtitle: 'Blurs post thumbnails until tapped', @@ -403,48 +407,16 @@ class FocusSettingsPage extends StatelessWidget { ), ), - const _SectionHeader(title: 'FOCUSGRAM V2 OVERLAY'), + const _SectionHeader(title: 'CONTENT HIDER'), _SwitchTile( - title: 'Content Hider', - subtitle: 'Hide stories tray, feed posts, reels, suggested content', - value: settings.v2ContentHiderEnabled, - onChanged: (v) => settings.setV2ContentHiderEnabled(v), + title: 'Hide Feed Posts', + subtitle: + 'Hides home feed posts (stories tray, posts, suggested content)', + value: settings.contentPosts, + onChanged: (v) => settings.setContentPostsEnabled(v), ), - if (settings.v2ContentHiderEnabled) - Padding( - padding: const EdgeInsets.only(left: 32), - child: Column( - children: [ - _SwitchTile( - title: 'Hide Stories Tray', - subtitle: 'Story bubbles row', - value: settings.contentStories, - onChanged: (v) => settings.setContentStoriesEnabled(v), - ), - _SwitchTile( - title: 'Hide Feed Posts', - subtitle: 'Home feed posts', - value: settings.contentPosts, - onChanged: (v) => settings.setContentPostsEnabled(v), - ), - _SwitchTile( - title: 'Hide Reels (Feed)', - subtitle: 'Reels shown in the feed', - value: settings.contentReels, - onChanged: (v) => settings.setContentReelsEnabled(v), - ), - _SwitchTile( - title: 'Hide Suggested Content', - subtitle: 'Suggested posts and recommendation units', - value: settings.contentSuggested, - onChanged: (v) => settings.setContentSuggestedEnabled(v), - ), - ], - ), - ), - const SizedBox(height: 40), ], ), diff --git a/lib/scripts/content_disabling.dart b/lib/scripts/content_disabling.dart index fedf299..a21e9b3 100644 --- a/lib/scripts/content_disabling.dart +++ b/lib/scripts/content_disabling.dart @@ -451,18 +451,40 @@ const String kHideSuggestedPostsJS = r''' (function() { function hideSuggestedPosts() { try { - document.querySelectorAll('span, h3, h4').forEach(function(el) { + // Target text patterns that indicate suggested content + const suggestedPatterns = [ + 'Suggested for you', + 'Suggested posts', + "You're all caught up", + 'Suggested', + 'Recommendations', + 'Discover more', + 'Suggested Accounts', + ]; + + // Find and hide all elements with suggested content text + document.querySelectorAll('span, h3, h4, h2, a').forEach(function(el) { try { const text = el.textContent.trim(); - if ( - text === 'Suggested for you' || - text === 'Suggested posts' || - text === "You're all caught up" - ) { + const matched = suggestedPatterns.some(pattern => + text === pattern || text.includes(pattern) + ); + + if (matched) { let parent = el.parentElement; - for (let i = 0; i < 8 && parent; i++) { + // Traverse up to find the container section/article + for (let i = 0; i < 12 && parent; i++) { const tag = parent.tagName.toLowerCase(); - if (tag === 'article' || tag === 'section' || tag === 'li') { + const classList = parent.className || ''; + + // Hide articles, sections, lists, and common suggestion containers + if ( + tag === 'article' || + tag === 'section' || + tag === 'li' || + classList.includes('xjx87jv0') || // Instagram suggestion container + classList.includes('x1a8lsjc') // Reel suggestion container + ) { parent.style.setProperty('display', 'none', 'important'); break; } @@ -471,6 +493,21 @@ const String kHideSuggestedPostsJS = r''' } } catch(_) {} }); + + // Also hide by attribute patterns + document.querySelectorAll('[aria-label*="Suggested"], [data-testid*="suggested"]').forEach(function(el) { + try { + let parent = el; + for (let i = 0; i < 12 && parent; i++) { + const tag = parent.tagName.toLowerCase(); + if (tag === 'article' || tag === 'section' || tag === 'li') { + parent.style.setProperty('display', 'none', 'important'); + break; + } + parent = parent.parentElement; + } + } catch(_) {} + }); } catch(_) {} } diff --git a/lib/scripts/dm_keyboard_fix.dart b/lib/scripts/dm_keyboard_fix.dart index cf0322c..c5f4f05 100644 --- a/lib/scripts/dm_keyboard_fix.dart +++ b/lib/scripts/dm_keyboard_fix.dart @@ -13,4 +13,3 @@ const String kDmKeyboardFixJS = r''' } catch (_) {} }); '''; - diff --git a/lib/scripts/focus_scripts.dart b/lib/scripts/focus_scripts.dart index e417cfe..03d48bd 100644 --- a/lib/scripts/focus_scripts.dart +++ b/lib/scripts/focus_scripts.dart @@ -78,18 +78,22 @@ List buildUserScripts(FocusSettings settings) { final scripts = []; if (startScripts.isNotEmpty) { - scripts.add(UserScript( - source: startScripts.join('\n'), - injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START, - forMainFrameOnly: false, - )); + scripts.add( + UserScript( + source: startScripts.join('\n'), + injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START, + forMainFrameOnly: false, + ), + ); } if (endScripts.isNotEmpty) { - scripts.add(UserScript( - source: endScripts.join('\n'), - injectionTime: UserScriptInjectionTime.AT_DOCUMENT_END, - forMainFrameOnly: true, - )); + scripts.add( + UserScript( + source: endScripts.join('\n'), + injectionTime: UserScriptInjectionTime.AT_DOCUMENT_END, + forMainFrameOnly: true, + ), + ); } return scripts; -} \ No newline at end of file +} diff --git a/lib/scripts/haptic_bridge.dart b/lib/scripts/haptic_bridge.dart index c5f080d..aa831c4 100644 --- a/lib/scripts/haptic_bridge.dart +++ b/lib/scripts/haptic_bridge.dart @@ -9,4 +9,3 @@ const String kHapticBridgeScript = ''' }, true); })(); '''; - diff --git a/lib/scripts/scroll_smoothing.dart b/lib/scripts/scroll_smoothing.dart index ceff100..fd4e1c3 100644 --- a/lib/scripts/scroll_smoothing.dart +++ b/lib/scripts/scroll_smoothing.dart @@ -10,4 +10,3 @@ const String kScrollSmoothingJS = r''' } catch (_) {} })(); '''; - diff --git a/lib/scripts/spa_navigation_monitor.dart b/lib/scripts/spa_navigation_monitor.dart index 25dc988..829fc41 100644 --- a/lib/scripts/spa_navigation_monitor.dart +++ b/lib/scripts/spa_navigation_monitor.dart @@ -29,4 +29,3 @@ const String kSpaNavigationMonitorScript = ''' window.addEventListener('popstate', () => notifyUrlChange()); })(); '''; - diff --git a/lib/scripts/video_downloader.dart b/lib/scripts/video_downloader.dart index 4ebb7b6..5c0d66a 100644 --- a/lib/scripts/video_downloader.dart +++ b/lib/scripts/video_downloader.dart @@ -172,7 +172,7 @@ const String kVideoDownloadJS = r''' btn.innerHTML = icon(); btn.style.cssText = [ 'position:absolute', - 'z-index:2147483647', + 'z-index:999', 'width:34px', 'height:34px', 'border-radius:10px', diff --git a/lib/services/remote_popup_service.dart b/lib/services/remote_popup_service.dart new file mode 100644 index 0000000..fcc203f --- /dev/null +++ b/lib/services/remote_popup_service.dart @@ -0,0 +1,84 @@ +import 'dart:convert'; + +import 'package:http/http.dart' as http; +import 'package:shared_preferences/shared_preferences.dart'; + +class RemotePopupData { + final bool show; + final String id; + final String title; + final String body; + final int maxShows; + final String buttonText; + + RemotePopupData({ + required this.show, + required this.id, + required this.title, + required this.body, + required this.maxShows, + required this.buttonText, + }); + + factory RemotePopupData.fromJson(Map json) { + return RemotePopupData( + show: json['show'] ?? false, + id: json['id']?.toString() ?? '', + title: json['header']?.toString() ?? 'Notice', + body: json['body']?.toString() ?? '', + maxShows: json['max_shows'] ?? 1, + buttonText: json['button_text']?.toString() ?? 'OK', + ); + } +} + +class RemotePopupService { + // Keep placeholder value until you replace it. + static const String popupUrl = + 'https://raw.githubusercontent.com/Ujwal223/FocusGram/refs/heads/main/android/popup.json'; + + static Future fetchPopup() async { + try { + // Cache-busting to avoid stale popup configs from GitHub raw URLs. + final uri = Uri.parse( + '$popupUrl?t=${DateTime.now().millisecondsSinceEpoch}', + ); + + final response = await http.get( + uri, + headers: const { + 'Cache-Control': 'no-cache', + }, + ); + + if (response.statusCode != 200) return null; + + final decoded = jsonDecode(response.body); + if (decoded is! Map) return null; + + return RemotePopupData.fromJson(decoded); + } catch (_) { + return null; + } + } + + static Future shouldShow(RemotePopupData data) async { + if (!data.show) return false; + if (data.id.isEmpty) return false; + + final prefs = await SharedPreferences.getInstance(); + final key = 'popup_count_${data.id}'; + final shownCount = prefs.getInt(key) ?? 0; + + return shownCount < data.maxShows; + } + + static Future markShown(RemotePopupData data) async { + if (data.id.isEmpty) return; + + final prefs = await SharedPreferences.getInstance(); + final key = 'popup_count_${data.id}'; + final current = prefs.getInt(key) ?? 0; + await prefs.setInt(key, current + 1); + } +} diff --git a/lib/services/settings_service.dart b/lib/services/settings_service.dart index ab7e4f1..e51622e 100644 --- a/lib/services/settings_service.dart +++ b/lib/services/settings_service.dart @@ -1,4 +1,5 @@ import 'dart:convert'; + import 'package:flutter/foundation.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -407,9 +408,11 @@ class SettingsService extends ChangeNotifier { } Future setBreathGateSeconds(int seconds) async { - _breathGateSeconds = seconds.clamp(3, 60).toInt(); + final clamped = seconds.clamp(3, 60); + _breathGateSeconds = clamped.toInt(); await _prefs?.setInt(_keyBreathGateSeconds, _breathGateSeconds); - notifyListeners(); + // Defer notifyListeners to next microtask to avoid rebuild conflicts + Future.microtask(notifyListeners); } Future setWordChallengeCount(int count) async { diff --git a/lib/widgets/remote_popup_handler.dart b/lib/widgets/remote_popup_handler.dart new file mode 100644 index 0000000..1240fcc --- /dev/null +++ b/lib/widgets/remote_popup_handler.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; + +import '../services/remote_popup_service.dart'; + +class RemotePopupHandler { + static Future checkAndShow(BuildContext context) async { + final popup = await RemotePopupService.fetchPopup(); + if (popup == null) return; + + final shouldShow = await RemotePopupService.shouldShow(popup); + if (!shouldShow) return; + + await RemotePopupService.markShown(popup); + + if (!context.mounted) return; + + showDialog( + context: context, + barrierDismissible: true, + builder: (_) { + return AlertDialog( + title: Text(popup.title), + content: Text(popup.body), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: Text(popup.buttonText), + ), + ], + ); + }, + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index ab7b7bd..1048de1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: focusgram description: "FocusGram is a free, open-source digital wellness tool for Android. Blocks distracting content, sets time limits, and helps you use social media intentionally." publish_to: 'none' -version: 1.1.0 +version: 2.0.0 environment: sdk: ^3.10.7 diff --git a/test/screens/main_webview_page_media_download_test.dart b/test/screens/main_webview_page_media_download_test.dart index 864aacd..92d2a27 100644 --- a/test/screens/main_webview_page_media_download_test.dart +++ b/test/screens/main_webview_page_media_download_test.dart @@ -17,7 +17,8 @@ void main() { test('accepts http(s) instagram-like hosts and calls launcher', () async { final launched = []; final ok = await handleFocusGramMediaDownload( - raw: '{"type":"video","url":"https://cdninstagram.com/v/1.mp4","filename":"x"}', + raw: + '{"type":"video","url":"https://cdninstagram.com/v/1.mp4","filename":"x"}', launch: (uri) async => launched.add(uri), ); @@ -30,7 +31,8 @@ void main() { test('rejects non-instagram hosts even if http(s)', () async { final launched = []; final ok = await handleFocusGramMediaDownload( - raw: '{"type":"video","url":"https://example.com/video.mp4","filename":"x"}', + raw: + '{"type":"video","url":"https://example.com/video.mp4","filename":"x"}', launch: (uri) async => launched.add(uri), ); diff --git a/test/services/screen_time_service_test.dart b/test/services/screen_time_service_test.dart index b59219c..aa46dda 100644 --- a/test/services/screen_time_service_test.dart +++ b/test/services/screen_time_service_test.dart @@ -38,29 +38,32 @@ void main() { expect(raw, isNull); }); - test('startTracking increments today seconds and stopTracking persists', () async { - final s = ScreenTimeService(); - await s.init(); + test( + 'startTracking increments today seconds and stopTracking persists', + () async { + final s = ScreenTimeService(); + await s.init(); - final beforeTodayKey = DateTime.now(); - final todayKey = - '${beforeTodayKey.year.toString().padLeft(4, '0')}-' - '${beforeTodayKey.month.toString().padLeft(2, '0')}-' - '${beforeTodayKey.day.toString().padLeft(2, '0')}'; + final beforeTodayKey = DateTime.now(); + final todayKey = + '${beforeTodayKey.year.toString().padLeft(4, '0')}-' + '${beforeTodayKey.month.toString().padLeft(2, '0')}-' + '${beforeTodayKey.day.toString().padLeft(2, '0')}'; - s.startTracking(); + s.startTracking(); - // Wait ~2 seconds (test is unit-ish; still acceptable). - await Future.delayed(const Duration(seconds: 2)); + // Wait ~2 seconds (test is unit-ish; still acceptable). + await Future.delayed(const Duration(seconds: 2)); - s.stopTracking(); + s.stopTracking(); - expect(s.secondsByDate[todayKey], isNotNull); - expect(s.secondsByDate[todayKey]!, greaterThanOrEqualTo(2)); + expect(s.secondsByDate[todayKey], isNotNull); + expect(s.secondsByDate[todayKey]!, greaterThanOrEqualTo(2)); - final prefs = await SharedPreferences.getInstance(); - final stored = prefs.getString(ScreenTimeService.prefKey); - expect(stored, isNotNull); - expect(stored, contains(todayKey)); - }); + final prefs = await SharedPreferences.getInstance(); + final stored = prefs.getString(ScreenTimeService.prefKey); + expect(stored, isNotNull); + expect(stored, contains(todayKey)); + }, + ); } diff --git a/v2/ad_blocker_dom.js b/v2/ad_blocker_dom.js index 611518c..c56705b 100644 --- a/v2/ad_blocker_dom.js +++ b/v2/ad_blocker_dom.js @@ -1,6 +1,6 @@ /** * FocusGram DOM Ad Blocker - * Removes sponsored posts, "Suggested for you" injections, and ad elements. + * SHould have Removed sponsored posts, "Suggested for you" injections, and ad elements. * Uses structure-based selectors — NOT class names (those change weekly). * Injected at DOCUMENT_END. */ @@ -93,8 +93,6 @@ if (hasAdditions) scanAndRemove(); }); - observer.observe(document.body, { - childList: true, - subtree: true, - }); + const feed = document.querySelector('main') ?? document.body; +observer.observe(feed, { childList: true, subtree: true }); })(); diff --git a/v2/assets/scripts/fetch_interceptor.js b/v2/assets/scripts/fetch_interceptor.js index ee3aefe..c414187 100644 --- a/v2/assets/scripts/fetch_interceptor.js +++ b/v2/assets/scripts/fetch_interceptor.js @@ -209,7 +209,7 @@ let response = await _fetch(input, init); // Only intercept GraphQL feed queries - if (!url.includes('/graphql/query') && !url.includes('/api/v1/feed')) { + if (!url.includes('/graphql') && !url.includes('/api/v1/feed')) { return response; } diff --git a/v2/autoplay_blocker.js b/v2/autoplay_blocker.js deleted file mode 100644 index 6911383..0000000 --- a/v2/autoplay_blocker.js +++ /dev/null @@ -1,83 +0,0 @@ -/** - * FocusGram Autoplay Blocker - * Injected at DOCUMENT_START — before Instagram's JS loads. - * Prevents video autoplay by: - * 1. Blocking play() calls on video elements - * 2. Disabling autoplay attribute - * 3. Removing preload attributes - */ -(function () { - 'use strict'; - - window.__fgBlockAutoplay = false; - - // Override HTMLMediaElement.play() to check our flag - const _play = HTMLMediaElement.prototype.play; - HTMLMediaElement.prototype.play = function () { - if (window.__fgBlockAutoplay) { - // Return a resolved promise to avoid breaking Instagram's code - return Promise.resolve(); - } - return _play.call(this); - }; - - // Override autoplay property setter - const _videoDescriptor = Object.getOwnPropertyDescriptor(HTMLVideoElement.prototype, 'autoplay') || {}; - const _originalAutoplaySetter = _videoDescriptor.set; - - Object.defineProperty(HTMLVideoElement.prototype, 'autoplay', { - set: function (value) { - if (window.__fgBlockAutoplay && value) { - // Silently ignore autoplay attempts when blocking is enabled - return; - } - if (_originalAutoplaySetter) { - _originalAutoplaySetter.call(this, value); - } - }, - get: function () { - if (_videoDescriptor.get) { - return _videoDescriptor.get.call(this); - } - return this.getAttribute('autoplay') !== null; - }, - enumerable: _videoDescriptor.enumerable, - configurable: true, - }); - - // On page load and SPA navigation, scan for video elements and remove autoplay - const removeAutoplayFromVideos = () => { - document.querySelectorAll('video, [role="video"]').forEach(el => { - if (window.__fgBlockAutoplay) { - el.autoplay = false; - el.removeAttribute('autoplay'); - if (el.paused === false) { - el.pause(); - } - } - }); - }; - - // Run on load and when document changes - removeAutoplayFromVideos(); - - if (!window.__fgAutoplayObserver) { - let _timer = null; - window.__fgAutoplayObserver = new MutationObserver(() => { - clearTimeout(_timer); - _timer = setTimeout(removeAutoplayFromVideos, 500); - }); - window.__fgAutoplayObserver.observe(document.documentElement, { - childList: true, - subtree: true, - }); - } - - // Allow Flutter to toggle - window.__fgSetBlockAutoplay = function (enabled) { - window.__fgBlockAutoplay = !!enabled; - if (enabled) { - removeAutoplayFromVideos(); - } - }; -})(); diff --git a/v2/fetch_interceptor.js b/v2/fetch_interceptor.js index 3c30f80..7a90bf4 100644 --- a/v2/fetch_interceptor.js +++ b/v2/fetch_interceptor.js @@ -23,16 +23,22 @@ // Helper: Check if a node is an ad const isAdNode = (node) => { - if (!node || typeof node !== 'object') return false; - - return !!( - node.is_ad || - node.ad_action_link || - node.ad_id || - (node.product_type && node.product_type === 'ad') || - (node.ad_header_style && node.ad_header_style !== 'none') || - (node.__typename && node.__typename === 'GraphAdStory') - ); + if (!node || typeof node !== 'object') return false; + return !!( + node.is_ad || + node.ad_id || + node.ad_action_link || + node.ad_action_links?.length > 0 || + node.is_paid_partnership || + node.sponsor_tags?.length > 0 || + (node.commerciality_status === 'ad') || + (node.commerciality_status === 'shoppable_feed_ad') || + (node.product_type === 'ad') || + (node.ad_header_style && node.ad_header_style !== 'none') || + node.__typename === 'GraphAdStory' || + node.__typename === 'XDTAdFeedUnit' || + (node.__typename?.toLowerCase().includes('ad')) + ); }; // Helper: Check if a node is sponsored @@ -158,6 +164,7 @@ } } }; + // Override fetch const _fetch = window.fetch.bind(window); @@ -173,7 +180,7 @@ let response = await _fetch(input, init); // Only intercept GraphQL feed queries - if (!url.includes('/graphql/query') && !url.includes('/api/v1/feed')) { + if (!url.includes('/graphql') && !url.includes('/api/v1/feed')) { return response; } diff --git a/v2/instagram_webview.dart b/v2/instagram_webview.dart index 1aab363..724bb0c 100644 --- a/v2/instagram_webview.dart +++ b/v2/instagram_webview.dart @@ -78,7 +78,6 @@ class InstagramWebViewState extends State { // ── ContentBlockers — merged base + EasyList rules ────────────── contentBlockers: WebViewConfig.baseContentBlockers, - // TODO Phase 1.5: merge EasyListParser.load() here at startup // ── User Scripts — AT_DOCUMENT_START critical for ghost mode ───── initialUserScripts: UnmodifiableListView( @@ -96,6 +95,33 @@ class InstagramWebViewState extends State { onWebViewCreated: (controller) async { _controller = controller; + //Interceptor for adblock + shouldInterceptRequest: + (controller, request) async { + final url = request.url.toString(); + + const adDomains = [ + 'an.facebook.com', + 'connect.facebook.net', + 'pixel.facebook.com', + 'graph.facebook.com/logging', + 'www.instagram.com/ajax/bz', + 'www.instagram.com/api/v1/web/comet/logcalls', + 'doubleclick.net', + 'googletagmanager.com', + 'scorecardresearch.com', + ]; + + if (adDomains.any(url.contains)) { + return WebResourceResponse( + contentType: 'application/json', + httpStatus: WebResourceResponseHTTPStatus(statusCode: 200), + data: Uint8List.fromList(utf8.encode('{}')), + ); + } + return null; + }; + // Initialize GhostModeService _ghostMode = GhostModeService(); await _ghostMode!.load();