-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmp-480192.user.js
4120 lines (3912 loc) · 221 KB
/
tmp-480192.user.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name YouTube视频&音乐&儿童广告拦截
// @name:zh-CN YouTube视频&音乐&儿童广告拦截
// @name:zh-TW YouTube視頻&音樂&兒童廣告攔截
// @name:zh-HK YouTube視頻&音樂&兒童廣告攔截
// @name:en YouTubeVideo&music&kidsAdBlocking
// @namespace http://tampermonkey.net/
// @version 1.4.6.010
// @description 拦截所有youtube视频广告,音乐播放广告,儿童视频广告,不留白,不闪屏,无感,体验第一。已适配移动端,支持自定义拦截,添加影视频道
// @description:zh-CN 拦截所有youtube视频广告,音乐播放广告,儿童視頻廣告,不留白,不闪屏,无感,体验第一。已适配移动端,支持自定义拦截,添加影视频道
// @description:zh-TW 攔截所有YouTube視頻廣告,音樂播放廣告,兒童視頻廣告,不留白,不閃屏,無感,體驗第一。已適配移動端,支持自定義攔截,添加影視頻道
// @description:zh-HK 攔截所有YouTube視頻廣告,音樂播放廣告,兒童視頻廣告,不留白,不閃屏,無感,體驗第一。已適配移動端,支持自定義攔截,添加影視頻道
// @description:en Intercept all YouTube video ads, music playback ads, youtube kids ads, without leaving blank space, no flash screens, seamless experience, the first choice in user experience. Adapted for mobile devices, supports customizable interception, and allows the addition of video channels
// @author hua
// @match https://www.youtube.com/*
// @match https://m.youtube.com/*
// @match https://music.youtube.com/*
// @match https://www.youtubekids.com/*
// @exclude /^https?://\w+\.youtube\.com\/live_chat.*$/
// @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
// @connect https://update.greasyfork.org/
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_info
// @grant GM_addValueChangeListener
// @grant GM_removeValueChangeListener
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @run-at document-start
// @license MIT
// ==/UserScript==
(function () {
const preventDuplicationKey = "injected_xxxxxxx";
if (unsafeWindow[preventDuplicationKey]) {
console.log('重复注入!');
return;
}
unsafeWindow[preventDuplicationKey] = true;
const open_config_keyword = '2333';
const display_error_keyword = '2444';
let channel_id = GM_getValue('last_channel_id', 'default');
const user_data_listener = get_user_data_listener();
const user_data_api = get_user_data_api();
const user_data = user_data_api.get();
let open_recommend_tv_goodselect = 'off';
let open_recommend_featured = 'on';
let tmp_debugger_value;
let limit_eval = false;
let is_account_init;
const inject_info = {
"ytInitialPlayerResponse": false,
"ytInitialData": false,
"ytInitialReelWatchSequenceResponse": false,
"xhr": false,
"fetch": false
};
const origin_console = console;
const script_url = 'https://update.greasyfork.org/scripts/480192/youtube%E5%B9%BF%E5%91%8A%E6%8B%A6%E6%88%AA.user.js';
let href = location.href;
/** @type {RULE[]} */
let ytInitialPlayerResponse_rule;
/** @type {RULE[]} */
let ytInitialData_rule;
/** @type {RULE[]} */
let ytInitialReelWatchSequenceResponse_rule;
let open_debugger = true;
let isinint = false;
let mobile_web;
let movie_channel_info;
let mobile_movie_channel_info;
let flag_info;
let debugger_ytInitialPlayerResponse;
let debugger_ytInitialData;
let debugger_ytInitialReelWatchSequenceResponse;
const error_messages = [];
const data_process = get_data_process();
let shorts_fun = get_shorts_fun();
let yt_api = get_yt_api();
const shorts_parse_delay = 500;
const browser_info = getBrowserInfo();
let page_type = get_page_type();
const SPLIT_TAG = '###';
let langProblemLogged = false;
url_observer();
init();
function init() {
log('初始化开始!' + href, 0);
set_debugger();
is_account_init = false;
if (page_type === 'yt_shorts') shorts_fun.check_shorts_exist();
data_process.set_obj_filter(obj_process_filter);
limit_eval = data_process.limit_eval;
config_init(user_data.language);
const init_hook = init_hook_collection();
init_hook.property();
init_hook.other();
init_hook.request();
document.addEventListener('DOMContentLoaded', function () {
set_search_listen();
checke_update();
});
isinint = true;
log('初始化结束!' + href, 0);
}
function init_hook_collection() {
return {
property() {
let ytInitialPlayerResponse_value = unsafeWindow['ytInitialPlayerResponse'];
function process_property(name, value, rule) {
const start_time = Date.now();
if (typeof value === 'object') {
open_debugger && (eval(`debugger_${name} = JSON.parse(JSON.stringify(value))`));
rule && data_process.obj_process(value, rule, true);
}
if (typeof value === 'string') {
value = data_process.text_process(value, rule, 'insert', true);
}
log(`${name} 时间:`, Date.now() - start_time, 'spend_time');
return value;
}
define_property_hook(unsafeWindow, 'ytInitialPlayerResponse', {
get: function () {
return ytInitialPlayerResponse_value;
},
set: function (value) {
try {
inject_info.ytInitialPlayerResponse = true;
// if (value && open_debugger) debugger_ytInitialPlayerResponse = (typeof (value) === 'string') ? JSON.parse(value) : JSON.parse(JSON.stringify(value));
value && (value = process_property('ytInitialPlayerResponse', value, ytInitialPlayerResponse_rule));
} catch (e) { console.warn(e) }
ytInitialPlayerResponse_value = value;
},
configurable: false
});
let ytInitialReelWatchSequenceResponse_value = unsafeWindow['ytInitialReelWatchSequenceResponse'];
define_property_hook(unsafeWindow, 'ytInitialReelWatchSequenceResponse', {
get: function () {
return ytInitialReelWatchSequenceResponse_value;
},
set: function (value) {
try {
inject_info.ytInitialReelWatchSequenceResponse = true;
if (page_type.endsWith('_shorts')) {
// if (value && open_debugger) debugger_ytInitialReelWatchSequenceResponse = (typeof (value) === 'string') ? JSON.parse(value) : JSON.parse(JSON.stringify(value));
value && (value = process_property('ytInitialReelWatchSequenceResponse', value, ytInitialReelWatchSequenceResponse_rule));
}
} catch (e) { console.warn(e) }
ytInitialReelWatchSequenceResponse_value = value;
},
configurable: false
});
let ytInitialData_value = unsafeWindow['ytInitialData'];
define_property_hook(unsafeWindow, 'ytInitialData', {
get: function () {
return ytInitialData_value;
},
set: function (value) {
try {
inject_info.ytInitialData = true;
if (typeof (value) === 'string') {
ytInitialData_value = value;
return;
}
// if (open_debugger && value !== undefined && value !== null) debugger_ytInitialData = JSON.parse(JSON.stringify(value));
if (ytInitialData_rule) {
value && (value = process_property('ytInitialData', value, ytInitialData_rule));
}
} catch (e) { console.warn(e) }
ytInitialData_value = value;
},
configurable: false
});
const origin_ua = navigator.userAgent;
define_property_hook(navigator, 'userAgent', {
get: function () {
return (browser_info.isMobile || browser_info.name === 'Chrome') ? origin_ua : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36';
}
});
if (unsafeWindow.ytcfg) {
if (unsafeWindow.ytcfg.data_ && typeof (unsafeWindow.ytcfg.data_.LOGGED_IN) === 'boolean') {
account_data_init(unsafeWindow.ytcfg.data_.LOGGED_IN === true);
} else {
if (unsafeWindow.ytcfg.data_ && typeof unsafeWindow.ytcfg.data_ === 'object') {
define_property_hook(unsafeWindow.ytcfg.data_, 'LOGGED_IN', {
get: function () {
return this.LOGGED_IN_;
},
set: function (value) {
try {
this.LOGGED_IN_ = value;
account_data_init(value === true);
} catch (e) { console.warn(e); }
}
});
}
}
if (!unsafeWindow.ytcfg.data_) {
if (unsafeWindow.yt && unsafeWindow.yt.config_) {
const config_ = unsafeWindow.yt.config_;
if (typeof (config_.LOGGED_IN) === 'boolean') {
account_data_init(config_.LOGGED_IN === true);
}
config_.HL && config_init(config_.HL);
}
}
if (unsafeWindow.ytcfg.data_ && unsafeWindow.ytcfg.data_.HL) config_init(unsafeWindow.ytcfg.data_.HL);
if (!(unsafeWindow.ytcfg.data_ && unsafeWindow.ytcfg.data_.HL)) {
unsafeWindow.ytcfg._msgs = unsafeWindow.ytcfg.msgs;
define_property_hook(unsafeWindow.ytcfg, 'msgs', {
get: function () {
return this._msgs;
},
set: function (newValue) {
try {
if (newValue && newValue.__lang__) config_init(newValue.__lang__);
} catch (e) { console.warn(e); }
this._msgs = newValue;
}
});
unsafeWindow.ytcfg.msgs = unsafeWindow.ytcfg._msgs;
}
} else {
define_property_hook(unsafeWindow, 'ytcfg', {
get: function () {
return this._ytcfg;
},
set: function (newValue) {
try {
if (newValue.set) {
const origin_set = newValue.set;
newValue.set = function () {
origin_set.apply(this, arguments);
if (arguments[0] && typeof arguments[0].LOGGED_IN === 'boolean') {
account_data_init(arguments[0].LOGGED_IN === true);
}
if (arguments[0].HL) {
config_init(arguments[0].HL);
}
};
}
} catch (e) { console.warn(e); }
this._ytcfg = newValue;
}
});
}
},
other() {
let origin_createElement = document.createElement;
document.createElement = function () {
let node = origin_createElement.apply(this, arguments);
if (arguments[0] === 'template') {
let innerhtml_getter = Object.getOwnPropertyDescriptor(Element.prototype, "innerHTML").get;
let innerhtml_setter = Object.getOwnPropertyDescriptor(Element.prototype, "innerHTML").set;
define_property_hook(node, 'innerHTML', {
get: function () {
return innerhtml_getter.call(node);
},
set: function (value) {
// if (value.toString().includes('ytd-continuation-item-renderer')){
// if (href.includes('https://www.youtube.com/watch')){
// value = ''
// log(value);
// log('弹窗去掉------->ytd-continuation-item-renderer');
// }
try {
if (value.toString().includes('yt-mealbar-promo-renderer')) {
log('弹窗去掉------->yt-mealbar-promo-renderer', 'node_process');
value = '';
}
} catch (e) { console.warn(e) }
innerhtml_setter.call(node, value);
}
});
}
// if (arguments[0] === 'IFRAME') {
// const contentWindow_getter = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "contentWindow").get;
// define_property_hook(node, 'contentWindow', {
// get: function () {
// const contentWindow = contentWindow_getter.call(node);
// if (!contentWindow || this.src !== 'about:blank' || contentWindow.change_history) return contentWindow;
// set_history_hook(contentWindow);
// contentWindow.change_history = true;
// return contentWindow;
// }
// });
// }
return node;
};
document.createElement.toString = origin_createElement.toString.bind(origin_createElement);
},
request() {
/**
*
* @param {*} name
* @param {*} response
* @param {RULE[]} rule
* @returns
*/
async function deal_response(name, response, rule) {
if (!rule) return response;
try {
let is_deal = false;
const responseClone = response.clone();
let result = await responseClone.text();
let origin_result = result;
if (name === 'subscribe' || name === 'unsubscribe') {
let match_list = result.match(/channelId":\"([^"]*)"/);
const match_channel_id = match_list && match_list.length > 1 ? match_list[1] : '';
let channel_infos = user_data.channel_infos;
if (match_channel_id) {
if (name === 'unsubscribe') {
let index = channel_infos.ids.indexOf(match_channel_id);
if (index > -1) {
channel_infos.ids.splice(index, 1);
channel_infos.names.splice(index, 1);
}
} else {
channel_infos.ids.push(match_channel_id);
channel_infos.names.push('');
}
user_data.channel_infos = channel_infos;
user_data_api.set();
log(name, match_channel_id, 0);
}
is_deal = true;
}
if (name === 'playlist') {
try {
const obj = JSON.parse(result);
data_process.obj_process(obj.playerResponse, ytInitialPlayerResponse_rule, true);
data_process.obj_process(obj.response, ytInitialData_rule, true);
result = JSON.stringify(obj);
is_deal = true;
} catch (error) {
log('playlist 解析失败', error, -1);
}
}
if (!is_deal) {
let start_time = Date.now();
result = data_process.text_process(result, rule, 'insert', true);
log(name + ' 时间:', Date.now() - start_time, 'spend_time');
}
if (!result) {
result = origin_result;
debugger;
}
return new Response(result, response);
} catch (e) {
console.warn(e);
}
return response;
}
const origin_fetch = unsafeWindow.fetch;
if (origin_fetch.toString() !== 'function fetch() { [native code] }') {
log('fetch have been modified', -1);
}
unsafeWindow.fetch = function () {
const fetch_ = async function (uri, options) {
async function fetch_request(response) {
const url = response.url;
inject_info.fetch = true;
// return_response = response;
if (url.includes('youtubei/v1/next')) {
if (!page_type.endsWith('_watch')) return response;
return (await deal_response('next', response, ytInitialData_rule)) || response;
}
if (url.includes('youtubei/v1/player')) {
if (!page_type.endsWith('_home') && !page_type.endsWith('_watch')) return response;
return (await deal_response('player', response, ytInitialPlayerResponse_rule)) || response;
}
if (url.includes('youtubei/v1/reel/reel_watch_sequence')) {
// shorts 内容列表
if (!page_type.endsWith('_shorts')) return response;
return (await deal_response('reel_watch_sequence', response, ytInitialReelWatchSequenceResponse_rule)) || response;
}
if (url.includes('youtubei/v1/reel/reel_item_watch')) {
// shorts 内容
if (!page_type.endsWith('_shorts')) return response;
return (await deal_response('reel_item_watch', response, ytInitialData_rule)) || response;
}
if (url.includes('youtubei/v1/browse')) {
// if (!['yt_home', 'mobile_yt_home'].includes(page_type)) return response;
let rule = ytInitialData_rule;
if (page_type.endsWith('_home') && ['off', 'subscribed'].includes(user_data.open_recommend_liveroom)) {
let node, category_text;
if (mobile_web) {
node = document.querySelector('#filter-chip-bar > div > ytm-chip-cloud-chip-renderer.selected');
category_text = node && node.textContent;
} else {
node = document.querySelector('#chips > yt-chip-cloud-chip-renderer.style-scope.ytd-feed-filter-chip-bar-renderer.iron-selected');
category_text = node && node.querySelector('#text').textContent;
}
const filter_list = [flag_info.category_game, flag_info.category_live, flag_info.category_news];
if (filter_list.includes(category_text)) {
let body;
if (uri.body_) {
try {
body = JSON.parse(uri.body_);
} catch (error) {
}
}
if (!body || body.browseId !== 'FEwhat_to_watch') {
rule = ytInitialData_rule.filter(item => !item.includes(flag_info.live));
}
}
}
return (await deal_response('browse', response, rule)) || response;
}
// if (url.startsWith('https://www.youtube.com/playlist?list=')) {
// if (['yt_watch_playlist'].includes(page_type)) return response;
// return await deal_response('playlist', response, []);
// }
if (url.includes('https://m.youtube.com/youtubei/v1/guide')) {
// if (!['mobile_yt_home'].includes(page_type)) return response;
return (await deal_response('guide', response, ytInitialData_rule)) || response;
}
if (url.includes('/youtubei/v1/search')) {
// if (!['yt_search', 'mobile_yt_search'].includes(page_type)) return response;
return (await deal_response('search', response, ytInitialData_rule)) || response;
}
if (url.includes('/unsubscribe?prettyPrint=false')) {
return (await deal_response('unsubscribe', response)) || response;
}
if (url.includes('/subscribe?prettyPrint=false')) {
return (await deal_response('subscribe', response)) || response;
}
return response;
}
// if (['yt_music_channel'].includes(page_type) && uri.url_.startsWith('/playlist?list')) {
// return null;
// }
return origin_fetch(uri, options).then(fetch_request);
};
const names = Object.getOwnPropertyNames(origin_fetch);
for (let i = 0; i < names.length; i++) {
if (names[i] in fetch_)
continue;
let desc = Object.getOwnPropertyDescriptor(origin_fetch, names[i]);
define_property_hook(fetch_, names[i], desc);
}
return fetch_;
}();
const origin_Request = unsafeWindow.Request;
if (origin_Request.toString() !== 'function Request() { [native code] }') {
log('Request have been modified', -1);
}
unsafeWindow.Request = class extends unsafeWindow.Request {
constructor(input, options = void 0) {
super(input, options);
if (options && 'body' in options) this['body_'] = options['body'];
}
};
const textToObject = (txt)=>{
let obj = null;
if(typeof txt ==='string'){
try {
obj = JSON.parse(txt);
} catch (error) {
log('JSON解析失败', 1);
}
}else if (typeof txt === 'object'){
obj = txt;
}
return obj;
}
unsafeWindow.XMLHttpRequest = class extends unsafeWindow.XMLHttpRequest {
open(method, url, ...opts) {
inject_info.xhr = true;
// if (['mobile_yt_watch'].includes(page_type) && url.includes('m.youtube.com/watch?v')) {
// return null;
// }
// if (['mobile_yt_home'].includes(page_type) && url.includes('m.youtube.com/?pbj')) {
// return null;
// }
return super.open(method, url, ...opts);
}
processResult(result) {
try {
const xhr = this;
const resURL = xhr.responseURL || '';
if (resURL.includes('youtubei/v1/player')) {
// music_watch
if (typeof result === 'string') {
// if (!['yt_music_watch', 'mobile_yt_watch'].includes(page_type)) return result;
// if (result_type !== 'string') throw new Error('response is not string');
result = data_process.text_process(result, ytInitialPlayerResponse_rule, 'insert', true);
}
} else if (resURL.includes('youtube.com/playlist')) {
const obj = textToObject(result);
log(`出现 ${resURL} !`, obj, 0);
if (obj && obj.length >= 4) {
data_process.obj_process(obj[2].playerResponse, ytInitialPlayerResponse_rule, true);
data_process.obj_process(obj[3].response, ytInitialData_rule, true);
tmp_debugger_value = obj;
if (typeof result === 'string') result = JSON.stringify(obj);
else if (typeof result === 'object') result = obj;
}
}
} catch (error) {
log(`XHR ${url} 解析失败!`, error, -1);
}
return result;
}
get responseText() {
let result = super.responseText;
if (super.readyState === XMLHttpRequest.DONE) {
result = this.processResult(result);
}
return result;
}
get response() {
let result = super.response;
if (super.readyState === XMLHttpRequest.DONE) {
result = this.processResult(result);
}
return result;
}
};
}
}
}
function get_user_data_listener() {
return {
cur_channel_id: null,
listener_id: null,
set: function () {
// TODO
}
};
}
async function account_data_init(login) { // to be reviewed
if (login) {
if (is_account_init) return;
is_account_init = true;
yt_api.get_channel_id();
yt_api.get_subscribe_data();
}
// to be reviewed
// if (channel_id !== 'default') {
// channel_id = 'default';
// user_data.login = false;
// user_data = user_data_api.get();
// }
}
function define_property_hook(obj, property, descriptor) {
try {
Object.defineProperty(obj, property, descriptor);
if (descriptor.get) {
const get_ = Object.getOwnPropertyDescriptor(obj, property).get;
if (descriptor.get !== get_) {
log("hook " + property + " failed!", -1);
return;
}
}
if (descriptor.set) {
const set_ = Object.getOwnPropertyDescriptor(obj, property).set;
if (descriptor.set !== set_)
log("hook " + property + " failed!", -1);
}
} catch (error) {
log(`define ${property} hook error!`, error, -1);
return;
}
}
function config_init(tmp_language = null) {
if (!tmp_language) {
tmp_language = unsafeWindow['ytcfg'].msgs ? unsafeWindow['ytcfg'].msgs.__lang__ : (unsafeWindow['ytcfg'].data ? unsafeWindow['ytcfg'].data.HL : undefined);
!tmp_language && (tmp_language = unsafeWindow['yt'] && unsafeWindow['yt'].config_ && unsafeWindow['yt'].config_.HL);
if (!tmp_language) {
log('语言获取错误', unsafeWindow, -1);
tmp_language = 'zh-CN';
}
}
if (!['zh-CN', 'zh-TW', 'zh-HK', 'en'].includes(tmp_language)) {
!langProblemLogged && log(`Does not support language ${tmp_language}, only supports zh-CN, zh-TW, zh-HK, en, and is compatible with English locations; there may be some errors.`, -1);
langProblemLogged = true;
tmp_language = tmp_language.startsWith('en-') ? 'en' : 'zh-CN';
}
let flag_infos = {
"zh-CN": {
"sponsored": "赞助商广告",
"free_movie": "免费(含广告)",
"live": "直播",
"movie_channel": "影视",
"free_primetime_movie": "免费 Primetime 电影",
"Playables": "游戏大本营",
"think_video": "你对这个视频有何看法?|此推荐内容怎么样?",
"try": "试用",
"recommend_popular": "时下流行",
"featured": "Featured",
"category_live": "直播",
"category_game": "游戏",
"category_news": "新闻",
"btn_recommend_movie": "电影推荐",
"btn_recommend_shorts": "Shorts推荐",
"btn_recommend_liveroom": "直播推荐",
"btn_recommend_popular": "时下流行",
"btn_recommend_game": "游戏大本营推荐",
"btn_save": "保存",
"goodselect": "精选",
"music_ad_flag": "无广告打扰",
"upcoming": "即将开始",
"init": "初始化",
"ctoc": "已复制到剪贴板",
"runing_normally": "运行正常",
"err_msg": "错误信息",
"success": "成功",
"failed": "失败",
"tips": "你可以发送错误信息或者截图发给脚本开发者",
"exists_error": "存在错误信息(建议多次刷新观察是否是同样的错误信息)",
"inject": "注入",
"btn_lable_open": "开启",
"btn_lable_close": "关闭",
"btn_lable_subscribed": "仅订阅",
"recommend_subscribed_lable_tips": "只显示已订阅的推荐",
"title_add_shorts_upload_date": "Shorts添加更新时间",
"title_shorts_change_author_name": "Shorts用户名改频道名",
},
"zh-TW": {
"sponsored": "贊助商廣告",
"free_movie": "免費 \\(含廣告\\)",
"live": "直播",
"movie_channel": "電影與電視節目",
"Playables": "遊戲角落",
"free_primetime_movie": "免費的特選電影",
"think_video": "你對這部影片有什麼看法?|此推荐内容怎么样?",
"try": "試用",
"recommend_popular": "發燒影片",
"featured": "Featured",
"category_live": "直播中",
"category_game": "遊戲",
"category_news": "新聞",
"btn_recommend_movie": "电影推薦",
"btn_recommend_shorts": "Shorts推薦",
"btn_recommend_liveroom": "直播推薦",
"btn_recommend_popular": "發燒影片",
"btn_recommend_game": "遊戲角落推薦",
"btn_save": "保存",
"goodselect": "精選內容",
"music_ad_flag": "零廣告",
"upcoming": "即将直播",
"init": "初始化",
"ctoc": "已複製到剪貼板",
"runing_normally": "運行正常",
"err_msg": "錯誤訊息",
"success": "成功",
"failed": "失敗",
"tips": "你可以发送錯誤訊息或截圖給腳本開發者",
"exists_error": "存在錯誤訊息(建議多次刷新觀察是否是同樣的錯誤訊息)",
"inject": "注入",
"btn_lable_open": "開啓",
"btn_lable_close": "關閉",
"btn_lable_subscribed": "僅訂閱",
"recommend_subscribed_lable_tips": "只顯示已訂閱的推薦",
"title_add_shorts_upload_date": "Shorts添加更新時間",
"title_shorts_change_author_name": "Shorts用戶名稱改頻道名",
},
"zh-HK": {
"sponsored": "赞助",
"free_movie": "免費 \\(有廣告\\)",
"live": "直播",
"movie_channel": "電影與電視節目",
"Playables": "Playables",
"free_primetime_movie": "黃金時段電影",
"think_video": "你對此影片有何意見?|此推荐内容怎么样?",
"try": "試用",
"recommend_popular": "熱爆影片",
"featured": "Featured",
"category_live": "直播",
"category_game": "遊戲",
"category_news": "新聞",
"btn_recommend_movie": "电影推薦",
"btn_recommend_shorts": "Shorts推薦",
"btn_recommend_liveroom": "直播推薦",
"btn_recommend_popular": "熱爆影片",
"btn_recommend_game": "Playables推荐",
"btn_save": "保存",
"goodselect": "精選內容",
"music_ad_flag": "零廣告音樂",
"upcoming": "即將發佈",
"init": "初始化",
"ctoc": "已複製到剪貼板",
"runing_normally": "運行正常",
"err_msg": "錯誤訊息",
"success": "成功",
"failed": "失敗",
"tips": "你可以发送錯誤訊息或截圖給腳本開發者",
"exists_error": "存在錯誤訊息(建議多次刷新觀察是否是同樣的錯誤訊息)",
"inject": "注入",
"btn_lable_open": "開啓",
"btn_lable_close": "關閉",
"btn_lable_subscribed": "僅訂閱",
"recommend_subscribed_lable_tips": "只顯示已訂閱的推薦",
"title_add_shorts_upload_date": "Shorts添加更新時間",
"title_shorts_change_author_name": "Shorts用戶名稱改頻道名",
},
"en": {
"sponsored": "Sponsored",
"free_movie": "Free with ads",
"live": "LIVE",
"movie_channel": "Movies & TV",
"Playables": "Playables",
"free_primetime_movie": "Free Primetime movies",
"think_video": "What did you think of this video?|此推荐内容怎么样?",
"try": "Try",
"recommend_popular": "Trending",
"featured": "Featured",
"category_live": "Live",
"category_game": "Gaming",
"category_news": "News",
"btn_recommend_movie": "MovieRecommend",
"btn_recommend_shorts": "ShortsRecommend",
"btn_recommend_liveroom": "LiveRecommend",
"btn_recommend_popular": "TrendingRecommend",
"btn_recommend_game": "PlayablesRecommend",
"btn_save": "Save",
"goodselect": "Featured",
"music_ad_flag": "ad-free",
"upcoming": "UPCOMING",
"init": "init",
"ctoc": "Copied to clipboard",
"runing_normally": "running normally",
"err_msg": "error message",
"success": "success",
"failed": "failed",
"tips": "You can send error message or screenshot to the developer",
"exists_error": "Error message exists (It is recommended to refresh multiple times to see if it is the same error message)",
"inject": "inject",
"btn_lable_open": "on",
"btn_lable_close": "off",
"btn_lable_subscribed": "onlySubscribed",
"recommend_subscribed_lable_tips": "only show subscribed recommend",
"title_add_shorts_upload_date": "ShortsAddUploadTime",
"title_shorts_change_author_name": "ShortsChangeToChannelName",
}
};
if (tmp_language !== user_data.language) {
user_data.language = tmp_language;
user_data_api.set();
}
flag_info = flag_infos[user_data.language];
movie_channel_info = {
"guideEntryRenderer": {
"navigationEndpoint": {
"clickTrackingParams": "CBQQnOQDGAIiEwj5l8SLqPiCAxUXSEwIHbf1Dw0=",
"commandMetadata": {
"webCommandMetadata": {
"url": "/feed/storefront",
"webPageType": "WEB_PAGE_TYPE_BROWSE",
"rootVe": 6827,
"apiUrl": "/youtubei/v1/browse"
}
},
"browseEndpoint": {
"browseId": "FEstorefront"
}
},
"icon": {
"iconType": "CLAPPERBOARD"
},
"trackingParams": "CBQQnOQDGAIiEwj5l8SLqPiCAxUXSEwIHbf1Dw0=",
"formattedTitle": {
"simpleText": flag_info.movie_channel
},
"accessibility": {
"accessibilityData": {
"label": flag_info.movie_channel
}
}
}
};
unsafeWindow.movie_channel_info = movie_channel_info;
mobile_movie_channel_info = {
"navigationItemViewModel": {
"text": {
"content": flag_info.movie_channel
},
"icon": {
"sources": [
{
"clientResource": {
"imageName": "CLAPPERBOARD"
}
}
]
},
"onTap": {
"parallelCommand": {
"commands": [
{
"innertubeCommand": {
"clickTrackingParams": "CBQQnOQDGAIiEwj5l8SLqPiCAxUXSEwIHbf1Dw0=",
"hideMoreDrawerCommand": {}
}
},
{
"innertubeCommand": {
"clickTrackingParams": "CBQQnOQDGAIiEwj5l8SLqPiCAxUXSEwIHbf1Dw0=",
"commandMetadata": {
"webCommandMetadata": {
"url": "/feed/storefront",
"webPageType": "WEB_PAGE_TYPE_CHANNEL",
"rootVe": 3611,
"apiUrl": "/youtubei/v1/browse"
}
},
"browseEndpoint": {
"browseId": "FEstorefront"
}
}
}
]
}
},
"loggingDirectives": {
"trackingParams": "CBQQnOQDGAIiEwj5l8SLqPiCAxUXSEwIHbf1Dw0=",
"visibility": {
"types": "12"
},
"enableDisplayloggerExperiment": true
}
}
};
unsafeWindow.mobile_movie_channel_info = mobile_movie_channel_info;
ytInitialData_rule = null;
ytInitialReelWatchSequenceResponse_rule = null;
ytInitialPlayerResponse_rule = null;
mobile_web = page_type.startsWith('mobile');
const common_ytInitialData_rule = [
'tvfilmOfferModuleRenderer=- /.masthead$exist',
'merchandiseShelfRenderer=-',
'adSlotRenderer.=-',
];
const common_ytInitialPlayerResponse_rule = [
"abs:playerAds=-",
"abs:adPlacements=-",
"abs:adBreakHeartbeatParams=-",
"abs:adSlots=-",
"abs:streamingData.serverAbrStreamingUrl=- $exist"
];
if (page_type === 'yt_search') {
ytInitialPlayerResponse_rule = common_ytInitialPlayerResponse_rule;
ytInitialData_rule = common_ytInitialData_rule;
return;
}
if (page_type === 'yt_watch_playlist') {
ytInitialData_rule = common_ytInitialData_rule;
ytInitialPlayerResponse_rule = common_ytInitialPlayerResponse_rule;
return;
}
if (page_type === 'mobile_yt_search') {
ytInitialData_rule = common_ytInitialData_rule;
return;
}
if (page_type === 'yt_kids_watch') {
ytInitialData_rule = common_ytInitialData_rule;
return;
}
if (page_type === 'yt_music_watch') {
ytInitialPlayerResponse_rule = common_ytInitialPlayerResponse_rule;
ytInitialData_rule = common_ytInitialData_rule;
return;
}
// if (page_type.includes('yt_shorts')) {
// ytInitialReelWatchSequenceResponse_rule = ['abs:entries[*]=- /.command.reelWatchEndpoint.adClientParams$exist'];
// return;
// }
if (page_type.includes('yt_shorts')) {
ytInitialReelWatchSequenceResponse_rule = ['abs:entries[*]=- /.command.reelWatchEndpoint.adClientParams$exist'];
const tmp_ytInitialData_rule = [];
// 添加时间 // 改频道名
if (user_data.add_shorts_upload_date === 'on' || user_data.shorts_change_author_name === 'on') {
let dec_path = 'overlay.reelPlayerOverlayRenderer.reelPlayerHeaderSupportedRenderers.reelPlayerHeaderRenderer.channelTitleText.runs[0].text';
let name_base_path = 'json_obj.engagementPanels[1].engagementPanelSectionListRenderer.content.structuredDescriptionContentRenderer.items[0].videoDescriptionHeaderRenderer.channel.';
let time_tag_path;
let name_tag_path;
if (mobile_web) {
user_data.add_shorts_upload_date === 'on' && (time_tag_path = '....timestampText.runs[0].text');
user_data.shorts_change_author_name === 'on' && (name_tag_path = name_base_path + 'runs[0].text');
} else {
user_data.add_shorts_upload_date === 'on' && (time_tag_path = '....timestampText.simpleText');
user_data.shorts_change_author_name === 'on' && (name_tag_path = name_base_path + 'simpleText');
}
// to be reviewed
// const abs_path = `${name_tag_path}` || `json_obj.${dec_path}`;
// const time_tag_rule = `${time_tag_path ? ('\n{pathObj(' + time_tag_path + ')\}') : ''}`;
// let rule = `abs:${dec_path}={absObj(${abs_path})}${time_tag_rule}`;
// tmp_ytInitialData_rule.push(rule);
}
// 超级感谢
!mobile_web && tmp_ytInitialData_rule.push('abs:overlay.reelPlayerOverlayRenderer.suggestedAction=- /.shortsSuggestedActionRenderer.text.runs[0].text=购买超级感谢');
tmp_ytInitialData_rule.length && (ytInitialData_rule = tmp_ytInitialData_rule);
return;
}
if (page_type.includes('yt_watch')) {
const watch_page_ytInitialData_rule = common_ytInitialData_rule;
let lower_left_corner_tags;
let lower_left_corner_rule = mobile_web ? 'metadataBadgeRenderer.label.....=- ~=' : 'metadataBadgeRenderer.label.....=- ~=';
lower_left_corner_tags = [];
//赞助商广告
lower_left_corner_tags.push(flag_info.sponsored);
//免费电影
user_data.open_recommend_movie === 'off' && lower_left_corner_tags.push(flag_info.free_movie);
lower_left_corner_rule += lower_left_corner_tags.join('|');
watch_page_ytInitialData_rule.push(lower_left_corner_rule);
let live_rules;
//直播规则
if (['off', 'subscribed'].includes(user_data.open_recommend_liveroom)) {
live_rules = ['text.accessibility.accessibilityData.label........=- =' + flag_info.live];
!mobile_web && live_rules.push('metadataBadgeRenderer.label.....=- =' + flag_info.live);
}
live_rules && watch_page_ytInitialData_rule.push(...live_rules);
// 大标题栏目 短视频等
let recommend_rules = [];
let recommend_tags = [];
let recommend_base_rule = mobile_web ? 'reelShelfRenderer.title.runs[0].text........=- ~=' : 'reelShelfRenderer.title.runs[0].text.....=- ~=';
['off', 'subscribed'].includes(user_data.open_recommend_shorts) && recommend_tags.push('Shorts');
if (recommend_tags.length > 0) {
recommend_rules.push(recommend_base_rule + recommend_tags.join('|'));
}
recommend_rules.length && watch_page_ytInitialData_rule.push(...recommend_rules);
// 添加已订阅短视频
let subscribed_shorts_rule;
if (user_data.open_recommend_shorts === 'subscribed') {
subscribed_shorts_rule = 'secondaryResults.results[1].itemSectionRenderer.contents=+(arr_insert,method(shorts_fun.get_shorts_section()),0) @user_data.shorts_list.length$value>0';
}
subscribed_shorts_rule && watch_page_ytInitialData_rule.push(subscribed_shorts_rule);
// 视频下方可能会出现的推荐栏目
!mobile_web && watch_page_ytInitialData_rule.push("metadataRowContainer=-");
ytInitialData_rule = watch_page_ytInitialData_rule;
ytInitialPlayerResponse_rule = common_ytInitialPlayerResponse_rule;
return;
}
if (page_type.includes('yt_home')) {
let home_page_ytInitialData_ad_rule = [
'richItemRenderer.content.adSlotRenderer..=-'
];
// 每一个item左下角标签
let left_corner_tags;
let lower_left_corner_rule = mobile_web ? 'metadataBadgeRenderer.label.....=- ~=' : 'metadataBadgeRenderer.label......=- ~=';
left_corner_tags = [];