-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadscript.js
240 lines (220 loc) · 8.42 KB
/
adscript.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// ==UserScript==
// @name VK Ads Fixes
// @name:ru Правки рекламы ВКонтакте
// @name:uk Правки реклами ВКонтакте
// @namespace https://vtosters.app/
// @version 2.2
// @description Script for blocking ads in VK (VKontakte), bypassing blocking detection, etc.
// @description:ru Скрипт для блокировки рекламы в VK (ВКонтакте), обхода обнаружения блокировки и т.д.
// @description:uk Скрипт для блокування реклами у VK (ВКонтакті), обходу виявлення блокування тощо.
// @author gdlbo, Vologhat
// @match https://vk.com/*
// @match https://vk.ru/*
// @grant none
// @downloadURL https://update.greasyfork.org/scripts/518509/VK%20Ads%20Fixes.user.js
// @updateURL https://update.greasyfork.org/scripts/518509/VK%20Ads%20Fixes.meta.js
// ==/UserScript==
(() => {
"use strict"
class VkPeProperties
{
static #KEYS=[
"send_user_info_stats", "force_send_user_info", "send_user_info_on_localhost",
"send_navigation_stats_in_spa", "log_send_user_info_errors", "web_mytracker_collect_post_stats",
"web_stats_device_id", "web_stats_reduce_debounce", "web_stats_send_beacon",
"web_stats_send_on_events_limit", "web_stats_transport_story_view", "sentry_js_web_request_timeouts_feature",
"sentry_js_web_request_timeouts_forwarding", "sentry_js_web_timeouts_forwarding", "sentry_js_web_verbose",
"sentry_log_network_errors", "ads_app_form_link_redirect", "ads_autopromotion_web_geo",
"ads_easy_promote_goods_new_create_api", "ads_light_methods_protection", "ads_market_autopromotion_bookmarks_stats",
"ads_use_vk_community_video_portrait_4_5", "clips_web_my_tracker", "feed_post_track_code_client_web",
"games_send_track_visitor_activity", "js_errors_no_write_uncaught_errors", "tgb_adblock_protection",
"post_adblock_protection_promo", "eager_error_monitoring", "mini_apps_performance_close_app_empty_event",
"mini_apps_performance_iframe_errors", "mini_apps_performance_web", "mini_apps_send_my_tracker_activity",
"post_click_analytics_int_ext_link_click_web", "posting_track_event_count", "unique_adblock_users",
"audio_my_tracker_web", "mini_apps_send_stat_arguments_bridge_events_sdk", "ajax_request_parse_html_error",
"js_errors_no_write_uncaught_errors", "tns_track_sections", "tns_track_hosts", "geminus_counter",
"ads_pixels_track_new_events_web_mvk", "web_navigation_handlers", "measure_module_navigation_stats",
"group_join_track_event_count", "feed_content_events_open_post_event_web", "feed_posts_duration_stats_fix",
"collect_unsupported_user_info_stats", "log_fetch_requests", "log_fetch_requests_get",
"post_adguard_protection_promo", "extended_ajax_logging", "messenger_mediascope_stats_collect",
"audio_player_stats_web"
];
static isValidProperty(key)
{ return key in this.#KEYS }
}
//hook vk
let actualVk=window.vk
const vkHooks=new Set();
Object.defineProperty(window,"vk", {
get:() => actualVk,
set:(value) => {
actualVk=value
if(actualVk)vkHooks.forEach( hook => hook(actualVk))
return true
},
configurable:true
})
//hook vk properties
const createAndPerformVkPropHook=(key,hookfn) => {
//hook when vk redefines
vkHooks.add(vk => {
if(vk&&vk[key])hookfn(vk[key])
//hook when property redefines
let actualProp=vk[key]
Object.defineProperty(vk,key, {
get:() => actualProp,
set:(value) => {
actualProp=value
hookfn(actualProp)
return true
},
configurable:true,
enumerable:true
})
})
}
//remove properties from vk.pe hook
createAndPerformVkPropHook("pe",pe => {
console.log("patch pe")
Object.keys(pe)
.filter(key => VkPeProperties.isValidProperty(key))
.forEach(key => delete window.vk.pe[key])
})
//patch vk.AudioAdsConfig hook
createAndPerformVkPropHook("audioAdsConfig",audioAdsConfig => {
console.log("patch audioAdsConfig")
Object.defineProperties(audioAdsConfig, {
enabled: {
value:false
},
day_limit_reached: {
value:false
},
sections: {
value:[]
}
})
})
//disable error monitor DSN hook
createAndPerformVkPropHook("cfg",cfg => {
console.log("disable error monitoring DSN")
Object.defineProperty(cfg.error_monitoring_config,"dsn", {
value:"http://127.0.0.1"
})
})
//patch vk.adParams hook
createAndPerformVkPropHook("adParams",adParams => {
console.log("patch adParams")
Object.defineProperties(adParams, {
ads_can_show: {
value:0
},
leftads: {
value:""
},
wsTransport: {
value:"http://127.0.0.1"
},
ads_rotate_interval: {
vallue:Number.MAX_SAFE_INTEGER
}
})
})
//trigger vk and properties hooks
window.vk=window.vk
setInterval(() => {
//replace "away.php" url to the redirect url
document.querySelectorAll("a[href*='away.php']")
.forEach(a => {
const url=URL.parse(a.href)
if(!url.pathname.endsWith("away.php"))return
//find a search parameter with valid redirect url
url.searchParams.forEach((value) => {
if(URL.canParse(value))
{
a.href=value
return
}
})
})
//remove _ads_block_data_w blocks
document.querySelectorAll("div._ads_block_data_w")
.forEach(div => {
console.log(`Remove block with id ${div.id}]`)
div.remove()
})
//remove ads_left block
const adsLeft=document.getElementById("ads_left")
if(adsLeft)
{
console.log("Remove block with id: ads_left")
adsLeft.remove()
}
//clear all AdsLight functions
if(window.AdsLight)
Object.keys(window.AdsLight)
.filter(key => typeof window.AdsLight[key]==="function")
.forEach(key => Object.defineProperty(window.AdsLight,key, {
value:() => {}
}))
//patch window ads properties
Object.defineProperties(window, {
noAds: {
value:true,
configurable:true
},
noAdsAtAll: {
value:true,
configurable:true
},
no_left_ads: {
value:true,
configurable:true
},
no_ads: {
value:true,
configurable:true
},
isNoAdsForce: {
value:true,
configurable:true
},
hide_ad: {
value:true,
configurable:true
},
ya_direct: {
value:false,
configurable:true
},
yaDIrectAdActive: {
value:false,
configurable:true
},
__adsSet: {
value:() => {},
configurable:true
},
__adsUpdate: {
value:() => {},
configurable:true
},
AdmanHTML: {
value:false,
configurable:true
},
audioAdsConfig: {
value:false,
configurable:true
},
__adsGetAjaxParams: {
value:() => {},
configurable:true
},
__adsLoader: {
value:() => {},
configurable:true
},
})
},30000/navigator.hardwareConcurrency)
})();