-
Notifications
You must be signed in to change notification settings - Fork 2
/
UserAgentFixer.txt
75 lines (63 loc) · 5.98 KB
/
UserAgentFixer.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
!
! Title: "User Agent Fixer" - by K-mik@Z
! Expires: 4 days (update frequency)
! Author: K-mik@Z
! Homepage: https://github.com/K-mikaZ/new_approach_adb__1st/blob/master/UserAgentFixer.txt
! Description: User agent mocker for adguard.
!
!---------------------------------------------------------------------------------------------!
! ... No current plans for User-Agent Reduction on iOS and Android WebView at this time.
! ... https://www.chromium.org/updates/ua-reduction/#applicable-platforms
! ... https://adguard.com/kb/fr/general/ad-filtering/create-own-filters/#platform-and-not_platform-hints
!---------------------------------------------------------------------------------------------!
!#if adguard
! Error executing AG js: TypeError: Cannot redefine property: userAgent
! Set chromium-based browser User-Agent reduction snippets after the Mock the User-Agent with try/catch
!---------------------------------------------------------------------------------------------!
!----------------------------- start General JS API ------------------------------------------!
!---------------------------------------------------------------------------------------------!
!---------------------------------------------------------------------------------------------!
! ... Helper variables
! ... What are the latest user agents: https://www.whatismybrowser.com/guides/the-latest-user-agent
!---------------------------------------------------------------------------------------------!
! chromium-based Browser
#%#var AG_chromiumBasedBrowser=/^Mozilla\/5\.0 \(((?<platform>Lin|Win|Mac|X11; C|X11; L)+[^\)]+)\) AppleWebKit\/537.36 \(KHTML, like Gecko\) Chrome\/(?<major>\d+)[\d\.]+(?<mobile>[ Mobile]*) Safari\/537\.36(.+)?$/;
! gecko-based Browser ( replace `Chrome` from AG_chromiumBasedBrowser with `(.+)` ).
#%#var AG_geckoBasedBrowser=/^Mozilla\/5\.0 \(((?<platform>Lin|Win|Mac|X11; C|X11; L)+[^\)]+)\) AppleWebKit\/537.36 \(KHTML, like Gecko\) (.+)\/(?<major>\d+)[\d\.]+(?<mobile>[ Mobile]*) Safari\/537\.36(.+)?$/;
! The unifiedPlatform value comes from taking the short platform match and replacing it with the appropriate reduced value.
#%#var AG_unifiedPlatform={ 'Lin': 'Linux; Android 10; K', 'Win': 'Windows NT 10.0; Win64; x64', 'Mac': 'Macintosh; Intel Mac OS X 10_15_7', 'X11; C': 'X11; CrOS x86_64', 'X11; L': 'X11; Linux x86_64' };
!---------------------------------------------------------------------------------------------!
! ... Functions for simplify setting UA browser
! ... reduce-ua.js: https://gist.github.com/rowan-m/6f008cb407a81b9d52c00adbb9692929
!---------------------------------------------------------------------------------------------!
! Set UA to `chrome`, platform `Windows`.
#%#var AG_setGeckoBasedBrowserAsChromePlatformWindows=function setUA(){ try { const matched = AG_geckoBasedBrowser.exec(navigator.userAgent); if (matched) { const mockUA = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${matched.groups.major}.0.0.0${matched.groups.mobile} Safari/537.36`; Object.defineProperty(navigator, 'userAgent', { get: function() { return mockUA; }, enumerable: true, configurable: true }); }; } catch(e){} };
! Set UA to `chrome` (no platform change).
#%#var AG_setGeckoBasedBrowserAsChrome=function setUA(){ try { const matched = AG_geckoBasedBrowser.exec(navigator.userAgent); if (matched) { const mockUA = `Mozilla/5.0 (${AG_unifiedPlatform[matched.groups.platform]}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${matched.groups.major}.0.0.0${matched.groups.mobile} Safari/537.36`; Object.defineProperty(navigator, 'userAgent', { get: function() { return mockUA; }, enumerable: true, configurable: true }); }; } catch(e){} };
!---------------------------------------------------------------------------------------------!
!------------------------------- end General JS API ------------------------------------------!
!---------------------------------------------------------------------------------------------!
!---------------------------------------------------------------------------------------------!
! ... Mock the User-Agent ( set to chrome ) for geko-based browser
!---------------------------------------------------------------------------------------------!
! #### [FIX] Because of rakuten.tv block linux users.
!+ NOT_PLATFORM(ios, windows)
rakuten.tv#%#AG_setGeckoBasedBrowserAsChromePlatformWindows()
! #### [FIX] Google's YouTube load slower in non-Google browsers, specifically Firefox and Edge.
!+ NOT_PLATFORM(ios, ext_chromium)
music.youtube.com,m.youtube.com,youtubekids.com,www.youtube.com#%#AG_setGeckoBasedBrowserAsChrome()
!---------------------------------------------------------------------------------------------!
! ... User-Agent reduction snippets
! ... Code snippets to transform the current Chrome user-agent to the reduced format.
! ... equivalent to `--enable-features=ReduceUserAgent`
! ... https://developer.chrome.com/docs/privacy-sandbox/user-agent/snippets/#javascript
! ... https://www.chromium.org/updates/ua-reduction#TOC-Reduced-User-Agent-String-Reference
! ... Test here: [reduced-ua.glitch.me](https://reduced-ua.glitch.me/)
! ... READ ALSO
! ... Prevent covert tracking with User-Agent reduction: https://developer.chrome.com/docs/privacy-sandbox/user-agent/
! ... Limit passively shared browser data to reduce the volume of sensitive information which leads to fingerprinting.
!---------------------------------------------------------------------------------------------!
! reduce UA `only if chromium-based browser`.
!!+ NOT_PLATFORM(ios)
!~www.tiktok.com,www.twitch.tv#%#(function reduceUA(){ try { const matched = AG_chromiumBasedBrowser.exec(navigator.userAgent); if (matched) { const mockUA = `Mozilla/5.0 (${AG_unifiedPlatform[matched.groups.platform]}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${matched.groups.major}.0.0.0${matched.groups.mobile} Safari/537.36`; Object.defineProperty(navigator, 'userAgent', { get: function() { return mockUA; }, enumerable: true, configurable: true }); }; } catch(e){} })();
!#endif