-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1072 lines (973 loc) · 41.3 KB
/
index.html
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
<!DOCTYPE html>
<html lang="ru">
<head>
<title>UserScripts - Пользовательские скрипты</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="shower/themes/ribbon/styles/styles.css">
<link rel="stylesheet" href="./highlight/styles/default.css">
<script src="./highlight/highlight.pack.js"></script>
<style>
.shower {
--slide-ratio: calc(16 / 9);
}
.slide code {
font-family: monospace;
font-size: 0.8em;
line-height: 1.1em;
display: block;
white-space: pre;
padding: 1em 1em;
}
.slide .code .hljs-comment {
color: var(--color-grey);
}
.slide .code .code_meta_name {
color: var(--color-blue);
}
.text-icon {
height: 1em;
margin: -.4em .1em -.1em 0;
vertical-align: middle;
display: inline-block;
}
.slide, .overflow_hidden {
overflow: hidden;
}
.round {
border-radius: 100%;
}
.qr img {
border: 5px solid #000;
border-radius: 25px;
}
.slide .shout {
font-size: 56px;
}
.img-wrap {
max-height: 250px;
overflow: hidden;
position: relative;
}
.img-wrap:before {
position: absolute;
content: '';
display: block;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
box-shadow: inset 0 -345px 25px -300px #ffffff;
}
.img-wrap.top:before {
box-shadow: inset 0 345px 25px -300px #ffffff;
}
.img-wrap.vertical:before {
box-shadow: inset 0 345px 25px -300px #ffffff, inset 0 -345px 25px -300px #ffffff;
}
.img-wrap.top-right:before {
box-shadow: inset 345px -345px 20px -300px #ffffff;
}
.img-wrap.outer-shadow div {
box-shadow: 1px 2px 5px 0px rgba(0,0,0,0.2);
}
.img-wrap.no-shadow:before {
box-shadow: none;
}
.img-wrap.height {
max-height: 100%;
}
.img-wrap.radius {
border-radius: 3px;
overflow: hidden;
}
.img-wrap.radius div {
border-radius: 3px;
overflow: hidden;
}
.img-wrap img {
max-width: 100%;
}
.img-wrap.move-top {
margin-top: -1em;
}
#mutation_observer > p {
line-height: 1.5em;
}
.splitImageView .img-wrap {
width: 50%;
max-height: 350px;
float: left;
}
.avatar {
float: left;
margin-right: 2em;
}
.slide::after {
z-index: 2;
}
.slide p.bottom-note {
margin: 24px 0px;
line-height: 1.4em;
color: var(--color-grey);
}
.slide blockquote {
line-height: 1.5em;
font-size: 0.9em;
}
</style>
<script>
window.addEventListener('load', function onLoad() {
document.body.querySelectorAll('code').forEach(function onMatch(el) {
el.innerHTML = el.innerHTML.replace(/^\s{12}/mg, '').trim()
});
document.querySelectorAll('.code').forEach(function (block) {
block.classList.add('javascript');
hljs.highlightBlock(block);
});
document.querySelectorAll('.hljs-comment').forEach(function (block) {
block.innerHTML = block.innerHTML.replace(/(\/\/ )(@[\w\d-]+)/, "$1<span class='code_meta_name'>$2</span>")
});
});
</script>
</head>
<body class="shower list">
<header class="caption" id="Header">
<h1>UserScripts - Пользовательские скрипты</h1>
<p>Зачем нужны, чем могут помочь и где они обитают</p>
</header>
<section class="slide" id="Hello">
<div style="text-align: center; margin-top: 150px; font-size: 23px;">
<h2 style="font-size: 56px">UserScripts - Пользовательские скрипты</h2>
<p>Зачем нужны, чем могут помочь и где они обитают</p>
<p style="position: absolute; bottom: 36px; right: 36px; text-align: right;">@flyink (Котляров Евгений)</p>
</div>
</section>
<section class="slide" id="AboutMe">
<div class="overflow_hidden">
<h2 class="double_line">
<img src="./pictures/icons/me.jpg" class="text-icon" alt="" style="border-radius: 50px"/>
Котляров Евгений
</h2>
<ul class="size_32">
<li class="next">
Разработчик <span class="blue">ВКонтакте</span>
<img src="./pictures/icons/vk.png" class="text-icon" alt=""/>
</li>
<li class="next">
Отвечаю за платформу ботов
<img src="./pictures/emoji/robot.png" class="text-icon" alt=""/>
</li>
<li class="next">
Делаю расширения,
<span class="next">сервисы, </span>
<span class="next">ботов</span>
<span class="next">
и пользовательские скипты
<img src="./pictures/emoji/sparkles.png" class="text-icon" alt=""/>
</span>
</li>
</ul>
</div>
</section>
<section class="slide" id="AboutUserScript">
<h2>
<img src="./pictures/emoji/female-teacher.png" class="text-icon" alt=""/>
Что такое UserScript?
</h2>
<figure>
<blockquote class="next">Код, который хранится у пользователя и выполняет заданные действия.</blockquote>
</figure>
</section>
<section class="slide" id="my_scripts">
<h2 class="shout">
<img src="./pictures/emoji/thinking-face.png" class="text-icon" alt=""/>
Зачем нужны?
</h2>
</section>
<section class="slide" id="my_api">
<h2>
Автоматизация шаблонных действий
</h2>
<div class="img-wrap" style="max-height: 375px; margin: auto;">
<img src="pictures/api.png" alt=""/>
</div>
</section>
<section class="slide" id="view">
<h2>
Парсинг и улучшение просмотра
</h2>
<div class="img-wrap radius" style="max-height: 375px; margin: auto;">
<img src="pictures/logs.png" alt="" style="max-width: initial; width: 1500px;"/>
</div>
</section>
<section class="slide" id="filter">
<h2>
Упрощение и ускорение работы
</h2>
<div class="img-wrap top" style="max-height: 375px; margin: auto; overflow: hidden">
<img src="pictures/fast-help.png" alt="" style="margin-top: -250px;"/>
</div>
</section>
<section class="slide" id="lool">
<h2>
Сложный для реализации функционал
</h2>
<div class="img-wrap" style="max-height: 375px; margin: auto;">
<img src="pictures/im-filter.png" alt=""/>
</div>
</section>
<section class="slide" id="WhatCan">
<h2>
<img src="./pictures/emoji/face-with-monocle.png" class="text-icon" alt=""/>
Что умеют?
</h2>
<ol>
<li class="next">Выполнять JavaScript</li>
<li class="next">Вызывать API расширения</li>
<li class="next">Делать всякие гадости с вашим сайтом</li>
</ol>
<div class="img-wrap next">
<img src="pictures/vk-ok.png" alt=""/>
</div>
</section>
<section class="slide" id="WhereDoTheyWork">
<h2 class="shout">Где работают пользовательские скрипты?</h2>
</section>
<section class="slide" id="Greasemonkey">
<h2>
<img src="./pictures/icons/Greasemonkey.png" class="text-icon" alt=""/>
Greasemonkey
</h2>
<ol>
<li><a href="https://greasespot.net" target="_blank">greasespot.net</a></li>
<li>Дата выхода: 28 марта 2005 года (до Появления Chrome)</li>
</ol>
<blockquote style="margin-top: 50px;">
Проект Greasemonkey написан Aaron Boodman в 28 ноябре 2004 года, который был вдохновлен Firefox расширением, которое очищало интерфейс сайта AllMusic. К маю 2005 года для Greasemonkey было создано около 60 общих и 115 специфичных для сайта пользовательских скриптов.
</blockquote>
</section>
<section class="slide" id="ChromeUserScripts">
<h2>
<img src="./pictures/icons/google-chrome.png" class="text-icon" alt=""/>
Google Chrome
</h2>
<p>С февраля 2009 года в Google Chrome появилась встроенная поддержка пользовательских скриптов в формате Greasemonkey, но позже установка пользовательских скриптов с посторонних доменов была отключена.</p>
<div class="img-wrap" style="max-height: 250px;">
<img src="pictures/chrome-us.png" alt="chome block userscript"/>
</div>
</section>
<section class="slide" id="Tampermonkey">
<h2>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
Tampermonkey
</h2>
<ol>
<li><a href="https://tampermonkey.net" target="_blank">tampermonkey.net</a></li>
<li>Доступен на Chrome, Microsoft Edge, Safari, Opera и Firefox.</li>
</ol>
<blockquote style="margin-top: 50px;">
Tampermonkey был написан Jan Biniok в мае 2010 года из Greasemonkey, который уже был встроен в Chrome, но не имел полной совместимости.
</blockquote>
</section>
<section class="slide" id="ViolentMonkey">
<h2>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
Violentmonkey
</h2>
<ol>
<li><a href="https://violentmonkey.github.io/" target="_blank">violentmonkey.github.io</a></li>
<li>Менеджер пользовательских скриптов с открытым исходным кодом</li>
</ol>
</section>
<section class="slide" id="UserScriptsForSafari">
<h2>
<img src="./pictures/icons/userscripts.png" class="text-icon" alt=""/>
UserScripts для Safari
</h2>
<ol>
<li><a href="https://github.com/quoid/userscripts" target="_blank">github.com/quoid/userscripts</a></li>
<li>Доступно для Safari на iOS (+ipadOS) и macOS.</li>
<blockquote style="margin-top: 50px;">
An open-source userscript manager for Safari
</blockquote>
</ol>
</section>
<section class="slide" id="exTable">
<h2>
Поддержка
</h2>
<table style="font-size: 0.9em">
<thead>
<tr>
<th> </th>
<th>Android</th>
<th> iOS </th>
<th>Linux</th>
<th> macOS </th>
<th>Windows</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Chrome</strong></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
</td>
<td></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
</tr>
<tr>
<td><strong>Edge</strong></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
</td>
</tr>
<tr>
<td><strong>Firefox</strong></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
<img src="./pictures/icons/Greasemonkey.png" class="text-icon" alt=""/>
</td>
<td></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
<img src="./pictures/icons/Greasemonkey.png" class="text-icon" alt=""/>
</td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
<img src="./pictures/icons/Greasemonkey.png" class="text-icon" alt=""/>
</td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
<img src="./pictures/icons/Greasemonkey.png" class="text-icon" alt=""/>
</td>
</tr>
<tr>
<td><strong>Opera</strong></td>
<td></td>
<td></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
</tr>
<tr>
<td><strong>Safari</strong></td>
<td></td>
<td>
<img src="./pictures/icons/userscripts.png" class="text-icon" alt=""/>
</td>
<td></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/userscripts.png" class="text-icon" alt=""/>
</td>
<td></td>
</tr>
<tr>
<td><strong>Yandex Browser</strong></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
<td></td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
<td>
<img src="./pictures/icons/Tampermonkey_logo.png" class="text-icon" alt=""/>
<img src="./pictures/icons/violentmonkey.png" class="text-icon" alt=""/>
</td>
</tr>
</tbody></table>
<p class="bottom-note">
<a href="https://openuserjs.org/about/Userscript-Beginners-HOWTO" target="_blank">openuserjs.org/about/Userscript-Beginners-HOWTO</a>
</p>
</section>
<section class="slide splitImageView" id="Interface">
<h2>
<img src="./pictures/emoji/detective.png" class="text-icon" alt=""/>
Интерфейс
</h2>
<div style="overflow: hidden; width: 100%; height: 340px;">
<div class="img-wrap top-right radius">
<img src="pictures/greasemonkey.png" alt=""/>
</div>
<div class="img-wrap top-right radius">
<img src="pictures/tampermonkey.png" alt=""/>
</div>
</div>
</section>
<section class="slide" id="CreateTitle">
<h2 class="shout">Создадим новый скрипт?</h2>
</section>
<section class="slide" id="CreateScreen">
<h2>
<img src="./pictures/emoji/pencil.png" class="text-icon" alt=""/>
Интерфейс редактора Tampermonkey
</h2>
<div class="img-wrap" style="max-height: 450px; margin: -30px auto auto auto; overflow: hidden">
<img src="pictures/meta1.png" alt=""/>
</div>
</section>
<section class="slide" id="MetaData">
<h2>
<img src="./pictures/emoji/gear.png" class="text-icon" alt=""/>
Метаданные
</h2>
<code class="code code_comment">
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://vk.com/
// @grant none
// ==/UserScript==
</code>
<p class="bottom-note">
Подробнее о Метаданных пользовательских скриптов:
<a target="_blank" href="https://www.tampermonkey.net/documentation.php">tampermonkey.net/documentation.php</a>
</p>
</section>
<section class="slide" id="MetaName">
<h2>
<img src="./pictures/emoji/label.png" class="text-icon" alt=""/>
Задаем описание скрипта
</h2>
<code class="code code_comment">
// @name Название скрипта
// @namespace http://domain.com/
// name + namespace - формируют id скрипта
// @version 0.1
// @description Описание
// @author Автор
</code>
</section>
<section class="slide" id="EditCode">
<h2 class="shout">Пишем код?</h2>
</section>
<section class="slide" id="TryWriteCodeLog">
<h2>
<img src="./pictures/emoji/pencil.png" class="text-icon" alt=""/>
Пробуем... Обновляем страницу...
</h2>
<code class="code code_comment">
(function() {
'use strict';
console.log('hello', location.pathname);
})();
</code>
</section>
<section class="slide" id="Hello2x">
<h2>
... и видим несколько логов
<img src="./pictures/emoji/flushed-face.png" class="text-icon" alt=""/>
</h2>
<div class="img-wrap move-top" style="max-height: 350px">
<img src="pictures/hello2x.png" alt=""/>
</div>
</section>
<section class="slide" id="Frame">
<h2>
<img src="./pictures/emoji/ghost.png" class="text-icon" alt=""/>
Все дело в iframe
</h2>
<div class="img-wrap move-top" style="max-height: 340px;">
<img src="pictures/frame.png" alt=""/>
</div>
<p class="bottom-note">
PS: Тут в хроме можно переключать контекст
</p>
</section>
<section class="slide" id="meta_include">
<h2>
<img src="./pictures/emoji/label.png" class="text-icon" alt=""/>
Определяем набор страниц
</h2>
<code class="code code_comment">
// Добавить
// @include https://domain.com/*
// Исключить
// @exclude https://domain.com/image/
// Отключить в фреймах
// @noframes
</code>
</section>
<section class="slide" id="Hello1x">
<h2>
Добавляем @noframes и проверяем
</h2>
<div class="img-wrap next move-top" style="max-height: 350px">
<img src="pictures/hello1x.png" alt=""/>
</div>
</section>
<section class="slide" id="TryWriteCodePageFn">
<h2>
<img src="./pictures/emoji/pencil.png" class="text-icon" alt=""/>
Пробуем вызвать функцию сайта...
</h2>
<code class="code code_comment">
(function() {
'use strict';
<span></span>
const onDone = () => { document.body.style = 'green'; };
ajax.post('https://vk.com/foaf.php?id=1', {}, { onDone });
})();
</code>
</section>
<section class="slide" id="ContextFail">
<h2>
А Greasemonkey ее не видит...
</h2>
<div class="img-wrap" style="max-height: 350px">
<img src="pictures/ContextFail.png" alt=""/>
</div>
</section>
<section class="slide" id="ContentScripts">
<h2>
Content Scripts работают в своем контексте
</h2>
<blockquote>
... Полноценный доступ есть только через к DOM дереву страницы.<br>
С контент скрипта вы можете инициировать ивенты, изменять DOM.<br>
<b>Даже можете добавлять script тег в страницу</b> ...<br>
</blockquote>
<div class="img-wrap no-shadow" style="max-height: 450px; margin: 10px auto auto auto; width: 390px; ">
<img src="pictures/content-scripts.png" alt=""/>
</div>
<p class="bottom-note" style="margin-bottom: 0px;">
<a href="https://medium.com/@aleksanderzinewicz/google-chrome-extensions-%D1%87%D0%B0%D1%81%D1%82%D1%8C-1-%D0%B0%D1%80%D1%85%D0%B8%D1%82%D0%B5%D0%BA%D1%82%D1%83%D1%80%D0%B0-fcb0dc0949d4">Aleks Zinevych. Google Chrome Extensions — Часть 1. Архитектура</a>
</p>
</section>
<section class="slide" id="InjectCode">
<h2>
Встраиваем код в страницу
</h2>
<p class="note" style="line-height: 1.4em">
В Greasemonkey можно использовать @grant GM.unsafeWindow.
Tampermonkey сам пробрасывает переменные.
</p>
<code class="code code_comment">
(function injectScript(fn) {
var script = document.createElement('script');
script.textContent = '(' + fn + ')();';
script.id = fn.name;
document.head.appendChild(script);
})(function TryAjax() {
const onDone = () => { document.body.style = 'green'; };
ajax.post('https://vk.com/foaf.php?id=1', {}, { onDone });
});
</code>
</section>
<section class="slide" id="ButtonsQ">
<h2 class="shout">Как работать с динамическим контентом?</h2>
</section>
<section class="slide" id="mutation_observer">
<h2>
<img src="./pictures/emoji/sparkles.png" class="text-icon" alt=""/>
MutationObserver
</h2>
<p class="note">
Помогает отслеживать изменения в дереве элементов
</p>
<code class="code code_comment">
searchGreenElements(document.body);
<span></span>
new MutationObserver(function onMutations(mutations) {
mutations.forEach(function onMutation(mutation) {
searchGreenElements(mutation.target);
});
}).observe(document.body, {
subtree: true,
childList: true,
});
</code>
</section>
<section class="slide" id="addEventListener">
<h2>window.addEventListener + event.target</h2>
<p class="note">Реагируем нужные нам действия</p>
<code class="code code_comment">
window.addEventListener('keydown', function onKeyDown(event) {
if (event.target.classList.contains('support_input')) {
showAndFilterHelpList(event.target);
}
});
</code>
</section>
<section class="slide" id="Proxy">
<h2>Proxy, getter и setter</h2>
<p class="note">Ловим чтение и запись в обьектах</p>
<code class="code code_comment">
Object.defineProperty(store, "adsLists", {
set: function() {
// хе-хе
return [];
},
get: function() {
return [];
}
});
</code>
</section>
<section class="slide" id="functionReplace">
<h2>
<img src="./pictures/emoji/flying-saucer.png" class="text-icon" alt=""/>
Оборачиваем функций
</h2>
<p class="note">Заменяем аргументы и результаты функций</p>
<code class="code code_comment">
ajax.post = (function replaceFunction(ajaxPost) {
return function ajaxPostFake() {
var query = arguments[1];
if (/^хз/i.test(query.msg)) {
query.msg = 'Не знаю';
}
return ajaxPost.apply(this, arguments);
}
})(ajax.post);
</code>
</section>
<section class="slide" id="ApiQ">
<h2 class="shout">А можно вызывать API расширений?</h2>
</section>
<section class="slide" id="MetaGrant">
<h2>
Расширения предоставляют свое API
<img src="./pictures/emoji/wrench.png" class="text-icon" alt=""/>
</h2>
<p class="note">
С помощью @grant вы перечисляете все функции, которые хотите вызвать
</p>
<code class="code code_comment">
// Получение метаданных скрипта:
// @grant GM.info
// Аналог localStorage в контексте расширения:
// @grant GM.deleteValue/getValue/setValue/listValues
// Вывод уведомлений:
// @grant GM.notification
// Открытие новой вкладки:
// @grant GM.openInTab
// Копирование в буффер обмена
// @grant GM.setClipboard
</code>
</section>
<section class="slide" id="meta_resource">
<h2>@grant GM.getResourceUrl</h2>
<p class="note">
Запрос ресурсов с другого сайта. Возвращает Data URL.
</p>
<code class="code code_comment">
// ...
// @resource logo ../icons/laptop.png
// @grant GM.getResourceUrl
<span></span>
(async () => {
let img = document.createElement("img");
img.src = await GM.getResourceUrl("logo");
document.body.appendChild(img);
})();
</code>
</section>
<section class="slide" id="meta_resource_xhr">
<h2>@grant GM.xmlHttpRequest</h2>
<p class="note">
Позволяет делать запросы к другом сайтам
</p>
<code class="code code_comment">
// ...
// @connect api.vk.com
// @grant GM.xmlHttpRequest
<span></span>
GM.xmlHttpRequest({
method: "GET",
url: "http://api.vk.com/method/users.get",
onload: ({ response }) => {
console.log(response);
}
});
</code>
</section>
<section class="slide" id="meta_resource_xhr_access">
<h2>Tampermonkey запрещает лишние запросы</h2>
<div class="img-wrap vertical" style="max-height: 350px; margin: auto;max-width: 90%;">
<img src="pictures/xhr-access-1.png" alt="" style="margin-top: -60px;"/>
</div>
</section>
<section class="slide" id="ExButtonsQ">
<h2 class="shout">Могу ли я добавить элементы в меню расширения?</h2>
</section>
<section class="slide" id="MenuEx">
<h2>
В меню можно добавить команды
</h2>
<div class="img-wrap" style="max-height: 400px">
<img src="./pictures/MenuEx.png" alt=""/>
</div>
</section>
<section class="slide" id="GM_registerMenuCommand">
<h2>
@grant GM_registerMenuCommand
</h2>
<code class="code">
// ==UserScript==
// @name MenuExample
// @include https://vk.com/*
// @grant GM_registerMenuCommand
// ==/UserScript==
<span></span>
GM_registerMenuCommand('doSomeMagic', function() {
alert('doSomeMagic');
}, 'r');
</code>
</section>
<section class="slide" id="ContextMenuQ">
<h2 class="shout">А работать с контекстным меню?</h2>
</section>
<section class="slide" id="ContextMenuExample">
<h2>
Можно в контекстное меню *
</h2>
<div class="img-wrap vertical" style="max-height: 330px">
<img src="./pictures/ContextEx.png" alt="" style="margin-top: -50px"/>
</div>
<p>* - но только в Google Chrome</p>
</section>
<section class="slide" id="ContextMenuCode">
<h2>
@run-at context-menu
</h2>
<code class="code">
// ==UserScript==
// @name onContextMenu > doSomeMagic
// @author FlyInk13
// @include https://vk.com/*
// @run-at context-menu
// ==/UserScript==
<span></span>
(function onContextMenu() {
alert('doSomeMagic');
})();
</code>
</section>
<section class="slide" id="run_at_types">
<h2>@run-at</h2>
<ul>
<li><b>document-start</b> - До запуска любых сценариев</li>
<li><b>document-body</b> - После появлениея body</li>
<li><b>document-end</b> - После загрузки страницы</li>
<li><b>document-idle</b> - После запуска сценариев страницы</li>
<li><b>context-menu</b> - При вызове контекстного меню [Только для Chrome]</li>
</ul>
</section>
<section class="slide" id="Save">
<h2 class="shout">Куда можно сохранить скрипт?</h2>
</section>
<section class="slide" id="storage">
<h2>
<img src="./pictures/emoji/anchor.png" class="text-icon" alt=""/>
Места обитания
</h2>
<ol>
<li><a href="https://openuserjs.org/" target="_blank">OpenUserJS</a></li>
<li><a href="https://gist.github.com/" target="_blank">gist.github.com</a></li>
<li><a href="https://www.tampermonkey.net/scripts.php" target="_blank">Альтернативы UserScripts.org</a></li>
<li>На своем сайте с «*.user.js» в конце ссылки</li>
</ol>
</section>
<section class="slide" id="Update">
<h2 class="shout">А обновлять?</h2>
</section>
<section class="slide" id="UpdateMeta">
<h2>
Для этого можно указать @updateURL
</h2>
<code class="code">
// @updateURL https://openuserjs.org/....js
</code>
<div class="img-wrap" style="max-height: 350px; overflow: hidden; z-index: -2;">
<img src="pictures/update.png" alt=""/>
</div>
</section>
<section class="slide" id="MoreUserScripts">
<h2 class="shout">А есть ли жизнь без расширений?</h2>
</section>
<section class="slide" id="Bookmarklets">
<h2>
<img src="./pictures/emoji/white-medium-star.png" class="text-icon" alt=""/>
Букмарклеты
</h2>
<p class="note">
Закладки, в адресе которых прописан JavaScript код, выполняемый при их открытии
</p>
<div class="img-wrap move-top" style="max-height: 300px;">
<img src="pictures/favlets.png" alt=""/>
</div>
</section>
<section class="slide" id="MoreUserScripts2">
<h2 class="shout">И не только в браузерах...</h2>
</section>
<section class="slide splitImageView" id="iOS">
<h2>
<img src="./pictures/icons/shortcuts.png" class="text-icon" alt=""/>
Shortcut для iOS
</h2>
<div style="width: 80%; height: 400px; overflow: hidden; margin: auto">
<div class="img-wrap radius no-shadow outer-shadow height" style="overflow: visible;">
<div style="width: 300px; height: 330px; overflow: hidden;">
<img src="pictures/ios/cmd-view.jpg" alt=""/>
</div>
</div>
<div class="img-wrap radius no-shadow outer-shadow height" style="overflow: visible;">
<div style="width: 300px; height: 330px; overflow: hidden;">
<img src="pictures/ios/cmd-run.jpg" alt="" style="margin-top: -50px;"/>
</div>
</div>
</div>
</section>
<section class="slide" id="Automator_AppleScript">
<h2>
<img src="./pictures/icons/automator.png" class="text-icon" alt=""/>
Automator в Mac OS
</h2>
<div class="img-wrap no-shadow" style="max-height: 330px; margin-top: -20px; overflow: visible;">
<img src="pictures/Automator.png" height="350" alt="" style="margin: auto; display: block"/>
</div>
<p class="bottom-note">
<span style="float: right">AppleScript, JavaScript & Shell</span>
</p>
</section>
<section class="slide" id="Automator_TouchBar">
<h2>
Кнопки в Touch Bar
</h2>
<div class="img-wrap radius vertical" style="max-height: 400px;">
<img src="pictures/TouchBar.png" alt="" style="margin-top: -100px;"/>
</div>
</section>
<section class="slide splitImageView" id="JetBrains-LivePlugin">
<h2>
<img src="./pictures/icons/PhpStorm.png" class="text-icon" alt=""/>
JetBrains LivePlugin
</h2>
<p class="note">
Когда компилировать и публиковать официальные плагины сложно
</p>
<div style="width: 80%; height: 200px; overflow: hidden; margin: auto; margin-top: -20px">
<div class="img-wrap radius no-shadow outer-shadow height" style="overflow: visible;">
<div style="width: 300px; height: 255px; overflow: hidden;">
<img src="pictures/liveplugin.png" alt=""/>
</div>
</div>
<div class="img-wrap radius no-shadow outer-shadow height" style="overflow: visible;">
<div style="width: 300px; height: 255px; overflow: hidden;">
<img src="pictures/liveplugin2.png" alt="" />
</div>
</div>
</div>
<p class="bottom-note">
<a target="_blank" href=" https://plugins.jetbrains.com/plugin/7282-liveplugin">LivePlugin</a>
<span style="float: right">Kotlin & Groovy</span>
</p>
</section>