forked from bgrins/devtools-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1037 lines (871 loc) · 218 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="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>DevTools Snippets</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="devtools-snippets is a collection of helpful JavaScript code snippets to use inside of browser devtools.">
<meta name="author" content="Brian Grinstead, devtools-snippets contributors">
<link href="docs/styles.css" rel="stylesheet">
</head>
<body>
<div class="wrapper">
<div class="header">
<h1>DevTools Snippets</h1>
<h2>A collection of helpful snippets to use inside of browser devtools</h2>
<a id="project-link" href="https://github.com/bgrins/devtools-snippets">View Or Contribute On Github</a>
</div>
<div class="content">
<div class="alert">
<p>
<strong>Instructions:</strong> The snippets can be used in any browser console. Chrome provides a '<a href="https://github.com/bgrins/devtools-snippets#to-enable-devtools-snippets-in-chrome">snippets</a>' feature that can be used to manage the scripts, while Firefox has a '<a href="https://developer.mozilla.org/en-US/docs/Tools/Scratchpad">scratchpad</a>' feature that lets you run, edit, and save chunks of JavaScript.
</p>
<p>
View the <a href="https://github.com/bgrins/devtools-snippets">devtools-snippets project page</a>. For more information about using them in your favorite browser, check out the <a href="https://github.com/bgrins/devtools-snippets/blob/master/README.md">README</a>. Here is an <a href="http://www.briangrinstead.com/blog/devtools-snippets"> article about snippets</a> detailing why you might use them and additional features that would be nice.
</p>
<p>
<strong>Have a snippet you'd like to share with the world?</strong> Contributing is easy, there is a <a href="https://github.com/bgrins/devtools-snippets/blob/master/CONTRIBUTING.md">guide explaining more</a>.
</p>
</div>
<div class="links">
<ul>
<li><a href='#allcolors'>allcolors</a></li>
<li><a href='#cachebuster'>cachebuster</a></li>
<li><a href='#console-save'>console-save</a></li>
<li><a href='#cssprettifier'>cssprettifier</a></li>
<li><a href='#cssreload'>cssreload</a></li>
<li><a href='#dataurl'>dataurl</a></li>
<li><a href='#formcontrols'>formcontrols</a></li>
<li><a href='#hashlink'>hashlink</a></li>
<li><a href='#html_i18n_content'>html_i18n_content</a></li>
<li><a href='#insert-css'>insert-css</a></li>
<li><a href='#jquerify'>jquerify</a></li>
<li><a href='#log'>log</a></li>
<li><a href='#log-globals'>log-globals</a></li>
<li><a href='#overlay'>overlay</a></li>
<li><a href='#performance'>performance</a></li>
<li><a href='#plainforms'>plainforms</a></li>
<li><a href='#querystringvalues'>querystringvalues</a></li>
<li><a href='#showheaders'>showheaders</a></li>
<li><a href='#viewcookies'>viewcookies</a></li>
<li><a href='#wrapelement'>wrapelement</a></li>
</ul>
</div>
<hr />
<div class="snippets">
<div class='snippet-wrapper' id='allcolors'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/allcolors/allcolors.js'>allcolors.js</a> <a href='#allcolors'>#</a> <small style='float:right'><a href='snippets/allcolors/allcolors.js'>(view raw)</a></small></h3>
<p>Print out all colors from computed styles used in elements on the page. Uses styled console.log calls to visualize each color.</p>
<p><a href="snippets/allcolors/allcolors.js"><img src="snippets/allcolors/allcolors.png" alt="snippets/allcolors/allcolors" /></a></p>
</div><div class="highlight"><pre><span class="c1">// allcolors.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Print out CSS colors used in elements on the page.</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="c1">// Should include colors from elements that have a border color but have a zero width?</span>
<span class="kd">var</span> <span class="nx">includeBorderColorsWithZeroWidth</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">allColors</span> <span class="o">=</span> <span class="p">{};</span>
<span class="kd">var</span> <span class="nx">props</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"background-color"</span><span class="p">,</span> <span class="s2">"color"</span><span class="p">,</span> <span class="s2">"border-top-color"</span><span class="p">,</span> <span class="s2">"border-right-color"</span><span class="p">,</span> <span class="s2">"border-bottom-color"</span><span class="p">,</span> <span class="s2">"border-left-color"</span><span class="p">];</span>
<span class="kd">var</span> <span class="nx">skipColors</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">"rgb(0, 0, 0)"</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="s2">"rgba(0, 0, 0, 0)"</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="s2">"rgb(255, 255, 255)"</span><span class="o">:</span> <span class="mi">1</span>
<span class="p">};</span>
<span class="p">[].</span><span class="nx">forEach</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s2">"*"</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">nodeColors</span> <span class="o">=</span> <span class="p">{};</span>
<span class="nx">props</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">prop</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">color</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">getComputedStyle</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="kc">null</span><span class="p">).</span><span class="nx">getPropertyValue</span><span class="p">(</span><span class="nx">prop</span><span class="p">),</span>
<span class="nx">thisIsABorderProperty</span> <span class="o">=</span> <span class="p">(</span><span class="nx">prop</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s2">"border"</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">),</span>
<span class="nx">notBorderZero</span> <span class="o">=</span> <span class="nx">thisIsABorderProperty</span> <span class="o">?</span> <span class="nb">window</span><span class="p">.</span><span class="nx">getComputedStyle</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="kc">null</span><span class="p">).</span><span class="nx">getPropertyValue</span><span class="p">(</span><span class="nx">prop</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s2">"color"</span><span class="p">,</span> <span class="s2">"width"</span><span class="p">))</span> <span class="o">!==</span> <span class="s2">"0px"</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="nx">colorConditionsMet</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">includeBorderColorsWithZeroWidth</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">colorConditionsMet</span> <span class="o">=</span> <span class="nx">color</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">skipColors</span><span class="p">[</span><span class="nx">color</span><span class="p">];</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="nx">colorConditionsMet</span> <span class="o">=</span> <span class="nx">color</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">skipColors</span><span class="p">[</span><span class="nx">color</span><span class="p">]</span> <span class="o">&&</span> <span class="nx">notBorderZero</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">colorConditionsMet</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">allColors</span><span class="p">[</span><span class="nx">color</span><span class="p">])</span> <span class="p">{</span>
<span class="nx">allColors</span><span class="p">[</span><span class="nx">color</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
<span class="nx">count</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="nx">nodes</span><span class="o">:</span> <span class="p">[]</span>
<span class="p">};</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">nodeColors</span><span class="p">[</span><span class="nx">color</span><span class="p">])</span> <span class="p">{</span>
<span class="nx">allColors</span><span class="p">[</span><span class="nx">color</span><span class="p">].</span><span class="nx">count</span><span class="o">++</span><span class="p">;</span>
<span class="nx">allColors</span><span class="p">[</span><span class="nx">color</span><span class="p">].</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">nodeColors</span><span class="p">[</span><span class="nx">color</span><span class="p">]</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="kd">function</span> <span class="nx">rgbTextToRgbArray</span><span class="p">(</span><span class="nx">rgbText</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">rgbText</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\s/g</span><span class="p">,</span> <span class="s2">""</span><span class="p">).</span><span class="nx">match</span><span class="p">(</span><span class="sr">/\d+,\d+,\d+/</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">split</span><span class="p">(</span><span class="s2">","</span><span class="p">).</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">num</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">num</span><span class="p">,</span> <span class="mi">10</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">componentToHex</span><span class="p">(</span><span class="nx">c</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">hex</span> <span class="o">=</span> <span class="nx">c</span><span class="p">.</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">hex</span><span class="p">.</span><span class="nx">length</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">?</span> <span class="s2">"0"</span> <span class="o">+</span> <span class="nx">hex</span> <span class="o">:</span> <span class="nx">hex</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">rgbToHex</span><span class="p">(</span><span class="nx">rgbArray</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">r</span> <span class="o">=</span> <span class="nx">rgbArray</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
<span class="nx">g</span> <span class="o">=</span> <span class="nx">rgbArray</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
<span class="nx">b</span> <span class="o">=</span> <span class="nx">rgbArray</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
<span class="k">return</span> <span class="s2">"#"</span> <span class="o">+</span> <span class="nx">componentToHex</span><span class="p">(</span><span class="nx">r</span><span class="p">)</span> <span class="o">+</span> <span class="nx">componentToHex</span><span class="p">(</span><span class="nx">g</span><span class="p">)</span> <span class="o">+</span> <span class="nx">componentToHex</span><span class="p">(</span><span class="nx">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">allColorsSorted</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">allColors</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">rgbArray</span> <span class="o">=</span> <span class="nx">rgbTextToRgbArray</span><span class="p">(</span><span class="nx">i</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">hexValue</span> <span class="o">=</span> <span class="nx">rgbToHex</span><span class="p">(</span><span class="nx">rgbArray</span><span class="p">);</span>
<span class="nx">allColorsSorted</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">key</span><span class="o">:</span> <span class="nx">i</span><span class="p">,</span>
<span class="nx">value</span><span class="o">:</span> <span class="nx">allColors</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span>
<span class="nx">hexValue</span><span class="o">:</span> <span class="nx">hexValue</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="nx">allColorsSorted</span> <span class="o">=</span> <span class="nx">allColorsSorted</span><span class="p">.</span><span class="nx">sort</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">b</span><span class="p">.</span><span class="nx">value</span><span class="p">.</span><span class="nx">count</span> <span class="o">-</span> <span class="nx">a</span><span class="p">.</span><span class="nx">value</span><span class="p">.</span><span class="nx">count</span><span class="p">;</span>
<span class="p">});</span>
<span class="kd">var</span> <span class="nx">nameStyle</span> <span class="o">=</span> <span class="s2">"font-weight:normal;"</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">countStyle</span> <span class="o">=</span> <span class="s2">"font-weight:bold;"</span><span class="p">;</span>
<span class="kd">function</span> <span class="nx">colorStyle</span><span class="p">(</span><span class="nx">color</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="s2">"background:"</span> <span class="o">+</span> <span class="nx">color</span> <span class="o">+</span> <span class="s2">";color:"</span> <span class="o">+</span> <span class="nx">color</span> <span class="o">+</span> <span class="s2">";border:1px solid #333;"</span><span class="p">;</span>
<span class="p">};</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"Total colors used in elements on the page: "</span> <span class="o">+</span> <span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">href</span> <span class="o">+</span> <span class="s2">" are "</span> <span class="o">+</span> <span class="nx">allColorsSorted</span><span class="p">.</span><span class="nx">length</span><span class="p">);</span>
<span class="nx">allColorsSorted</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">c</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupCollapsed</span><span class="p">(</span><span class="s2">"%c %c "</span> <span class="o">+</span> <span class="nx">c</span><span class="p">.</span><span class="nx">key</span> <span class="o">+</span> <span class="s2">" "</span> <span class="o">+</span> <span class="nx">c</span><span class="p">.</span><span class="nx">hexValue</span> <span class="o">+</span> <span class="s2">" %c("</span> <span class="o">+</span> <span class="nx">c</span><span class="p">.</span><span class="nx">value</span><span class="p">.</span><span class="nx">count</span> <span class="o">+</span> <span class="s2">" times)"</span><span class="p">,</span>
<span class="nx">colorStyle</span><span class="p">(</span><span class="nx">c</span><span class="p">.</span><span class="nx">key</span><span class="p">),</span> <span class="nx">nameStyle</span><span class="p">,</span> <span class="nx">countStyle</span><span class="p">);</span>
<span class="nx">c</span><span class="p">.</span><span class="nx">value</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">();</span>
<span class="p">});</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">(</span><span class="s2">"All colors used in elements on the page"</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='cachebuster'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/cachebuster/cachebuster.js'>cachebuster.js</a> <a href='#cachebuster'>#</a> <small style='float:right'><a href='snippets/cachebuster/cachebuster.js'>(view raw)</a></small></h3>
<p>Overwrite all <code>link</code> and (optionally) <code>script</code> tags by adding Date.now() at the end of <code>href</code> and <code>src</code> attributes, respectively. By default processing <code>scripts</code> is not performed, you should change the variable <code>process_scripts</code> to true to run these.</p>
<p><a href="snippets/cachebuster/cachebuster.js"><img src="snippets/cachebuster/cachebuster.png" alt="snippets/cachebuster/cachebuster" /></a></p>
</div><div class="highlight"><pre><span class="c1">//Cache Buster</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">(){</span>
<span class="kd">var</span> <span class="nx">rep</span> <span class="o">=</span> <span class="sr">/.*\?.*/</span><span class="p">,</span>
<span class="nx">links</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s1">'link'</span><span class="p">),</span>
<span class="nx">scripts</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s1">'script'</span><span class="p">),</span>
<span class="nx">process_scripts</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="nx">i</span><span class="o"><</span><span class="nx">links</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span><span class="nx">i</span><span class="o">++</span><span class="p">){</span>
<span class="kd">var</span> <span class="nx">link</span> <span class="o">=</span> <span class="nx">links</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span>
<span class="nx">href</span> <span class="o">=</span> <span class="nx">link</span><span class="p">.</span><span class="nx">href</span><span class="p">;</span>
<span class="k">if</span><span class="p">(</span><span class="nx">rep</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">href</span><span class="p">)){</span>
<span class="nx">link</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span> <span class="nx">href</span><span class="o">+</span><span class="s1">'&'</span><span class="o">+</span><span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">else</span><span class="p">{</span>
<span class="nx">link</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span> <span class="nx">href</span><span class="o">+</span><span class="s1">'?'</span><span class="o">+</span><span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span><span class="p">(</span><span class="nx">process_scripts</span><span class="p">){</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="nx">i</span><span class="o"><</span><span class="nx">scripts</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span><span class="nx">i</span><span class="o">++</span><span class="p">){</span>
<span class="kd">var</span> <span class="nx">script</span> <span class="o">=</span> <span class="nx">scripts</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span>
<span class="nx">src</span> <span class="o">=</span> <span class="nx">script</span><span class="p">.</span><span class="nx">src</span><span class="p">;</span>
<span class="k">if</span><span class="p">(</span><span class="nx">rep</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">src</span><span class="p">)){</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="nx">src</span><span class="o">+</span><span class="s1">'&'</span><span class="o">+</span><span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">else</span><span class="p">{</span>
<span class="nx">script</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="nx">src</span><span class="o">+</span><span class="s1">'?'</span><span class="o">+</span><span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='console-save'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/console-save/console-save.js'>console-save.js</a> <a href='#console-save'>#</a> <small style='float:right'><a href='snippets/console-save/console-save.js'>(view raw)</a></small></h3>
<p>A simple way to save objects as .json files from the console, includes a chrome extension along with a plain script.</p>
<h4 id="usage">Usage</h4>
<p><code>console.save(data, [filename])</code></p>
<p>Data can be a string or just an object, objects are passed through <code>json.stringify()</code> before writing to file. Filename is optional, defaults to ‘console.json’.</p>
<h4 id="licence">Licence</h4>
<p>MIT</p>
<p><a href="snippets/console-save/console-save.js"><img src="snippets/console-save/console-save.png" alt="console.save" /></a></p>
</div><div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">console</span><span class="p">){</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">save</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">filename</span><span class="p">){</span>
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="s1">'Console.save: No data'</span><span class="p">)</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">filename</span><span class="p">)</span> <span class="nx">filename</span> <span class="o">=</span> <span class="s1">'console.json'</span>
<span class="k">if</span><span class="p">(</span><span class="k">typeof</span> <span class="nx">data</span> <span class="o">===</span> <span class="s2">"object"</span><span class="p">){</span>
<span class="nx">data</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="kc">undefined</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">blob</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Blob</span><span class="p">([</span><span class="nx">data</span><span class="p">],</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s1">'text/json'</span><span class="p">}),</span>
<span class="nx">e</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createEvent</span><span class="p">(</span><span class="s1">'MouseEvents'</span><span class="p">),</span>
<span class="nx">a</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">'a'</span><span class="p">)</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">download</span> <span class="o">=</span> <span class="nx">filename</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">URL</span><span class="p">.</span><span class="nx">createObjectURL</span><span class="p">(</span><span class="nx">blob</span><span class="p">)</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">dataset</span><span class="p">.</span><span class="nx">downloadurl</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'text/json'</span><span class="p">,</span> <span class="nx">a</span><span class="p">.</span><span class="nx">download</span><span class="p">,</span> <span class="nx">a</span><span class="p">.</span><span class="nx">href</span><span class="p">].</span><span class="nx">join</span><span class="p">(</span><span class="s1">':'</span><span class="p">)</span>
<span class="nx">e</span><span class="p">.</span><span class="nx">initMouseEvent</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span> <span class="kc">true</span><span class="p">,</span> <span class="kc">false</span><span class="p">,</span> <span class="nb">window</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="kc">false</span><span class="p">,</span> <span class="kc">false</span><span class="p">,</span> <span class="kc">false</span><span class="p">,</span> <span class="kc">false</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="kc">null</span><span class="p">)</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">dispatchEvent</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span>
<span class="p">}</span>
<span class="p">})(</span><span class="nx">console</span><span class="p">)</span>
</pre></div>
</div><div class='snippet-wrapper' id='cssprettifier'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/cssprettifier/cssprettifier.js'>cssprettifier.js</a> <a href='#cssprettifier'>#</a> <small style='float:right'><a href='snippets/cssprettifier/cssprettifier.js'>(view raw)</a></small></h3>
<p>Script for unminifying and prettifying a CSS file written by <a href="http://addyosmani.com">addyosmani</a> and <a href="http://sindresorhus.com">sindresorhus</a>. View the <a href="https://github.com/addyosmani/cssprettifier-bookmarklet">cssprettifier-bookmarklet project on github</a>.</p>
<p><a href="snippets/cssprettifier/cssprettifier.js"><img src="snippets/cssprettifier/cssprettifier.png" alt="snippets/cssprettifier/cssprettifier" /></a></p>
</div><div class="highlight"><pre><span class="c1">// cssprettifier.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Unminify and prettify a CSS file.</span>
<span class="cm">/*</span>
<span class="cm"> * cssprettifier-bookmarklet</span>
<span class="cm"> * Copyright (c) 2013 Addy Osmani, Sindre Sorhus</span>
<span class="cm"> * CSSBeautify (c) Sencha, Ariya Hidayat</span>
<span class="cm"> * Prism (c) Lea Verou</span>
<span class="cm"> * Licensed under the MIT license.</span>
<span class="cm"> */</span>
<span class="cm">/*globals document:true*/</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="s1">'use strict'</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">childNodes</span><span class="p">.</span><span class="nx">length</span> <span class="o">!==</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"CSS Prettify: This page doesn't appear to be a stylesheet. Make sure you run this on a css file"</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// cssbeautify</span>
<span class="p">(</span><span class="kd">function</span><span class="p">(){</span><span class="s2">"use strict"</span><span class="p">;</span><span class="kd">function</span> <span class="nx">a</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="nx">b</span><span class="p">){</span><span class="kd">function</span> <span class="nx">s</span><span class="p">(</span><span class="nx">a</span><span class="p">){</span><span class="k">return</span><span class="s2">" "</span><span class="o">===</span><span class="nx">a</span><span class="o">||</span><span class="s2">"\n"</span><span class="o">===</span><span class="nx">a</span><span class="o">||</span><span class="s2">" "</span><span class="o">===</span><span class="nx">a</span><span class="o">||</span><span class="s2">"\r"</span><span class="o">===</span><span class="nx">a</span><span class="o">||</span><span class="s2">"\f"</span><span class="o">===</span><span class="nx">a</span><span class="p">}</span><span class="kd">function</span> <span class="nx">t</span><span class="p">(</span><span class="nx">a</span><span class="p">){</span><span class="k">return</span><span class="s2">"'"</span><span class="o">===</span><span class="nx">a</span><span class="o">||</span><span class="s1">'"'</span><span class="o">===</span><span class="nx">a</span><span class="p">}</span><span class="kd">function</span> <span class="nx">u</span><span class="p">(</span><span class="nx">a</span><span class="p">){</span><span class="k">return</span> <span class="nx">h</span><span class="o">>=</span><span class="s2">"a"</span><span class="o">&&</span><span class="s2">"z"</span><span class="o">>=</span><span class="nx">h</span><span class="o">||</span><span class="nx">h</span><span class="o">>=</span><span class="s2">"A"</span><span class="o">&&</span><span class="s2">"Z"</span><span class="o">>=</span><span class="nx">h</span><span class="o">||</span><span class="nx">h</span><span class="o">>=</span><span class="s2">"0"</span><span class="o">&&</span><span class="s2">"9"</span><span class="o">>=</span><span class="nx">h</span><span class="o">||</span><span class="s2">"-_*.:#"</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span><span class="o">>=</span><span class="mi">0</span><span class="p">}</span><span class="kd">function</span> <span class="nx">v</span><span class="p">(){</span><span class="kd">var</span> <span class="nx">a</span><span class="p">;</span><span class="k">for</span><span class="p">(</span><span class="nx">a</span><span class="o">=</span><span class="nx">m</span><span class="p">;</span><span class="nx">a</span><span class="o">></span><span class="mi">0</span><span class="p">;</span><span class="nx">a</span><span class="o">-=</span><span class="mi">1</span><span class="p">)</span><span class="nx">g</span><span class="o">+=</span><span class="nx">c</span><span class="p">.</span><span class="nx">indent</span><span class="p">}</span><span class="kd">function</span> <span class="nx">w</span><span class="p">(){</span><span class="nx">g</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="nx">p</span><span class="o">?</span><span class="nx">g</span><span class="o">+=</span><span class="s2">" {"</span><span class="o">:</span><span class="p">(</span><span class="nx">g</span><span class="o">+=</span><span class="s2">"\n"</span><span class="p">,</span><span class="nx">v</span><span class="p">(),</span><span class="nx">g</span><span class="o">+=</span><span class="s2">"{"</span><span class="p">),</span><span class="s2">"\n"</span><span class="o">!==</span><span class="nx">i</span><span class="o">&&</span><span class="p">(</span><span class="nx">g</span><span class="o">+=</span><span class="s2">"\n"</span><span class="p">),</span><span class="nx">m</span><span class="o">+=</span><span class="mi">1</span><span class="p">}</span><span class="kd">function</span> <span class="nx">x</span><span class="p">(){</span><span class="kd">var</span> <span class="nx">a</span><span class="p">;</span><span class="nx">m</span><span class="o">-=</span><span class="mi">1</span><span class="p">,</span><span class="nx">g</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="nx">q</span><span class="o">&&</span><span class="p">(</span><span class="nx">a</span><span class="o">=</span><span class="nx">g</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">),</span><span class="s2">";"</span><span class="o">!==</span><span class="nx">a</span><span class="o">&&</span><span class="s2">"{"</span><span class="o">!==</span><span class="nx">a</span><span class="o">&&</span><span class="p">(</span><span class="nx">g</span><span class="o">+=</span><span class="s2">";"</span><span class="p">)),</span><span class="nx">g</span><span class="o">+=</span><span class="s2">"\n"</span><span class="p">,</span><span class="nx">v</span><span class="p">(),</span><span class="nx">g</span><span class="o">+=</span><span class="s2">"}"</span><span class="p">,</span><span class="nx">f</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="nx">g</span><span class="o">=</span><span class="s2">""</span><span class="p">}</span><span class="kd">var</span> <span class="nx">c</span><span class="p">,</span><span class="nx">f</span><span class="p">,</span><span class="nx">h</span><span class="p">,</span><span class="nx">i</span><span class="p">,</span><span class="nx">j</span><span class="p">,</span><span class="nx">k</span><span class="p">,</span><span class="nx">l</span><span class="p">,</span><span class="nx">m</span><span class="p">,</span><span class="nx">n</span><span class="p">,</span><span class="nx">o</span><span class="p">,</span><span class="nx">r</span><span class="p">,</span><span class="nx">d</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="nx">e</span><span class="o">=</span><span class="nx">a</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span><span class="nx">g</span><span class="o">=</span><span class="s2">""</span><span class="p">,</span><span class="nx">p</span><span class="o">=!</span><span class="mi">0</span><span class="p">,</span><span class="nx">q</span><span class="o">=!</span><span class="mi">1</span><span class="p">;</span><span class="k">for</span><span class="p">(</span><span class="nx">c</span><span class="o">=</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span><span class="o">></span><span class="mi">1</span><span class="o">?</span><span class="nx">b</span><span class="o">:</span><span class="p">{},</span><span class="nx">c</span><span class="p">.</span><span class="nx">indent</span><span class="o">===</span><span class="k">void</span> <span class="mi">0</span><span class="o">&&</span><span class="p">(</span><span class="nx">c</span><span class="p">.</span><span class="nx">indent</span><span class="o">=</span><span class="s2">" "</span><span class="p">),</span><span class="s2">"string"</span><span class="o">==</span><span class="k">typeof</span> <span class="nx">c</span><span class="p">.</span><span class="nx">openbrace</span><span class="o">&&</span><span class="p">(</span><span class="nx">p</span><span class="o">=</span><span class="s2">"end-of-line"</span><span class="o">===</span><span class="nx">c</span><span class="p">.</span><span class="nx">openbrace</span><span class="p">),</span><span class="s2">"boolean"</span><span class="o">==</span><span class="k">typeof</span> <span class="nx">c</span><span class="p">.</span><span class="nx">autosemicolon</span><span class="o">&&</span><span class="p">(</span><span class="nx">q</span><span class="o">=</span><span class="nx">c</span><span class="p">.</span><span class="nx">autosemicolon</span><span class="p">),</span><span class="nx">r</span><span class="o">=</span><span class="nb">String</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">trimRight</span><span class="o">?</span><span class="kd">function</span><span class="p">(</span><span class="nx">a</span><span class="p">){</span><span class="k">return</span> <span class="nx">a</span><span class="p">.</span><span class="nx">trimRight</span><span class="p">()}</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">a</span><span class="p">){</span><span class="k">return</span> <span class="nx">a</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\s+$/</span><span class="p">,</span><span class="s2">""</span><span class="p">)},</span><span class="nx">l</span><span class="o">=</span><span class="p">{</span><span class="nx">Start</span><span class="o">:</span><span class="mi">0</span><span class="p">,</span><span class="nx">AtRule</span><span class="o">:</span><span class="mi">1</span><span class="p">,</span><span class="nx">Block</span><span class="o">:</span><span class="mi">2</span><span class="p">,</span><span class="nx">Selector</span><span class="o">:</span><span class="mi">3</span><span class="p">,</span><span class="nx">Ruleset</span><span class="o">:</span><span class="mi">4</span><span class="p">,</span><span class="nx">Property</span><span class="o">:</span><span class="mi">5</span><span class="p">,</span><span class="nx">Separator</span><span class="o">:</span><span class="mi">6</span><span class="p">,</span><span class="nx">Expression</span><span class="o">:</span><span class="mi">7</span><span class="p">,</span><span class="nx">URL</span><span class="o">:</span><span class="mi">8</span><span class="p">},</span><span class="nx">m</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">,</span><span class="nx">o</span><span class="o">=!</span><span class="mi">1</span><span class="p">,</span><span class="nx">f</span><span class="o">=</span><span class="p">[],</span><span class="nx">a</span><span class="o">=</span><span class="nx">a</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\r\n/g</span><span class="p">,</span><span class="s2">"\n"</span><span class="p">);</span><span class="nx">e</span><span class="o">></span><span class="nx">d</span><span class="p">;)</span><span class="k">if</span><span class="p">(</span><span class="nx">h</span><span class="o">=</span><span class="nx">a</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">d</span><span class="p">),</span><span class="nx">i</span><span class="o">=</span><span class="nx">a</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">d</span><span class="o">+</span><span class="mi">1</span><span class="p">),</span><span class="nx">d</span><span class="o">+=</span><span class="mi">1</span><span class="p">,</span><span class="nx">t</span><span class="p">(</span><span class="nx">n</span><span class="p">))</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">h</span><span class="o">===</span><span class="nx">n</span><span class="o">&&</span><span class="p">(</span><span class="nx">n</span><span class="o">=</span><span class="kc">null</span><span class="p">),</span><span class="s2">"\"</span><span class="o">===</span><span class="nx">h</span><span class="o">&&</span><span class="nx">i</span><span class="o">===</span><span class="nx">n</span><span class="o">&&</span><span class="p">(</span><span class="nx">g</span><span class="o">+=</span><span class="nx">i</span><span class="p">,</span><span class="nx">d</span><span class="o">+=</span><span class="mi">1</span><span class="p">);</span><span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">t</span><span class="p">(</span><span class="nx">h</span><span class="p">))</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">n</span><span class="o">=</span><span class="nx">h</span><span class="p">;</span><span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="s2">"*"</span><span class="o">===</span><span class="nx">h</span><span class="o">&&</span><span class="s2">"/"</span><span class="o">===</span><span class="nx">i</span><span class="o">&&</span><span class="p">(</span><span class="nx">o</span><span class="o">=!</span><span class="mi">1</span><span class="p">,</span><span class="nx">g</span><span class="o">+=</span><span class="nx">i</span><span class="p">,</span><span class="nx">d</span><span class="o">+=</span><span class="mi">1</span><span class="p">);</span><span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="s2">"/"</span><span class="o">!==</span><span class="nx">h</span><span class="o">||</span><span class="s2">"*"</span><span class="o">!==</span><span class="nx">i</span><span class="p">){</span><span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="o">===</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">){</span><span class="k">if</span><span class="p">(</span><span class="mi">0</span><span class="o">===</span><span class="nx">f</span><span class="p">.</span><span class="nx">length</span><span class="o">&&</span><span class="nx">s</span><span class="p">(</span><span class="nx">h</span><span class="p">)</span><span class="o">&&</span><span class="mi">0</span><span class="o">===</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span><span class="k">continue</span><span class="p">;</span><span class="k">if</span><span class="p">(</span><span class="s2">" "</span><span class="o">>=</span><span class="nx">h</span><span class="o">||</span><span class="nx">h</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">>=</span><span class="mi">128</span><span class="p">){</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">,</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="nx">u</span><span class="p">(</span><span class="nx">h</span><span class="p">)</span><span class="o">||</span><span class="s2">"["</span><span class="o">===</span><span class="nx">h</span><span class="o">||</span><span class="s2">"@"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="k">if</span><span class="p">(</span><span class="nx">j</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="mi">0</span><span class="o">===</span><span class="nx">j</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span><span class="nx">f</span><span class="p">.</span><span class="nx">length</span><span class="o">></span><span class="mi">0</span><span class="o">&&</span><span class="p">(</span><span class="nx">g</span><span class="o">=</span><span class="s2">"\n\n"</span><span class="p">);</span><span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="s2">"}"</span><span class="o">===</span><span class="nx">j</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">j</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">||</span><span class="s2">";"</span><span class="o">===</span><span class="nx">j</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">j</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="nx">g</span><span class="o">=</span><span class="nx">j</span><span class="o">+</span><span class="s2">"\n\n"</span><span class="p">;</span><span class="k">else</span> <span class="k">for</span><span class="p">(;;){</span><span class="k">if</span><span class="p">(</span><span class="nx">i</span><span class="o">=</span><span class="nx">g</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">),</span><span class="s2">" "</span><span class="o">!==</span><span class="nx">i</span><span class="o">&&</span><span class="mi">9</span><span class="o">!==</span><span class="nx">i</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span><span class="k">break</span><span class="p">;</span><span class="nx">g</span><span class="o">=</span><span class="nx">g</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">)}</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="s2">"@"</span><span class="o">===</span><span class="nx">h</span><span class="o">?</span><span class="nx">l</span><span class="p">.</span><span class="nx">AtRule</span><span class="o">:</span><span class="nx">l</span><span class="p">.</span><span class="nx">Selector</span><span class="p">;</span><span class="k">continue</span><span class="p">}}</span><span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="o">!==</span><span class="nx">l</span><span class="p">.</span><span class="nx">AtRule</span><span class="p">)</span><span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="o">!==</span><span class="nx">l</span><span class="p">.</span><span class="nx">Block</span><span class="p">)</span><span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="o">!==</span><span class="nx">l</span><span class="p">.</span><span class="nx">Selector</span><span class="p">)</span><span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="o">!==</span><span class="nx">l</span><span class="p">.</span><span class="nx">Ruleset</span><span class="p">)</span><span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="o">!==</span><span class="nx">l</span><span class="p">.</span><span class="nx">Property</span><span class="p">)</span><span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="o">!==</span><span class="nx">l</span><span class="p">.</span><span class="nx">Separator</span><span class="p">)</span><span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="o">!==</span><span class="nx">l</span><span class="p">.</span><span class="nx">Expression</span><span class="p">)</span><span class="nx">k</span><span class="o">===</span><span class="nx">l</span><span class="p">.</span><span class="nx">URL</span><span class="o">&&</span><span class="s2">")"</span><span class="o">===</span><span class="nx">h</span><span class="o">&&</span><span class="nx">g</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="s2">"\"</span><span class="o">!==</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">?</span><span class="p">(</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Expression</span><span class="p">)</span><span class="o">:</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">;</span><span class="k">else</span><span class="p">{</span><span class="k">if</span><span class="p">(</span><span class="s2">"}"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">x</span><span class="p">(),</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">,</span><span class="nx">m</span><span class="o">></span><span class="mi">0</span><span class="o">&&</span><span class="p">(</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Block</span><span class="p">);</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="s2">";"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">g</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="nx">g</span><span class="o">+=</span><span class="s2">";\n"</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Ruleset</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="s2">"("</span><span class="o">===</span><span class="nx">h</span><span class="o">&&</span><span class="s2">"l"</span><span class="o">===</span><span class="nx">g</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">2</span><span class="p">)</span><span class="o">&&</span><span class="s2">"r"</span><span class="o">===</span><span class="nx">g</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">3</span><span class="p">)</span><span class="o">&&</span><span class="s2">"u"</span><span class="o">===</span><span class="nx">g</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">4</span><span class="p">)){</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">URL</span><span class="p">;</span><span class="k">continue</span><span class="p">}}</span><span class="k">else</span><span class="p">{</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">s</span><span class="p">(</span><span class="nx">h</span><span class="p">)){</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Expression</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="nx">t</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span><span class="o">&&</span><span class="p">(</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Expression</span><span class="p">)}</span><span class="k">else</span><span class="p">{</span><span class="k">if</span><span class="p">(</span><span class="s2">":"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">g</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="nx">g</span><span class="o">+=</span><span class="s2">": "</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Expression</span><span class="p">,</span><span class="nx">s</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span><span class="o">&&</span><span class="p">(</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Separator</span><span class="p">);</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="s2">"}"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">x</span><span class="p">(),</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">,</span><span class="nx">m</span><span class="o">></span><span class="mi">0</span><span class="o">&&</span><span class="p">(</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Block</span><span class="p">);</span><span class="k">continue</span><span class="p">}</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">}</span><span class="k">else</span><span class="p">{</span><span class="k">if</span><span class="p">(</span><span class="s2">"}"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">x</span><span class="p">(),</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">,</span><span class="nx">m</span><span class="o">></span><span class="mi">0</span><span class="o">&&</span><span class="p">(</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Block</span><span class="p">);</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="s2">"\n"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">g</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="nx">g</span><span class="o">+=</span><span class="s2">"\n"</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">s</span><span class="p">(</span><span class="nx">h</span><span class="p">)){</span><span class="nx">g</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="nx">g</span><span class="o">+=</span><span class="s2">"\n"</span><span class="p">,</span><span class="nx">v</span><span class="p">(),</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Property</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">}</span><span class="k">else</span><span class="p">{</span><span class="k">if</span><span class="p">(</span><span class="s2">"{"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">w</span><span class="p">(),</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Ruleset</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="s2">"}"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">x</span><span class="p">(),</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">}</span><span class="k">else</span><span class="p">{</span><span class="k">if</span><span class="p">(</span><span class="nx">u</span><span class="p">(</span><span class="nx">h</span><span class="p">)){</span><span class="k">if</span><span class="p">(</span><span class="nx">j</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="mi">0</span><span class="o">===</span><span class="nx">j</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span><span class="nx">f</span><span class="p">.</span><span class="nx">length</span><span class="o">></span><span class="mi">0</span><span class="o">&&</span><span class="p">(</span><span class="nx">g</span><span class="o">=</span><span class="s2">"\n\n"</span><span class="p">);</span><span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="s2">"}"</span><span class="o">===</span><span class="nx">j</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">j</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="nx">g</span><span class="o">=</span><span class="nx">j</span><span class="o">+</span><span class="s2">"\n\n"</span><span class="p">;</span><span class="k">else</span> <span class="k">for</span><span class="p">(;;){</span><span class="k">if</span><span class="p">(</span><span class="nx">i</span><span class="o">=</span><span class="nx">g</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">),</span><span class="s2">" "</span><span class="o">!==</span><span class="nx">i</span><span class="o">&&</span><span class="mi">9</span><span class="o">!==</span><span class="nx">i</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span><span class="k">break</span><span class="p">;</span><span class="nx">g</span><span class="o">=</span><span class="nx">g</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nx">g</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">)}</span><span class="nx">v</span><span class="p">(),</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Selector</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="s2">"}"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">x</span><span class="p">(),</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">}</span><span class="k">else</span><span class="p">{</span><span class="k">if</span><span class="p">(</span><span class="s2">";"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">k</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">Start</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="k">if</span><span class="p">(</span><span class="s2">"{"</span><span class="o">===</span><span class="nx">h</span><span class="p">){</span><span class="nx">j</span><span class="o">=</span><span class="nx">r</span><span class="p">(</span><span class="nx">g</span><span class="p">),</span><span class="nx">w</span><span class="p">(),</span><span class="nx">k</span><span class="o">=</span><span class="s2">"@font-face"</span><span class="o">===</span><span class="nx">j</span><span class="o">?</span><span class="nx">l</span><span class="p">.</span><span class="nx">Ruleset</span><span class="o">:</span><span class="nx">l</span><span class="p">.</span><span class="nx">Block</span><span class="p">;</span><span class="k">continue</span><span class="p">}</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">}}</span><span class="k">else</span> <span class="nx">o</span><span class="o">=!</span><span class="mi">0</span><span class="p">,</span><span class="nx">g</span><span class="o">+=</span><span class="nx">h</span><span class="p">,</span><span class="nx">g</span><span class="o">+=</span><span class="nx">i</span><span class="p">,</span><span class="nx">d</span><span class="o">+=</span><span class="mi">1</span><span class="p">;</span><span class="k">return</span> <span class="nx">g</span><span class="o">=</span><span class="nx">f</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s2">""</span><span class="p">)</span><span class="o">+</span><span class="nx">g</span><span class="p">}</span><span class="s2">"undefined"</span><span class="o">!=</span><span class="k">typeof</span> <span class="nx">exports</span><span class="o">?</span><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span><span class="o">=</span><span class="nx">exports</span><span class="o">=</span><span class="nx">a</span><span class="o">:</span><span class="s2">"object"</span><span class="o">==</span><span class="k">typeof</span> <span class="nb">window</span><span class="o">&&</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">cssbeautify</span><span class="o">=</span><span class="nx">a</span><span class="p">)})();</span>
<span class="c1">// prism</span>
<span class="p">(</span><span class="kd">function</span><span class="p">(){</span><span class="kd">var</span> <span class="nx">e</span><span class="o">=</span><span class="sr">/\blang(?:uage)?-(?!\*)(\w+)\b/i</span><span class="p">,</span><span class="nx">t</span><span class="o">=</span><span class="nx">self</span><span class="p">.</span><span class="nx">Prism</span><span class="o">=</span><span class="p">{</span><span class="nx">util</span><span class="o">:</span><span class="p">{</span><span class="nx">type</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span><span class="k">return</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">toString</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">e</span><span class="p">).</span><span class="nx">match</span><span class="p">(</span><span class="sr">/\[object (\w+)\]/</span><span class="p">)[</span><span class="mi">1</span><span class="p">]},</span><span class="nx">clone</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span><span class="kd">var</span> <span class="nx">n</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">util</span><span class="p">.</span><span class="nx">type</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span><span class="k">switch</span><span class="p">(</span><span class="nx">n</span><span class="p">){</span><span class="k">case</span><span class="s2">"Object"</span><span class="o">:</span><span class="kd">var</span> <span class="nx">r</span><span class="o">=</span><span class="p">{};</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">e</span><span class="p">)</span><span class="nx">e</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span><span class="o">&&</span><span class="p">(</span><span class="nx">r</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">util</span><span class="p">.</span><span class="nx">clone</span><span class="p">(</span><span class="nx">e</span><span class="p">[</span><span class="nx">i</span><span class="p">]));</span><span class="k">return</span> <span class="nx">r</span><span class="p">;</span><span class="k">case</span><span class="s2">"Array"</span><span class="o">:</span><span class="k">return</span> <span class="nx">e</span><span class="p">.</span><span class="nx">slice</span><span class="p">()}</span><span class="k">return</span> <span class="nx">e</span><span class="p">}},</span><span class="nx">languages</span><span class="o">:</span><span class="p">{</span><span class="nx">extend</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">n</span><span class="p">){</span><span class="kd">var</span> <span class="nx">r</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">util</span><span class="p">.</span><span class="nx">clone</span><span class="p">(</span><span class="nx">t</span><span class="p">.</span><span class="nx">languages</span><span class="p">[</span><span class="nx">e</span><span class="p">]);</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">n</span><span class="p">)</span><span class="nx">r</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span><span class="o">=</span><span class="nx">n</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span><span class="k">return</span> <span class="nx">r</span><span class="p">},</span><span class="nx">insertBefore</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">n</span><span class="p">,</span><span class="nx">r</span><span class="p">,</span><span class="nx">i</span><span class="p">){</span><span class="nx">i</span><span class="o">=</span><span class="nx">i</span><span class="o">||</span><span class="nx">t</span><span class="p">.</span><span class="nx">languages</span><span class="p">;</span><span class="kd">var</span> <span class="nx">s</span><span class="o">=</span><span class="nx">i</span><span class="p">[</span><span class="nx">e</span><span class="p">],</span><span class="nx">o</span><span class="o">=</span><span class="p">{};</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">u</span> <span class="k">in</span> <span class="nx">s</span><span class="p">)</span><span class="k">if</span><span class="p">(</span><span class="nx">s</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">u</span><span class="p">)){</span><span class="k">if</span><span class="p">(</span><span class="nx">u</span><span class="o">==</span><span class="nx">n</span><span class="p">)</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">a</span> <span class="k">in</span> <span class="nx">r</span><span class="p">)</span><span class="nx">r</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span><span class="o">&&</span><span class="p">(</span><span class="nx">o</span><span class="p">[</span><span class="nx">a</span><span class="p">]</span><span class="o">=</span><span class="nx">r</span><span class="p">[</span><span class="nx">a</span><span class="p">]);</span><span class="nx">o</span><span class="p">[</span><span class="nx">u</span><span class="p">]</span><span class="o">=</span><span class="nx">s</span><span class="p">[</span><span class="nx">u</span><span class="p">]}</span><span class="k">return</span> <span class="nx">i</span><span class="p">[</span><span class="nx">e</span><span class="p">]</span><span class="o">=</span><span class="nx">o</span><span class="p">},</span><span class="nx">DFS</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">n</span><span class="p">){</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">r</span> <span class="k">in</span> <span class="nx">e</span><span class="p">){</span><span class="nx">n</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">r</span><span class="p">,</span><span class="nx">e</span><span class="p">[</span><span class="nx">r</span><span class="p">]);</span><span class="nx">t</span><span class="p">.</span><span class="nx">util</span><span class="p">.</span><span class="nx">type</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span><span class="o">===</span><span class="s2">"Object"</span><span class="o">&&</span><span class="nx">t</span><span class="p">.</span><span class="nx">languages</span><span class="p">.</span><span class="nx">DFS</span><span class="p">(</span><span class="nx">e</span><span class="p">[</span><span class="nx">r</span><span class="p">],</span><span class="nx">n</span><span class="p">)}}},</span><span class="nx">highlightAll</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">n</span><span class="p">){</span><span class="kd">var</span> <span class="nx">r</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s1">'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'</span><span class="p">);</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="nx">s</span><span class="p">;</span><span class="nx">s</span><span class="o">=</span><span class="nx">r</span><span class="p">[</span><span class="nx">i</span><span class="o">++</span><span class="p">];)</span><span class="nx">t</span><span class="p">.</span><span class="nx">highlightElement</span><span class="p">(</span><span class="nx">s</span><span class="p">,</span><span class="nx">e</span><span class="o">===!</span><span class="mi">0</span><span class="p">,</span><span class="nx">n</span><span class="p">)},</span><span class="nx">highlightElement</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">r</span><span class="p">,</span><span class="nx">i</span><span class="p">,</span><span class="nx">s</span><span class="p">){</span><span class="kd">var</span> <span class="nx">o</span><span class="p">,</span><span class="nx">u</span><span class="p">,</span><span class="nx">a</span><span class="o">=</span><span class="nx">r</span><span class="p">;</span><span class="k">while</span><span class="p">(</span><span class="nx">a</span><span class="o">&&!</span><span class="nx">e</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">a</span><span class="p">.</span><span class="nx">className</span><span class="p">))</span><span class="nx">a</span><span class="o">=</span><span class="nx">a</span><span class="p">.</span><span class="nx">parentNode</span><span class="p">;</span><span class="k">if</span><span class="p">(</span><span class="nx">a</span><span class="p">){</span><span class="nx">o</span><span class="o">=</span><span class="p">(</span><span class="nx">a</span><span class="p">.</span><span class="nx">className</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span><span class="o">||</span><span class="p">[,</span><span class="s2">""</span><span class="p">])[</span><span class="mi">1</span><span class="p">];</span><span class="nx">u</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">languages</span><span class="p">[</span><span class="nx">o</span><span class="p">]}</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">u</span><span class="p">)</span><span class="k">return</span><span class="p">;</span><span class="nx">r</span><span class="p">.</span><span class="nx">className</span><span class="o">=</span><span class="nx">r</span><span class="p">.</span><span class="nx">className</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="s2">""</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\s+/g</span><span class="p">,</span><span class="s2">" "</span><span class="p">)</span><span class="o">+</span><span class="s2">" language-"</span><span class="o">+</span><span class="nx">o</span><span class="p">;</span><span class="nx">a</span><span class="o">=</span><span class="nx">r</span><span class="p">.</span><span class="nx">parentNode</span><span class="p">;</span><span class="sr">/pre/i</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">a</span><span class="p">.</span><span class="nx">nodeName</span><span class="p">)</span><span class="o">&&</span><span class="p">(</span><span class="nx">a</span><span class="p">.</span><span class="nx">className</span><span class="o">=</span><span class="nx">a</span><span class="p">.</span><span class="nx">className</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="s2">""</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\s+/g</span><span class="p">,</span><span class="s2">" "</span><span class="p">)</span><span class="o">+</span><span class="s2">" language-"</span><span class="o">+</span><span class="nx">o</span><span class="p">);</span><span class="kd">var</span> <span class="nx">f</span><span class="o">=</span><span class="nx">r</span><span class="p">.</span><span class="nx">textContent</span><span class="p">;</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">f</span><span class="p">)</span><span class="k">return</span><span class="p">;</span><span class="nx">f</span><span class="o">=</span><span class="nx">f</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&/g</span><span class="p">,</span><span class="s2">"&amp;"</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/</g</span><span class="p">,</span><span class="s2">"&lt;"</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/>/g</span><span class="p">,</span><span class="s2">"&gt;"</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\u00a0/g</span><span class="p">,</span><span class="s2">" "</span><span class="p">);</span><span class="kd">var</span> <span class="nx">l</span><span class="o">=</span><span class="p">{</span><span class="nx">element</span><span class="o">:</span><span class="nx">r</span><span class="p">,</span><span class="nx">language</span><span class="o">:</span><span class="nx">o</span><span class="p">,</span><span class="nx">grammar</span><span class="o">:</span><span class="nx">u</span><span class="p">,</span><span class="nx">code</span><span class="o">:</span><span class="nx">f</span><span class="p">};</span><span class="nx">t</span><span class="p">.</span><span class="nx">hooks</span><span class="p">.</span><span class="nx">run</span><span class="p">(</span><span class="s2">"before-highlight"</span><span class="p">,</span><span class="nx">l</span><span class="p">);</span><span class="k">if</span><span class="p">(</span><span class="nx">i</span><span class="o">&&</span><span class="nx">self</span><span class="p">.</span><span class="nx">Worker</span><span class="p">){</span><span class="kd">var</span> <span class="nx">c</span><span class="o">=</span><span class="k">new</span> <span class="nx">Worker</span><span class="p">(</span><span class="nx">t</span><span class="p">.</span><span class="nx">filename</span><span class="p">);</span><span class="nx">c</span><span class="p">.</span><span class="nx">onmessage</span><span class="o">=</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span><span class="nx">l</span><span class="p">.</span><span class="nx">highlightedCode</span><span class="o">=</span><span class="nx">n</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">data</span><span class="p">));</span><span class="nx">l</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">innerHTML</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">highlightedCode</span><span class="p">;</span><span class="nx">s</span><span class="o">&&</span><span class="nx">s</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">l</span><span class="p">.</span><span class="nx">element</span><span class="p">);</span><span class="nx">t</span><span class="p">.</span><span class="nx">hooks</span><span class="p">.</span><span class="nx">run</span><span class="p">(</span><span class="s2">"after-highlight"</span><span class="p">,</span><span class="nx">l</span><span class="p">)};</span><span class="nx">c</span><span class="p">.</span><span class="nx">postMessage</span><span class="p">(</span><span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">({</span><span class="nx">language</span><span class="o">:</span><span class="nx">l</span><span class="p">.</span><span class="nx">language</span><span class="p">,</span><span class="nx">code</span><span class="o">:</span><span class="nx">l</span><span class="p">.</span><span class="nx">code</span><span class="p">}))}</span><span class="k">else</span><span class="p">{</span><span class="nx">l</span><span class="p">.</span><span class="nx">highlightedCode</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">highlight</span><span class="p">(</span><span class="nx">l</span><span class="p">.</span><span class="nx">code</span><span class="p">,</span><span class="nx">l</span><span class="p">.</span><span class="nx">grammar</span><span class="p">);</span><span class="nx">l</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">innerHTML</span><span class="o">=</span><span class="nx">l</span><span class="p">.</span><span class="nx">highlightedCode</span><span class="p">;</span><span class="nx">s</span><span class="o">&&</span><span class="nx">s</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">r</span><span class="p">);</span><span class="nx">t</span><span class="p">.</span><span class="nx">hooks</span><span class="p">.</span><span class="nx">run</span><span class="p">(</span><span class="s2">"after-highlight"</span><span class="p">,</span><span class="nx">l</span><span class="p">)}},</span><span class="nx">highlight</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">r</span><span class="p">){</span><span class="k">return</span> <span class="nx">n</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">t</span><span class="p">.</span><span class="nx">tokenize</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">r</span><span class="p">))},</span><span class="nx">tokenize</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">n</span><span class="p">){</span><span class="kd">var</span> <span class="nx">r</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">Token</span><span class="p">,</span><span class="nx">i</span><span class="o">=</span><span class="p">[</span><span class="nx">e</span><span class="p">],</span><span class="nx">s</span><span class="o">=</span><span class="nx">n</span><span class="p">.</span><span class="nx">rest</span><span class="p">;</span><span class="k">if</span><span class="p">(</span><span class="nx">s</span><span class="p">){</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">o</span> <span class="k">in</span> <span class="nx">s</span><span class="p">)</span><span class="nx">n</span><span class="p">[</span><span class="nx">o</span><span class="p">]</span><span class="o">=</span><span class="nx">s</span><span class="p">[</span><span class="nx">o</span><span class="p">];</span><span class="k">delete</span> <span class="nx">n</span><span class="p">.</span><span class="nx">rest</span><span class="p">}</span><span class="nx">e</span><span class="o">:</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">o</span> <span class="k">in</span> <span class="nx">n</span><span class="p">){</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">n</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span><span class="o">||!</span><span class="nx">n</span><span class="p">[</span><span class="nx">o</span><span class="p">])</span><span class="k">continue</span><span class="p">;</span><span class="kd">var</span> <span class="nx">u</span><span class="o">=</span><span class="nx">n</span><span class="p">[</span><span class="nx">o</span><span class="p">],</span><span class="nx">a</span><span class="o">=</span><span class="nx">u</span><span class="p">.</span><span class="nx">inside</span><span class="p">,</span><span class="nx">f</span><span class="o">=!!</span><span class="nx">u</span><span class="p">.</span><span class="nx">lookbehind</span><span class="o">||</span><span class="mi">0</span><span class="p">;</span><span class="nx">u</span><span class="o">=</span><span class="nx">u</span><span class="p">.</span><span class="nx">pattern</span><span class="o">||</span><span class="nx">u</span><span class="p">;</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">l</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="nx">l</span><span class="o"><</span><span class="nx">i</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span><span class="nx">l</span><span class="o">++</span><span class="p">){</span><span class="kd">var</span> <span class="nx">c</span><span class="o">=</span><span class="nx">i</span><span class="p">[</span><span class="nx">l</span><span class="p">];</span><span class="k">if</span><span class="p">(</span><span class="nx">i</span><span class="p">.</span><span class="nx">length</span><span class="o">></span><span class="nx">e</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span><span class="k">break</span> <span class="nx">e</span><span class="p">;</span><span class="k">if</span><span class="p">(</span><span class="nx">c</span> <span class="k">instanceof</span> <span class="nx">r</span><span class="p">)</span><span class="k">continue</span><span class="p">;</span><span class="nx">u</span><span class="p">.</span><span class="nx">lastIndex</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kd">var</span> <span class="nx">h</span><span class="o">=</span><span class="nx">u</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">c</span><span class="p">);</span><span class="k">if</span><span class="p">(</span><span class="nx">h</span><span class="p">){</span><span class="nx">f</span><span class="o">&&</span><span class="p">(</span><span class="nx">f</span><span class="o">=</span><span class="nx">h</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">length</span><span class="p">);</span><span class="kd">var</span> <span class="nx">p</span><span class="o">=</span><span class="nx">h</span><span class="p">.</span><span class="nx">index</span><span class="o">-</span><span class="mi">1</span><span class="o">+</span><span class="nx">f</span><span class="p">,</span><span class="nx">h</span><span class="o">=</span><span class="nx">h</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">slice</span><span class="p">(</span><span class="nx">f</span><span class="p">),</span><span class="nx">d</span><span class="o">=</span><span class="nx">h</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span><span class="nx">v</span><span class="o">=</span><span class="nx">p</span><span class="o">+</span><span class="nx">d</span><span class="p">,</span><span class="nx">m</span><span class="o">=</span><span class="nx">c</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nx">p</span><span class="o">+</span><span class="mi">1</span><span class="p">),</span><span class="nx">g</span><span class="o">=</span><span class="nx">c</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">v</span><span class="o">+</span><span class="mi">1</span><span class="p">),</span><span class="nx">y</span><span class="o">=</span><span class="p">[</span><span class="nx">l</span><span class="p">,</span><span class="mi">1</span><span class="p">];</span><span class="nx">m</span><span class="o">&&</span><span class="nx">y</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">m</span><span class="p">);</span><span class="kd">var</span> <span class="nx">b</span><span class="o">=</span><span class="k">new</span> <span class="nx">r</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span><span class="nx">a</span><span class="o">?</span><span class="nx">t</span><span class="p">.</span><span class="nx">tokenize</span><span class="p">(</span><span class="nx">h</span><span class="p">,</span><span class="nx">a</span><span class="p">)</span><span class="o">:</span><span class="nx">h</span><span class="p">);</span><span class="nx">y</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">b</span><span class="p">);</span><span class="nx">g</span><span class="o">&&</span><span class="nx">y</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">g</span><span class="p">);</span><span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">splice</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span><span class="nx">y</span><span class="p">)}}}</span><span class="k">return</span> <span class="nx">i</span><span class="p">},</span><span class="nx">hooks</span><span class="o">:</span><span class="p">{</span><span class="nx">all</span><span class="o">:</span><span class="p">{},</span><span class="nx">add</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">n</span><span class="p">){</span><span class="kd">var</span> <span class="nx">r</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">hooks</span><span class="p">.</span><span class="nx">all</span><span class="p">;</span><span class="nx">r</span><span class="p">[</span><span class="nx">e</span><span class="p">]</span><span class="o">=</span><span class="nx">r</span><span class="p">[</span><span class="nx">e</span><span class="p">]</span><span class="o">||</span><span class="p">[];</span><span class="nx">r</span><span class="p">[</span><span class="nx">e</span><span class="p">].</span><span class="nx">push</span><span class="p">(</span><span class="nx">n</span><span class="p">)},</span><span class="nx">run</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">n</span><span class="p">){</span><span class="kd">var</span> <span class="nx">r</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">hooks</span><span class="p">.</span><span class="nx">all</span><span class="p">[</span><span class="nx">e</span><span class="p">];</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">r</span><span class="o">||!</span><span class="nx">r</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span><span class="k">return</span><span class="p">;</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="nx">s</span><span class="p">;</span><span class="nx">s</span><span class="o">=</span><span class="nx">r</span><span class="p">[</span><span class="nx">i</span><span class="o">++</span><span class="p">];)</span><span class="nx">s</span><span class="p">(</span><span class="nx">n</span><span class="p">)}}},</span><span class="nx">n</span><span class="o">=</span><span class="nx">t</span><span class="p">.</span><span class="nx">Token</span><span class="o">=</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">t</span><span class="p">){</span><span class="k">this</span><span class="p">.</span><span class="nx">type</span><span class="o">=</span><span class="nx">e</span><span class="p">;</span><span class="k">this</span><span class="p">.</span><span class="nx">content</span><span class="o">=</span><span class="nx">t</span><span class="p">};</span><span class="nx">n</span><span class="p">.</span><span class="nx">stringify</span><span class="o">=</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span><span class="k">if</span><span class="p">(</span><span class="k">typeof</span> <span class="nx">e</span><span class="o">==</span><span class="s2">"string"</span><span class="p">)</span><span class="k">return</span> <span class="nx">e</span><span class="p">;</span><span class="k">if</span><span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">toString</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span><span class="o">==</span><span class="s2">"[object Array]"</span><span class="p">)</span><span class="k">return</span> <span class="nx">e</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">n</span><span class="p">.</span><span class="nx">stringify</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s2">""</span><span class="p">);</span><span class="kd">var</span> <span class="nx">r</span><span class="o">=</span><span class="p">{</span><span class="nx">type</span><span class="o">:</span><span class="nx">e</span><span class="p">.</span><span class="nx">type</span><span class="p">,</span><span class="nx">content</span><span class="o">:</span><span class="nx">n</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">content</span><span class="p">),</span><span class="nx">tag</span><span class="o">:</span><span class="s2">"span"</span><span class="p">,</span><span class="nx">classes</span><span class="o">:</span><span class="p">[</span><span class="s2">"token"</span><span class="p">,</span><span class="nx">e</span><span class="p">.</span><span class="nx">type</span><span class="p">],</span><span class="nx">attributes</span><span class="o">:</span><span class="p">{}};</span><span class="nx">r</span><span class="p">.</span><span class="nx">type</span><span class="o">==</span><span class="s2">"comment"</span><span class="o">&&</span><span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">attributes</span><span class="p">.</span><span class="nx">spellcheck</span><span class="o">=</span><span class="s2">"true"</span><span class="p">);</span><span class="nx">t</span><span class="p">.</span><span class="nx">hooks</span><span class="p">.</span><span class="nx">run</span><span class="p">(</span><span class="s2">"wrap"</span><span class="p">,</span><span class="nx">r</span><span class="p">);</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="s2">""</span><span class="p">;</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">s</span> <span class="k">in</span> <span class="nx">r</span><span class="p">.</span><span class="nx">attributes</span><span class="p">)</span><span class="nx">i</span><span class="o">+=</span><span class="nx">s</span><span class="o">+</span><span class="s1">'="'</span><span class="o">+</span><span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">attributes</span><span class="p">[</span><span class="nx">s</span><span class="p">]</span><span class="o">||</span><span class="s2">""</span><span class="p">)</span><span class="o">+</span><span class="s1">'"'</span><span class="p">;</span><span class="k">return</span><span class="s2">"<"</span><span class="o">+</span><span class="nx">r</span><span class="p">.</span><span class="nx">tag</span><span class="o">+</span><span class="s1">' class="'</span><span class="o">+</span><span class="nx">r</span><span class="p">.</span><span class="nx">classes</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s2">" "</span><span class="p">)</span><span class="o">+</span><span class="s1">'" '</span><span class="o">+</span><span class="nx">i</span><span class="o">+</span><span class="s2">">"</span><span class="o">+</span><span class="nx">r</span><span class="p">.</span><span class="nx">content</span><span class="o">+</span><span class="s2">"</"</span><span class="o">+</span><span class="nx">r</span><span class="p">.</span><span class="nx">tag</span><span class="o">+</span><span class="s2">">"</span><span class="p">};</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">self</span><span class="p">.</span><span class="nb">document</span><span class="p">){</span><span class="nx">self</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s2">"message"</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span><span class="kd">var</span> <span class="nx">n</span><span class="o">=</span><span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">data</span><span class="p">),</span><span class="nx">r</span><span class="o">=</span><span class="nx">n</span><span class="p">.</span><span class="nx">language</span><span class="p">,</span><span class="nx">i</span><span class="o">=</span><span class="nx">n</span><span class="p">.</span><span class="nx">code</span><span class="p">;</span><span class="nx">self</span><span class="p">.</span><span class="nx">postMessage</span><span class="p">(</span><span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">t</span><span class="p">.</span><span class="nx">tokenize</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span><span class="nx">t</span><span class="p">.</span><span class="nx">languages</span><span class="p">[</span><span class="nx">r</span><span class="p">])));</span><span class="nx">self</span><span class="p">.</span><span class="nx">close</span><span class="p">()},</span><span class="o">!</span><span class="mi">1</span><span class="p">);</span><span class="k">return</span><span class="p">}</span><span class="kd">var</span> <span class="nx">r</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">"script"</span><span class="p">);</span><span class="nx">r</span><span class="o">=</span><span class="nx">r</span><span class="p">[</span><span class="nx">r</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span><span class="k">if</span><span class="p">(</span><span class="nx">r</span><span class="p">){</span><span class="nx">t</span><span class="p">.</span><span class="nx">filename</span><span class="o">=</span><span class="nx">r</span><span class="p">.</span><span class="nx">src</span><span class="p">;</span><span class="nb">document</span><span class="p">.</span><span class="nx">addEventListener</span><span class="o">&&!</span><span class="nx">r</span><span class="p">.</span><span class="nx">hasAttribute</span><span class="p">(</span><span class="s2">"data-manual"</span><span class="p">)</span><span class="o">&&</span><span class="nb">document</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s2">"DOMContentLoaded"</span><span class="p">,</span><span class="nx">t</span><span class="p">.</span><span class="nx">highlightAll</span><span class="p">)}})();;</span>
<span class="nx">Prism</span><span class="p">.</span><span class="nx">languages</span><span class="p">.</span><span class="nx">css</span><span class="o">=</span><span class="p">{</span><span class="nx">comment</span><span class="o">:</span><span class="sr">/\/\*[\w\W]*?\*\//g</span><span class="p">,</span><span class="nx">atrule</span><span class="o">:</span><span class="sr">/@[\w-]+?(\s+[^;{]+)?(?=\s*{|\s*;)/gi</span><span class="p">,</span><span class="nx">url</span><span class="o">:</span><span class="sr">/url\((["']?).*?\)/gi</span><span class="p">,</span><span class="nx">selector</span><span class="o">:</span><span class="sr">/[^\{\}\s][^\{\}]*(?=\s*\{)/g</span><span class="p">,</span><span class="nx">property</span><span class="o">:</span><span class="sr">/(\b|\B)[a-z-]+(?=\s*:)/ig</span><span class="p">,</span><span class="nx">string</span><span class="o">:</span><span class="sr">/("|')(\?.)*?/g</span><span class="p">,</span><span class="nx">important</span><span class="o">:</span><span class="sr">/\B!important\b/gi</span><span class="p">,</span><span class="nx">ignore</span><span class="o">:</span><span class="sr">/&(lt|gt|amp);/gi</span><span class="p">,</span><span class="nx">punctuation</span><span class="o">:</span><span class="sr">/[\{\};:]/g</span><span class="p">};</span><span class="nx">Prism</span><span class="p">.</span><span class="nx">languages</span><span class="p">.</span><span class="nx">markup</span><span class="o">&&</span><span class="nx">Prism</span><span class="p">.</span><span class="nx">languages</span><span class="p">.</span><span class="nx">insertBefore</span><span class="p">(</span><span class="s2">"markup"</span><span class="p">,</span><span class="s2">"tag"</span><span class="p">,{</span><span class="nx">style</span><span class="o">:</span><span class="p">{</span><span class="nx">pattern</span><span class="o">:</span><span class="sr">/(&lt;|<)style[\w\W]*?(>|&gt;)[\w\W]*?(&lt;|<)\/style(>|&gt;)/ig</span><span class="p">,</span><span class="nx">inside</span><span class="o">:</span><span class="p">{</span><span class="nx">tag</span><span class="o">:</span><span class="p">{</span><span class="nx">pattern</span><span class="o">:</span><span class="sr">/(&lt;|<)style[\w\W]*?(>|&gt;)|(&lt;|<)\/style(>|&gt;)/ig</span><span class="p">,</span><span class="nx">inside</span><span class="o">:</span><span class="nx">Prism</span><span class="p">.</span><span class="nx">languages</span><span class="p">.</span><span class="nx">markup</span><span class="p">.</span><span class="nx">tag</span><span class="p">.</span><span class="nx">inside</span><span class="p">},</span><span class="nx">rest</span><span class="o">:</span><span class="nx">Prism</span><span class="p">.</span><span class="nx">languages</span><span class="p">.</span><span class="nx">css</span><span class="p">}}});</span>
<span class="kd">var</span> <span class="nx">prismStyle</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">'style'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">beautified</span> <span class="o">=</span> <span class="nx">cssbeautify</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">textContent</span><span class="p">,</span> <span class="p">{</span><span class="nx">autosemicolon</span><span class="o">:</span> <span class="kc">true</span><span class="p">});</span>
<span class="kd">var</span> <span class="nx">highlighted</span> <span class="o">=</span> <span class="nx">Prism</span><span class="p">.</span><span class="nx">highlight</span><span class="p">(</span><span class="nx">beautified</span><span class="p">,</span> <span class="nx">Prism</span><span class="p">.</span><span class="nx">languages</span><span class="p">.</span><span class="nx">css</span><span class="p">);</span>
<span class="nx">prismStyle</span><span class="p">.</span><span class="nx">textContent</span> <span class="o">=</span> <span class="s1">'code[class*="language-"],pre[class*="language-"]{color:black;text-shadow:0 1px white;font-family:Consolas,Monaco,<!-- REPLACE -->#39;Andale Mono<!-- REPLACE -->#39;,monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;}@media print{code[class*="language-"],pre[class*="language-"]{text-shadow:none;}}pre[class*="language-"]{padding:1em;margin:.5em 0;overflow:auto;}:not(pre) > code[class*="language-"],pre[class*="language-"]{background:#f5f2f0;}:not(pre) > code[class*="language-"]{padding:.1em;border-radius:.3em;}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:slategray;}.token.punctuation{color:#999;}.namespace{opacity:.7;}.token.property,.token.tag,.token.boolean,.token.number{color:#905;}.token.selector,.token.attr-name,.token.string{color:#690;}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color:#a67f59;background:hsla(0,0%,100%,.5);}.token.atrule,.token.attr-value,.token.keyword{color:#07a;}.token.regex,.token.important{color:#e90;}.token.important{font-weight:bold;}.token.entity{cursor:help;}'</span><span class="p">;</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">head</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="s1">''</span><span class="p">;</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">head</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">prismStyle</span><span class="p">);</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="s1">'<code><pre>'</span> <span class="o">+</span> <span class="nx">highlighted</span> <span class="o">+</span> <span class="s1">'</pre></code>'</span><span class="p">;</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='cssreload'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/cssreload/cssreload.js'>cssreload.js</a> <a href='#cssreload'>#</a> <small style='float:right'><a href='snippets/cssreload/cssreload.js'>(view raw)</a></small></h3>
<p>Reloads all CSS files on the page. It does so by adding a random GET parameter onto each stylesheet’s <code>href</code> attribute.</p>
<p><a href="snippets/cssreload/cssreload.js"><img src="snippets/cssreload/cssreload.gif" alt="snippets/cssreload/cssreload" /></a></p>
</div><div class="highlight"><pre><span class="c1">// cssreload.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Removes then reloads all the CSS files in the current page</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">function</span> <span class="nx">insertAfter</span><span class="p">(</span><span class="nx">newElement</span><span class="p">,</span> <span class="nx">targetElement</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">parent</span> <span class="o">=</span> <span class="nx">targetElement</span><span class="p">.</span><span class="nx">parentNode</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">parent</span><span class="p">.</span><span class="nx">lastChild</span> <span class="o">==</span> <span class="nx">targetElement</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">parent</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">newElement</span><span class="p">);</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="nx">parent</span><span class="p">.</span><span class="nx">insertBefore</span><span class="p">(</span><span class="nx">newElement</span><span class="p">,</span> <span class="nx">targetElement</span><span class="p">.</span><span class="nx">nextSibling</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">reloadStyleSheet</span><span class="p">(</span><span class="nx">stylesheet</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">element</span> <span class="o">=</span> <span class="nx">stylesheet</span><span class="p">.</span><span class="nx">ownerNode</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">clone</span> <span class="o">=</span> <span class="nx">element</span><span class="p">.</span><span class="nx">cloneNode</span><span class="p">(</span><span class="kc">false</span><span class="p">);</span>
<span class="nx">clone</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span> <span class="nx">addRandomToUrl</span><span class="p">(</span><span class="nx">clone</span><span class="p">.</span><span class="nx">href</span><span class="p">);</span>
<span class="nx">clone</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s2">"load"</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">element</span><span class="p">.</span><span class="nx">parentNode</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">element</span><span class="p">.</span><span class="nx">parentNode</span><span class="p">.</span><span class="nx">removeChild</span><span class="p">(</span><span class="nx">element</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="nx">insertAfter</span><span class="p">(</span><span class="nx">clone</span><span class="p">,</span> <span class="nx">element</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">addRandomToUrl</span><span class="p">(</span><span class="nx">input</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// prevent CSS caching</span>
<span class="kd">var</span> <span class="nx">hasRnd</span> <span class="o">=</span> <span class="sr">/([?&])_=[^&]*/</span><span class="p">,</span>
<span class="nx">hasQueryString</span> <span class="o">=</span> <span class="sr">/\?/</span><span class="p">,</span>
<span class="nx">hasHash</span> <span class="o">=</span> <span class="sr">/(.+)#(.+)/</span><span class="p">,</span>
<span class="nx">hash</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span>
<span class="nx">rnd</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">hashMatches</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">hasHash</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">hashMatches</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">input</span> <span class="o">=</span> <span class="nx">hashMatches</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
<span class="nx">hash</span> <span class="o">=</span> <span class="nx">hashMatches</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
<span class="p">}</span>
<span class="nx">url</span> <span class="o">=</span> <span class="nx">hasRnd</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">input</span><span class="p">)</span> <span class="o">?</span>
<span class="nx">input</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">hasRnd</span><span class="p">,</span> <span class="s2">"$1_="</span> <span class="o">+</span> <span class="nx">rnd</span><span class="p">)</span> <span class="o">:</span>
<span class="nx">input</span> <span class="o">+</span> <span class="p">(</span><span class="nx">hasQueryString</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">input</span><span class="p">)</span> <span class="o">?</span> <span class="s2">"&"</span> <span class="o">:</span> <span class="s2">"?"</span><span class="p">)</span> <span class="o">+</span> <span class="s2">"_="</span> <span class="o">+</span> <span class="nx">rnd</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">hash</span><span class="p">)</span> <span class="nx">url</span> <span class="o">+=</span> <span class="s1">'#'</span> <span class="o">+</span> <span class="nx">hash</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">url</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">[].</span><span class="nx">forEach</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">styleSheets</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">styleSheet</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">styleSheet</span><span class="p">.</span><span class="nx">href</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'reload '</span> <span class="o">+</span> <span class="nx">styleSheet</span><span class="p">.</span><span class="nx">href</span><span class="p">);</span>
<span class="nx">reloadStyleSheet</span><span class="p">(</span><span class="nx">styleSheet</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='dataurl'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/dataurl/dataurl.js'>dataurl.js</a> <a href='#dataurl'>#</a> <small style='float:right'><a href='snippets/dataurl/dataurl.js'>(view raw)</a></small></h3>
<p>Convert all images on the page to data URLs. <em>Note: this only works for images that are on the same domain as the current page</em>.</p>
<p><a href="snippets/dataurl/dataurl.js"><img src="snippets/dataurl/dataurl.png" alt="snippets/dataurl/dataurl" /></a></p>
</div><div class="highlight"><pre><span class="c1">// dataurl.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Print out data URLs for all images / canvases on the page.</span>
<span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"Data URLs"</span><span class="p">);</span>
<span class="p">[].</span><span class="nx">forEach</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s2">"img"</span><span class="p">),</span> <span class="kd">function</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">"canvas"</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">ctx</span> <span class="o">=</span> <span class="nx">c</span><span class="p">.</span><span class="nx">getContext</span><span class="p">(</span><span class="s2">"2d"</span><span class="p">);</span>
<span class="nx">c</span><span class="p">.</span><span class="nx">width</span> <span class="o">=</span> <span class="nx">i</span><span class="p">.</span><span class="nx">width</span><span class="p">;</span>
<span class="nx">c</span><span class="p">.</span><span class="nx">height</span> <span class="o">=</span> <span class="nx">i</span><span class="p">.</span><span class="nx">height</span><span class="p">;</span>
<span class="k">try</span> <span class="p">{</span>
<span class="nx">ctx</span><span class="p">.</span><span class="nx">drawImage</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">c</span><span class="p">.</span><span class="nx">toDataURL</span><span class="p">());</span>
<span class="p">}</span>
<span class="k">catch</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="s2">"No Permission - try opening this image in a new tab and running the snippet again?"</span><span class="p">,</span> <span class="nx">i</span><span class="p">.</span><span class="nx">src</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">[].</span><span class="nx">forEach</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s2">"canvas"</span><span class="p">),</span> <span class="kd">function</span><span class="p">(</span><span class="nx">c</span><span class="p">)</span> <span class="p">{</span>
<span class="k">try</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">c</span><span class="p">,</span> <span class="nx">c</span><span class="p">.</span><span class="nx">toDataURL</span><span class="p">());</span>
<span class="p">}</span>
<span class="k">catch</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">c</span><span class="p">,</span> <span class="s2">"No Permission"</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">(</span><span class="s2">"Data URLs"</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='formcontrols'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/formcontrols/formcontrols.js'>formcontrols.js</a> <a href='#formcontrols'>#</a> <small style='float:right'><a href='snippets/formcontrols/formcontrols.js'>(view raw)</a></small></h3>
<p>Shows all html form elements with their values and types in a nice table. Adds a new table for each form on the page. Implementation by <a href="https://github.com/Kienz">Kienz</a>.</p>
<p><a href="snippets/formcontrols/formcontrols.js"><img src="snippets/formcontrols/formcontrols.png" alt="snippets/formcontrols/formcontrols" /></a></p>
</div><div class="highlight"><pre><span class="c1">// formcontrols.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Print out forms and their controls</span>
<span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">forms</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s2">"form"</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">forms</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">tab</span> <span class="o">=</span> <span class="p">[</span> <span class="p">];</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"HTMLForm <!-- REPLACE -->quot;"</span> <span class="o">+</span> <span class="nx">forms</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">"<!-- REPLACE -->quot;: "</span> <span class="o">+</span> <span class="nx">forms</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">action</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Element:"</span><span class="p">,</span> <span class="nx">forms</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="s2">"\nName: "</span><span class="o">+</span><span class="nx">forms</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">name</span><span class="o">+</span><span class="s2">"\nMethod: "</span><span class="o">+</span><span class="nx">forms</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">method</span><span class="p">.</span><span class="nx">toUpperCase</span><span class="p">()</span><span class="o">+</span><span class="s2">"\nAction: "</span><span class="o">+</span><span class="nx">forms</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">action</span> <span class="o">||</span> <span class="s2">"null"</span><span class="p">);</span>
<span class="p">[</span><span class="s2">"input"</span><span class="p">,</span> <span class="s2">"textarea"</span><span class="p">,</span> <span class="s2">"select"</span><span class="p">].</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">control</span><span class="p">)</span> <span class="p">{</span>
<span class="p">[].</span><span class="nx">forEach</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">forms</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="nx">control</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">tab</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="s2">"Element"</span><span class="o">:</span> <span class="nx">node</span><span class="p">,</span>
<span class="s2">"Type"</span><span class="o">:</span> <span class="nx">node</span><span class="p">.</span><span class="nx">type</span><span class="p">,</span>
<span class="s2">"Name"</span><span class="o">:</span> <span class="nx">node</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span>
<span class="s2">"Value"</span><span class="o">:</span> <span class="nx">node</span><span class="p">.</span><span class="nx">value</span><span class="p">,</span>
<span class="s2">"Pretty Value"</span><span class="o">:</span> <span class="p">(</span><span class="nb">isNaN</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">value</span><span class="p">)</span> <span class="o">||</span> <span class="nx">node</span><span class="p">.</span><span class="nx">value</span> <span class="o">===</span> <span class="s2">""</span> <span class="o">?</span> <span class="nx">node</span><span class="p">.</span><span class="nx">value</span> <span class="o">:</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">value</span><span class="p">))</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">table</span><span class="p">(</span><span class="nx">tab</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='hashlink'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/hashlink/hashlink.js'>hashlink.js</a> <a href='#hashlink'>#</a> <small style='float:right'><a href='snippets/hashlink/hashlink.js'>(view raw)</a></small></h3>
<p>Handy way to find the closest linkable element on a page. Run it, then click on an element, and it will give you the closest #link to that page.</p>
<p><a href="snippets/hashlink/hashlink.js"><img src="snippets/hashlink/hashlink.png" alt="snippets/hashlink/hashlink" /></a></p>
<p><a href="snippets/hashlink/hashlink.js"><img src="snippets/hashlink/hashlink.gif" alt="snippets/hashlink/hashlink" /></a></p>
</div><div class="highlight"><pre><span class="c1">// hashlink.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Click on an element to print out the closest hash link.</span>
<span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">function</span> <span class="nx">logHashlink</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">removeEventListener</span><span class="p">(</span><span class="s1">'mousedown'</span><span class="p">,</span> <span class="nx">logHashlink</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="nx">node</span> <span class="o">!=</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">tagName</span> <span class="o">===</span> <span class="s2">"A"</span> <span class="o">&&</span> <span class="nx">node</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">id</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">name</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">id</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">node</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">parentNode</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span>
<span class="nx">e</span><span class="p">.</span><span class="nx">stopPropagation</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">URL</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">origin</span> <span class="o">+</span> <span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">pathname</span> <span class="o">+</span> <span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">search</span><span class="p">;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"Hashlink"</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Clicked on "</span><span class="p">,</span> <span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">id</span> <span class="o">===</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"No ID Found - closest anchor: "</span> <span class="o">+</span> <span class="nx">URL</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Closest linkable element: "</span><span class="p">,</span> <span class="nx">node</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">URL</span> <span class="o">+</span> <span class="s2">"#"</span> <span class="o">+</span> <span class="nx">id</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">(</span><span class="s2">"Hashlink"</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">stopClickEvent</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span>
<span class="nx">e</span><span class="p">.</span><span class="nx">stopPropagation</span><span class="p">();</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">removeEventListener</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span> <span class="nx">stopClickEvent</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="p">}</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">'mousedown'</span><span class="p">,</span> <span class="nx">logHashlink</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span> <span class="nx">stopClickEvent</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="k">return</span> <span class="s2">"hashlink: Click on an element to log it's closest hash link"</span><span class="p">;</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='html_i18n_content'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/html_i18n_content/html_i18n_content.js'>html_i18n_content.js</a> <a href='#html_i18n_content'>#</a> <small style='float:right'><a href='snippets/html_i18n_content/html_i18n_content.js'>(view raw)</a></small></h3>
<p>Generate downloadable files, based on location.href,
for <a href="http://developer.chrome.com/extensions/i18n.html">i18n</a> of Chrome App or Extension:</p>
<ul>
<li>messages.json containing chrome.i18n messages (with placeholders) for element.innerText and input[value]</li>
<li>location.href with i18n-content tags added (text and placeholders preserved to ease round-tripping changes)</li>
<li>applyChromeI18nMessages.js to include in location.href to initialize localized messages on load</li>
</ul>
<p>Implementation by <a href="https://github.com/anaran">anaran</a>.</p>
<p><a href="snippets/html_i18n_content/html_i18n_content.js"><img src="snippets/html_i18n_content/html_i18n_content.gif" alt="snippets/html_i18n_content/html_i18n_content" /></a></p>
</div><div class="highlight"><pre><span class="c1">// html_i18n_content.js</span>
<span class="c1">// https://github.com/anaran/devtools-snippets</span>
<span class="c1">// Generate downloadable chrome.i18n messages file for location.href.</span>
<span class="c1">// See http://developer.chrome.com/extensions/i18n.html</span>
<span class="c1">// Messages are based on innerText or value attribute, keyed by class attribute.</span>
<span class="c1">// $Placeholders$ are added to messages.json as well.</span>
<span class="c1">// Generate downloadable HTML file with corresponding i18n-content attributes.</span>
<span class="c1">// Generate downloadable script to initialize localized messages on load.</span>
<span class="k">try</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">location</span><span class="p">.</span><span class="nx">href</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">hsh</span> <span class="o">=</span> <span class="p">{};</span>
<span class="kd">var</span> <span class="nx">replacer</span> <span class="o">=</span> <span class="p">[];</span>
<span class="nx">replacer</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="s1">'message'</span><span class="p">,</span> <span class="s1">'description'</span><span class="p">,</span> <span class="s1">'placeholders'</span><span class="p">,</span> <span class="s1">'content'</span><span class="p">,</span> <span class="s1">'example'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">addKeyValuePlaceHolders</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">messages</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">messages</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">'message'</span><span class="o">:</span> <span class="nx">value</span><span class="p">,</span>
<span class="s1">'description'</span><span class="o">:</span> <span class="nx">value</span>
<span class="p">};</span>
<span class="kd">var</span> <span class="nx">placeHolders</span> <span class="o">=</span> <span class="nx">value</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/\$([^$]+)\$/g</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">placeHolders</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">messages</span><span class="p">[</span><span class="nx">key</span><span class="p">][</span><span class="s1">'placeholders'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{};</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">jlen</span> <span class="o">=</span> <span class="nx">placeHolders</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">j</span> <span class="o"><</span> <span class="nx">jlen</span><span class="p">;</span> <span class="nx">j</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">placeHolderName</span> <span class="o">=</span> <span class="nx">placeHolders</span><span class="p">[</span><span class="nx">j</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\$/g</span><span class="p">,</span> <span class="s1">''</span><span class="p">).</span><span class="nx">toLowerCase</span><span class="p">();</span>
<span class="nx">messages</span><span class="p">[</span><span class="nx">key</span><span class="p">][</span><span class="s1">'placeholders'</span><span class="p">][</span><span class="nx">placeHolderName</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">'content'</span><span class="o">:</span> <span class="s1">'$'</span> <span class="o">+</span> <span class="p">(</span><span class="nx">j</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span>
<span class="s1">'example'</span><span class="o">:</span> <span class="nx">value</span>
<span class="p">};</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">replacer</span><span class="p">.</span><span class="nx">some</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">value</span> <span class="o">===</span> <span class="nx">placeHolderName</span><span class="p">;</span>
<span class="p">}))</span> <span class="p">{</span>
<span class="nx">replacer</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">placeHolderName</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">messages</span><span class="p">;</span>
<span class="p">};</span>
<span class="kd">var</span> <span class="nx">i18nForValueAttribute</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">select</span><span class="p">,</span> <span class="nx">messages</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">nds</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="nx">select</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">getAttribute</span><span class="p">(</span><span class="s1">'value'</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">key</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">className</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">key</span> <span class="o">&&</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">'i18n-content'</span><span class="p">,</span> <span class="nx">key</span><span class="p">);</span>
<span class="c1">// Better keep value for round-tripping.</span>
<span class="c1">// nds[i].setAttribute('value', '');</span>
<span class="nx">messages</span> <span class="o">=</span> <span class="nx">addKeyValuePlaceHolders</span><span class="p">(</span><span class="nx">messages</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="kd">var</span> <span class="nx">i18nForInnerText</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">select</span><span class="p">,</span> <span class="nx">messages</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">nds</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="nx">select</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// TODO Please note we use .innerText because it preserves newline characters in Chrome, while .textContent loses them.</span>
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">innerText</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">childElementCount</span> <span class="o">===</span> <span class="mi">0</span> <span class="o">&&</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">key</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">className</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">value</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\s+/g</span><span class="p">,</span> <span class="s1">' '</span><span class="p">).</span><span class="nx">trim</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">key</span> <span class="o">&&</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">'i18n-content'</span><span class="p">,</span> <span class="nx">key</span><span class="p">);</span>
<span class="c1">// Better keep value for round-tripping.</span>
<span class="c1">// nds[i].innerText = '';</span>
<span class="nx">messages</span> <span class="o">=</span> <span class="nx">addKeyValuePlaceHolders</span><span class="p">(</span><span class="nx">messages</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">i18nNodes</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="nx">select</span> <span class="o">+</span> <span class="s1">'[i18n-content]'</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">i18nNodes</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">i18nNodes</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">hasAttribute</span><span class="p">(</span><span class="s1">'i18n-content'</span><span class="p">)</span> <span class="o">&&</span> <span class="nx">i18nNodes</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">childElementCount</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">warn</span><span class="p">(</span><span class="s1">'HTML elements have been added to\n%O\nPlease only use text and named character references (%o)!'</span><span class="p">,</span>
<span class="nx">i18nNodes</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="s1">'https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Introduction#Named_character_references'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="nx">i18nForInnerText</span><span class="p">(</span><span class="s1">'*'</span><span class="p">,</span> <span class="nx">hsh</span><span class="p">);</span>
<span class="nx">i18nForValueAttribute</span><span class="p">(</span><span class="s1">'input[value]'</span><span class="p">,</span> <span class="nx">hsh</span><span class="p">);</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">getOwnPropertyNames</span><span class="p">(</span><span class="nx">hsh</span><span class="p">).</span><span class="nx">sort</span><span class="p">().</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">replacer</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
<span class="p">});</span>
<span class="kd">var</span> <span class="nx">messagesString</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">hsh</span><span class="p">,</span> <span class="nx">replacer</span><span class="p">,</span> <span class="mi">4</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">htmlFileText</span> <span class="o">=</span> <span class="s1">'<!DOCTYPE '</span> <span class="o">+</span> <span class="nb">document</span><span class="p">.</span><span class="nx">doctype</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s1">'>\n'</span> <span class="o">+</span> <span class="nb">document</span><span class="p">.</span><span class="nx">documentElement</span><span class="p">.</span><span class="nx">outerHTML</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">htmlFileName</span> <span class="o">=</span> <span class="nx">location</span><span class="p">.</span><span class="nx">pathname</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">'/'</span><span class="p">).</span><span class="nx">pop</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">makeDownloadLink</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">filename</span><span class="p">,</span> <span class="nx">style</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">blob</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">window</span><span class="p">.</span><span class="nx">Blob</span><span class="p">([</span><span class="nx">data</span><span class="p">],</span> <span class="p">{</span>
<span class="s1">'type'</span><span class="o">:</span> <span class="s1">'text/utf-8'</span>
<span class="p">});</span>
<span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">'a'</span><span class="p">);</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">innerText</span> <span class="o">=</span> <span class="s1">'Download '</span> <span class="o">+</span> <span class="nx">filename</span><span class="p">;</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span> <span class="nx">URL</span><span class="p">.</span><span class="nx">createObjectURL</span><span class="p">(</span><span class="nx">blob</span><span class="p">);</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">download</span> <span class="o">=</span> <span class="nx">filename</span><span class="p">;</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">'style'</span><span class="p">,</span> <span class="nx">style</span><span class="p">);</span>
<span class="nx">a</span><span class="p">.</span><span class="nx">onclick</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">setTimeout</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">removeChild</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span>
<span class="p">},</span> <span class="mi">500</span><span class="p">);</span>
<span class="p">};</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">applyChromeI18nMessages</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="c1">// This generated function body is wrapped in (...)(); to execute on load.</span>
<span class="c1">// This will only install the onreadystatechange event handler</span>
<span class="c1">// to be run when the document load is complete.</span>
<span class="c1">// Load this file into the associated HTML file by including</span>
<span class="c1">// <script src="applyChromeI18nMessages.js"></script></span>
<span class="c1">// in its head element.</span>
<span class="k">try</span> <span class="p">{</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">'readystatechange'</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">event</span><span class="p">.</span><span class="nx">target</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">!==</span> <span class="s1">'complete'</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">chrome</span><span class="p">.</span><span class="nx">i18n</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">warn</span><span class="p">(</span><span class="s1">'chrome.i18n is undefined.\n%s\nis %cnot%c viewed as part of a chrome extension.'</span><span class="p">,</span> <span class="nb">document</span><span class="p">.</span><span class="nx">URL</span><span class="p">,</span> <span class="s1">'font-weight: bold'</span><span class="p">,</span> <span class="s1">''</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">nds</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s1">'[i18n-content]'</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">getAttribute</span><span class="p">(</span><span class="s1">'value'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">key</span> <span class="o">=</span> <span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">getAttribute</span><span class="p">(</span><span class="s1">'i18n-content'</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">value</span> <span class="o">===</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// TODO Please note we use .innerText because it preserves newline characters in Chrome, while .textContent loses them.</span>
<span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">innerText</span> <span class="o">=</span> <span class="nx">chrome</span><span class="p">.</span><span class="nx">i18n</span><span class="p">.</span><span class="nx">getMessage</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="nx">nds</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">'value'</span><span class="p">,</span> <span class="nx">chrome</span><span class="p">.</span><span class="nx">i18n</span><span class="p">.</span><span class="nx">getMessage</span><span class="p">(</span><span class="nx">key</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">})();</span>
<span class="p">},</span> <span class="kc">false</span><span class="p">);</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">exception</span><span class="p">)</span> <span class="p">{</span>
<span class="nb">window</span><span class="p">.</span><span class="nx">alert</span><span class="p">(</span><span class="s1">'exception.stack: '</span> <span class="o">+</span> <span class="nx">exception</span><span class="p">.</span><span class="nx">stack</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">((</span><span class="k">new</span> <span class="nb">Date</span><span class="p">()).</span><span class="nx">toJSON</span><span class="p">(),</span> <span class="s1">'exception.stack:'</span><span class="p">,</span> <span class="nx">exception</span><span class="p">.</span><span class="nx">stack</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="nx">makeDownloadLink</span><span class="p">(</span><span class="nx">messagesString</span><span class="p">,</span> <span class="s1">'messages.json'</span><span class="p">,</span> <span class="s1">'position:fixed;top:2em;left:50%;opacity:0.5'</span><span class="p">);</span>
<span class="nx">makeDownloadLink</span><span class="p">(</span><span class="nx">htmlFileText</span><span class="p">,</span> <span class="nx">htmlFileName</span><span class="p">,</span> <span class="s1">'position:fixed;top:4em;left:50%;opacity:0.5'</span><span class="p">);</span>
<span class="nx">makeDownloadLink</span><span class="p">(</span><span class="s1">'('</span> <span class="o">+</span> <span class="nx">applyChromeI18nMessages</span> <span class="o">+</span> <span class="s1">')();'</span><span class="p">,</span> <span class="s1">'applyChromeI18nMessages.js'</span><span class="p">,</span> <span class="s1">'position:fixed;top:6em;left:50%;opacity:0.5'</span><span class="p">);</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">exception</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">exception</span><span class="p">.</span><span class="nx">stack</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div><div class='snippet-wrapper' id='insert-css'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/insert-css/insert-css.js'>insert-css.js</a> <a href='#insert-css'>#</a> <small style='float:right'><a href='snippets/insert-css/insert-css.js'>(view raw)</a></small></h3>
<p>Defines <code>insertCss()</code> function which injects a snippet of CSS into the current page. After running the snippet, you can call it as follows: <code>insertCss('span { color: red !important; }');</code></p>
<p><a href="snippets/insert-css/insert-css.js"><img src="snippets/insert-css/insert-css.png" alt="snippets/insert-css/insert-css" /></a></p>
</div><div class="highlight"><pre><span class="c1">// insert-css.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Injects a snippet of CSS into the current page.</span>
<span class="kd">function</span> <span class="nx">insertCss</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">style</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">'style'</span><span class="p">);</span>
<span class="nx">style</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s1">'text/css'</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">style</span><span class="p">.</span><span class="nx">styleSheet</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// IE</span>
<span class="nx">style</span><span class="p">.</span><span class="nx">styleSheet</span><span class="p">.</span><span class="nx">cssText</span> <span class="o">=</span> <span class="nx">code</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">// Other browsers</span>
<span class="nx">style</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">code</span><span class="p">;</span>
<span class="p">}</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">"head"</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">appendChild</span><span class="p">(</span> <span class="nx">style</span> <span class="p">);</span>
<span class="p">}</span>
<span class="c1">// Feel free to extend this snippet with your favorite CSS snippets.</span>
<span class="c1">// Here's an example which makes the current page high contrast.</span>
<span class="c1">// Notice the trailing backslashes, used to define multiline strings.</span>
<span class="kd">function</span> <span class="nx">insertCssHighContrast</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">css</span> <span class="o">=</span> <span class="s1">'\</span>
<span class="s1"> * { background: white ! important; color: black !important } \</span>
<span class="s1"> :link, :link * { color: #0000EE !important } \</span>
<span class="s1"> :visited, :visited * { color: #551A8B !important } \</span>
<span class="s1"> '</span><span class="p">;</span>
<span class="nx">insertCss</span><span class="p">(</span><span class="nx">css</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div><div class='snippet-wrapper' id='jquerify'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/jquerify/jquerify.js'>jquerify.js</a> <a href='#jquerify'>#</a> <small style='float:right'><a href='snippets/jquerify/jquerify.js'>(view raw)</a></small></h3>
<p>Includes jQuery onto a page if it is not yet included.</p>
<p><a href="snippets/jquerify/jquerify.js"><img src="snippets/jquerify/jquerify.png" alt="snippets/jquerify/jquerify" /></a></p>
</div><div class="highlight"><pre><span class="c1">// jquerify.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Add jQuery to any page that does not have it already.</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span> <span class="o">!</span><span class="nb">window</span><span class="p">.</span><span class="nx">jQuery</span> <span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">dollarInUse</span> <span class="o">=</span> <span class="o">!!</span><span class="nb">window</span><span class="p">.</span><span class="nx">$</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">s</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">'script'</span><span class="p">);</span>
<span class="nx">s</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">'src'</span><span class="p">,</span> <span class="s1">'//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js'</span><span class="p">);</span>
<span class="nx">s</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">'load'</span><span class="p">,</span> <span class="kd">function</span><span class="p">(){</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'jQuery loaded!'</span><span class="p">);</span>
<span class="k">if</span><span class="p">(</span><span class="nx">dollarInUse</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">jQuery</span><span class="p">.</span><span class="nx">noConflict</span><span class="p">();</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'`$` already in use; use `jQuery`'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">s</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='log'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/log/log.js'>log.js</a> <a href='#log'>#</a> <small style='float:right'><a href='snippets/log/log.js'>(view raw)</a></small></h3>
<p>Adds a <code>log</code> function to window object.</p>
<p><a href="snippets/log/log.js"><img src="snippets/log/log.png" alt="snippets/log/log" /></a></p>
</div><div class="highlight"><pre><span class="c1">// log.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Adds a `log` function to window object.</span>
<span class="c1">// http://www.briangrinstead.com/blog/console-log-helper-function</span>
<span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nb">window</span><span class="p">.</span><span class="nx">log</span> <span class="o">=</span> <span class="nb">Function</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">bind</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">,</span> <span class="nx">console</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='log-globals'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/log-globals/log-globals.js'>log-globals.js</a> <a href='#log-globals'>#</a> <small style='float:right'><a href='snippets/log-globals/log-globals.js'>(view raw)</a></small></h3>
<p>Logs your global variables to the console. Useful for finding leaked global variables.</p>
<p><a href="https://github.com/sindresorhus/log-globals">log-globals</a> created by <a href="http://sindresorhus.com">Sindre Sorhus</a>.</p>
<p><a href="snippets/log-globals/log-globals.js"><img src="snippets/log-globals/log-globals.png" alt="screenshot" /></a></p>
</div><div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> log-globals</span>
<span class="cm"> by Sindre Sorhus</span>
<span class="cm"> https://github.com/sindresorhus/log-globals</span>
<span class="cm"> MIT License</span>
<span class="cm">*/</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="s1">'use strict'</span><span class="p">;</span>
<span class="kd">function</span> <span class="nx">getIframe</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">el</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">'iframe'</span><span class="p">);</span>
<span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s1">'none'</span><span class="p">;</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">el</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">win</span> <span class="o">=</span> <span class="nx">el</span><span class="p">.</span><span class="nx">contentWindow</span><span class="p">;</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">removeChild</span><span class="p">(</span><span class="nx">el</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">win</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">detectGlobals</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">iframe</span> <span class="o">=</span> <span class="nx">getIframe</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="kc">null</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">prop</span> <span class="k">in</span> <span class="nb">window</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="p">(</span><span class="nx">prop</span> <span class="k">in</span> <span class="nx">iframe</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">ret</span><span class="p">[</span><span class="nx">prop</span><span class="p">]</span> <span class="o">=</span> <span class="nb">window</span><span class="p">[</span><span class="nx">prop</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">ret</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">detectGlobals</span><span class="p">());</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='overlay'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/overlay/overlay.js'>overlay.js</a> <a href='#overlay'>#</a> <small style='float:right'><a href='snippets/overlay/overlay.js'>(view raw)</a></small></h3>
<p>Add an semi-transparent image overlay over your page to have pixel-perfect integration with your designs.</p>
</div><div class="highlight"><pre><span class="kd">var</span> <span class="nx">storageKey</span> <span class="o">=</span> <span class="s1">'overlay-default'</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">overlayDefault</span> <span class="o">=</span> <span class="nx">localStorage</span><span class="p">.</span><span class="nx">getItem</span><span class="p">(</span><span class="nx">storageKey</span><span class="p">)</span> <span class="o">||</span> <span class="s1">''</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="nx">prompt</span><span class="p">(</span><span class="s1">'paste overlay url'</span><span class="p">,</span> <span class="nx">overlayDefault</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">url</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">localStorage</span><span class="p">.</span><span class="nx">setItem</span><span class="p">(</span><span class="nx">storageKey</span><span class="p">,</span> <span class="nx">url</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">overlay</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">'div'</span><span class="p">);</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">position</span> <span class="o">=</span> <span class="s1">'absolute'</span><span class="p">;</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">left</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">top</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">width</span> <span class="o">=</span> <span class="s1">'100%'</span><span class="p">;</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">height</span><span class="o">=</span><span class="s1">'100%'</span><span class="p">;</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">backgroundImage</span> <span class="o">=</span> <span class="s1">'url('</span> <span class="o">+</span> <span class="nx">url</span> <span class="o">+</span> <span class="s1">')'</span><span class="p">;</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">backgroundSize</span> <span class="o">=</span> <span class="s1">'cover'</span><span class="p">;</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">zIndex</span><span class="o">=</span><span class="mi">10000</span><span class="p">;</span>
<span class="nx">overlay</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">opacity</span> <span class="o">=</span> <span class="mf">0.5</span><span class="p">;</span>
<span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">overlay</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div><div class='snippet-wrapper' id='performance'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/performance/performance.js'>performance.js</a> <a href='#performance'>#</a> <small style='float:right'><a href='snippets/performance/performance.js'>(view raw)</a></small></h3>
<p>Print out information about the <a href="https://developer.mozilla.org/en-US/docs/Navigation_timing">window.performance object</a>. <em>Uses console.table and grouping to organize the information</em>.</p>
<p><a href="snippets/performance/performance.js"><img src="snippets/performance/performance.png" alt="snippets/performance/performance" /></a></p>
</div><div class="highlight"><pre><span class="c1">// performance.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Print out window.performance information.</span>
<span class="c1">// https://developer.mozilla.org/en-US/docs/Navigation_timing</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">t</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">performance</span><span class="p">.</span><span class="nx">timing</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">lt</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">chrome</span> <span class="o">&&</span> <span class="nb">window</span><span class="p">.</span><span class="nx">chrome</span><span class="p">.</span><span class="nx">loadTimes</span> <span class="o">&&</span> <span class="nb">window</span><span class="p">.</span><span class="nx">chrome</span><span class="p">.</span><span class="nx">loadTimes</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">timings</span> <span class="o">=</span> <span class="p">[];</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Time Until Page Loaded"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">loadEventEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">navigationStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Time Until DOMContentLoaded"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">domContentLoadedEventEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">navigationStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Total Response Time"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">responseEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">requestStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Connection"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">connectEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">connectStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Response"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">responseEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">responseStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Domain Lookup"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">domainLookupEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">domainLookupStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Load Event"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">loadEventEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">loadEventStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Unload Event"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">unloadEventEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">unloadEventStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"DOMContentLoaded Event"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">t</span><span class="p">.</span><span class="nx">domContentLoadedEventEnd</span> <span class="o">-</span> <span class="nx">t</span><span class="p">.</span><span class="nx">domContentLoadedEventStart</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="k">if</span><span class="p">(</span><span class="nx">lt</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span><span class="p">(</span><span class="nx">lt</span><span class="p">.</span><span class="nx">wasNpnNegotiated</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"NPN negotiation protocol"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">lt</span><span class="p">.</span><span class="nx">npnNegotiatedProtocol</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"Connection Info"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nx">lt</span><span class="p">.</span><span class="nx">connectionInfo</span>
<span class="p">});</span>
<span class="nx">timings</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">label</span><span class="o">:</span> <span class="s2">"First paint after Document load"</span><span class="p">,</span>
<span class="nx">time</span><span class="o">:</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">ceil</span><span class="p">(</span><span class="nx">lt</span><span class="p">.</span><span class="nx">firstPaintTime</span> <span class="o">-</span> <span class="nx">lt</span><span class="p">.</span><span class="nx">finishDocumentLoadTime</span><span class="p">)</span> <span class="o">+</span> <span class="s2">"ms"</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">navigation</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">performance</span><span class="p">.</span><span class="nx">navigation</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">navigationTypes</span> <span class="o">=</span> <span class="p">{</span> <span class="p">};</span>
<span class="nx">navigationTypes</span><span class="p">[</span><span class="nx">navigation</span><span class="p">.</span><span class="nx">TYPE_NAVIGATENEXT</span> <span class="o">||</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"Navigation started by clicking on a link, or entering the URL in the user agent's address bar, or form submission."</span><span class="p">,</span>
<span class="nx">navigationTypes</span><span class="p">[</span><span class="nx">navigation</span><span class="p">.</span><span class="nx">TYPE_RELOAD</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"Navigation through the reload operation or the location.reload() method."</span><span class="p">,</span>
<span class="nx">navigationTypes</span><span class="p">[</span><span class="nx">navigation</span><span class="p">.</span><span class="nx">TYPE_BACK_FORWARD</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"Navigation through a history traversal operation."</span><span class="p">,</span>
<span class="nx">navigationTypes</span><span class="p">[</span><span class="nx">navigation</span><span class="p">.</span><span class="nx">TYPE_UNDEFINED</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"Navigation type is undefined."</span><span class="p">,</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"window.performance"</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">performance</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"Navigation Information"</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">navigationTypes</span><span class="p">[</span><span class="nx">navigation</span><span class="p">.</span><span class="nx">type</span><span class="p">]);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Number of redirects that have taken place: "</span><span class="p">,</span> <span class="nx">navigation</span><span class="p">.</span><span class="nx">redirectCount</span><span class="p">)</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">(</span><span class="s2">"Navigation Information"</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"Timing"</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">performance</span><span class="p">.</span><span class="nx">timing</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">table</span><span class="p">(</span><span class="nx">timings</span><span class="p">,</span> <span class="p">[</span><span class="s2">"label"</span><span class="p">,</span> <span class="s2">"time"</span><span class="p">]);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">(</span><span class="s2">"Timing"</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">(</span><span class="s2">"window.performance"</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='plainforms'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/plainforms/plainforms.js'>plainforms.js</a> <a href='#plainforms'>#</a> <small style='float:right'><a href='snippets/plainforms/plainforms.js'>(view raw)</a></small></h3>
<p>HTML5 Forms are great, but sometimes you don’t want the browser to validate or present special controls for them. For instance, if you want to test server-side validation of some fields, you do not want the browser to prevent invalid data for that field type. This snippet finds all of the HTML5 input elements, sets their type attributes to “text” (and keeps any values that were set), and removes any validations enforced by the browser. Implementation by <a href="https://github.com/stroebjo">stroebjo</a>.</p>
<p><a href="snippets/plainforms/plainforms.js"><img src="snippets/plainforms/plainforms.gif" alt="snippets/plainforms/plainforms" /></a></p>
</div><div class="highlight"><pre><span class="c1">// plainforms.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Remove HTML5 form features (validations and special input types).</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="p">[</span><span class="s1">'maxlength'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'pattern'</span><span class="p">,</span> <span class="s1">'step'</span> <span class="p">].</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
<span class="p">[].</span><span class="nx">forEach</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s2">"["</span> <span class="o">+</span> <span class="nx">attr</span> <span class="o">+</span> <span class="s2">"]"</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">removeAttribute</span><span class="p">(</span><span class="nx">attr</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="p">[</span><span class="s1">'tel'</span><span class="p">,</span> <span class="s1">'url'</span><span class="p">,</span> <span class="s1">'email'</span><span class="p">,</span> <span class="s1">'datetime'</span><span class="p">,</span> <span class="s1">'date'</span><span class="p">,</span> <span class="s1">'month'</span><span class="p">,</span> <span class="s1">'week'</span><span class="p">,</span> <span class="s1">'time'</span><span class="p">,</span> <span class="s1">'datetime-local'</span><span class="p">,</span> <span class="s1">'number'</span><span class="p">,</span> <span class="s1">'range'</span><span class="p">,</span> <span class="s1">'color'</span><span class="p">].</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
<span class="p">[].</span><span class="nx">forEach</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s2">"input[type="</span> <span class="o">+</span> <span class="nx">type</span> <span class="o">+</span> <span class="s2">"]"</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">'type'</span><span class="p">,</span> <span class="s1">'text'</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">info</span><span class="p">(</span><span class="s2">"All HTML5 form validations have been removed."</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='querystringvalues'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/querystringvalues/querystringvalues.js'>querystringvalues.js</a> <a href='#querystringvalues'>#</a> <small style='float:right'><a href='snippets/querystringvalues/querystringvalues.js'>(view raw)</a></small></h3>
<p>Print a table of query string (GET) values. This can be helpful, especially when trying to read the values from a long or complicated URL that may otherwise need to be pasted into another editor to read. Implementation by <a href="https://github.com/mattpass">mattpass</a>.</p>
<p><a href="snippets/querystringvalues/querystringvalues.js"><img src="snippets/querystringvalues/querystringvalues.png" alt="snippets/querystringvalues/querystringvalues" /></a></p>
</div><div class="highlight"><pre><span class="c1">// querystringvalues.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Print out key/value pairs from querystring.</span>
<span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="nx">location</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">querystring</span> <span class="o">=</span> <span class="nx">location</span><span class="p">.</span><span class="nx">search</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">tab</span> <span class="o">=</span> <span class="nx">querystring</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"&"</span><span class="p">).</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">qs</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">{</span> <span class="s2">"Key"</span><span class="o">:</span> <span class="nx">qs</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> <span class="s2">"Value"</span><span class="o">:</span> <span class="nx">qs</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)[</span><span class="mi">1</span><span class="p">],</span> <span class="s2">"Pretty Value"</span><span class="o">:</span> <span class="nb">decodeURIComponent</span><span class="p">(</span><span class="nx">qs</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)[</span><span class="mi">1</span><span class="p">]).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">//g</span><span class="p">,</span><span class="s2">" "</span><span class="p">)</span> <span class="p">}</span>
<span class="p">});</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"Querystring Values"</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"URL: "</span><span class="o">+</span><span class="nx">url</span><span class="o">+</span><span class="s2">"\nQS: "</span><span class="o">+</span><span class="nx">querystring</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">table</span><span class="p">(</span><span class="nx">tab</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">(</span><span class="s2">"Querystring Values"</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='showheaders'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/showheaders/showheaders.js'>showheaders.js</a> <a href='#showheaders'>#</a> <small style='float:right'><a href='snippets/showheaders/showheaders.js'>(view raw)</a></small></h3>
<p>Pretty prints the HTTP headers for the current page into the console. <em>Uses console.table</em>.</p>
<p><a href="snippets/showheaders/showheaders.js"><img src="snippets/showheaders/showheaders.png" alt="snippets/showheaders/showheaders" /></a></p>
</div><div class="highlight"><pre><span class="c1">// showheaders.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Print out response headers for current URL.</span>
<span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">request</span><span class="o">=</span><span class="k">new</span> <span class="nx">XMLHttpRequest</span><span class="p">();</span>
<span class="nx">request</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="s1">'HEAD'</span><span class="p">,</span><span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">,</span><span class="kc">true</span><span class="p">);</span>
<span class="nx">request</span><span class="p">.</span><span class="nx">onload</span> <span class="o">=</span> <span class="nx">request</span><span class="p">.</span><span class="nx">onerror</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">headers</span> <span class="o">=</span> <span class="nx">request</span><span class="p">.</span><span class="nx">getAllResponseHeaders</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">tab</span> <span class="o">=</span> <span class="nx">headers</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"\n"</span><span class="p">).</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">h</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">{</span> <span class="s2">"Key"</span><span class="o">:</span> <span class="nx">h</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">": "</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> <span class="s2">"Value"</span><span class="o">:</span> <span class="nx">h</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">": "</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span> <span class="p">}</span>
<span class="p">}).</span><span class="nx">filter</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">h</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">h</span><span class="p">.</span><span class="nx">Value</span> <span class="o">!==</span> <span class="kc">undefined</span><span class="p">;</span> <span class="p">});</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">group</span><span class="p">(</span><span class="s2">"Request Headers"</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">headers</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">table</span><span class="p">(</span><span class="nx">tab</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">groupEnd</span><span class="p">(</span><span class="s2">"Request Headers"</span><span class="p">);</span>
<span class="p">};</span>
<span class="nx">request</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="kc">null</span><span class="p">);</span>
<span class="p">})();</span>
</pre></div>
</div><div class='snippet-wrapper' id='viewcookies'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/viewcookies/viewcookies.js'>viewcookies.js</a> <a href='#viewcookies'>#</a> <small style='float:right'><a href='snippets/viewcookies/viewcookies.js'>(view raw)</a></small></h3>
<p>Shows all cookies stored in document.cookies in a console.table.</p>
<p><a href="snippets/viewcookies/viewcookies.js"><img src="snippets/viewcookies/viewcookies.png" alt="snippets/viewcookies/viewcookies" /></a></p>
</div><div class="highlight"><pre><span class="c1">// viewcookies.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Shows all cookies stored in document.cookies in a console.table</span>
<span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="s1">'use strict'</span><span class="p">;</span>
<span class="nb">window</span><span class="p">.</span><span class="nx">viewCookies</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">cookie</span><span class="p">)</span> <span class="p">{</span>
<span class="kr">const</span> <span class="nx">cookies</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">cookie</span>
<span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="sr">/; ?/</span><span class="p">)</span>
<span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">s</span> <span class="o">=></span> <span class="p">{</span>
<span class="kr">const</span> <span class="p">[</span> <span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span> <span class="p">]</span> <span class="o">=</span> <span class="nx">s</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/^(.*?)=(.*)$/</span><span class="p">);</span>
<span class="k">return</span> <span class="p">{</span>
<span class="nx">key</span><span class="p">,</span>
<span class="nx">value</span><span class="o">:</span> <span class="nb">decodeURIComponent</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span>
<span class="p">};</span>
<span class="p">});</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">table</span><span class="p">(</span><span class="nx">cookies</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">warn</span><span class="p">(</span><span class="s1">'document.cookie is empty!'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="p">})();</span>
<span class="nb">window</span><span class="p">.</span><span class="nx">viewCookies</span><span class="p">();</span>
</pre></div>
</div><div class='snippet-wrapper' id='wrapelement'><div class='snippet'><h3><a href='https://github.com/bgrins/devtools-snippets/tree/master/snippets/wrapelement/wrapelement.js'>wrapelement.js</a> <a href='#wrapelement'>#</a> <small style='float:right'><a href='snippets/wrapelement/wrapelement.js'>(view raw)</a></small></h3>
<p>Exposes a window function <code>wrapElement(element, tag)</code>. The first parameter is either a DOM Node, or a selector string, and the second parameter is the tag name for the wrapping element. Implementation by <a href="https://github.com/gkatsev">gkatsev</a>.</p>
<p><a href="snippets/wrapelement/wrapelement.js"><img src="snippets/wrapelement/wrapelement.png" alt="snippets/wrapelement/wrapelement" /></a></p>
</div><div class="highlight"><pre><span class="c1">// wrapelement.js</span>
<span class="c1">// https://github.com/bgrins/devtools-snippets</span>
<span class="c1">// Wrap a given element in a given type of element</span>
<span class="c1">// wrapElement('.foo', 'h1');</span>