How to use parseHTML method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

fromhtml.js

Source: fromhtml.js Github

copy
1/* bender-tags: editor */
2
3function parseHtml( raw, parent ) {
4	var fragment = CKEDITOR.htmlParser.fragment.fromHtml( raw, parent || 'body', 'p' ),
5		writer = new CKEDITOR.htmlParser.basicWriter();
6
7	fragment.writeChildrenHtml( writer );
8	return writer.getHtml( true );
9}
10
11bender.test( {
12	test_parser_1: function() {
13		assert.areSame( '<p><b>2</b> Test</p><table><tr><td>1</td><td>3</td></tr></table>',
14						parseHtml( '<table><tr><td>1</td><p><b>2</b> Test</p><td>3</td></tr></table>' ) );
15	},
16
17	test_parser_2: function() {
18		assert.areSame( '<table><tr><td><b>1</b></td><td><b>2</b></td></tr></table>',
19						parseHtml( '<b><table><tr><td>1</td><td>2</td></tr></table></b>' ) );
20	},
21
22	test_parser_3_1: function() {
23		assert.areSame( '<p><b><i>Table:</i></b></p><table><tr><td><b><i>1</i></b></td><td><b><i>2</i></b></td></tr></table>',
24						parseHtml(	'<b><i>Table:<table><tr><td>1</td><td>2</td></tr></table></i></b>' ) );
25	},
26
27	test_parser_3_2: function() {
28		assert.areSame( '<table><tr><td><b><i>1</i></b></td><td><b><i>2</i></b></td></tr></table><p><b><i>Table</i></b></p>',
29						parseHtml(	'<b><i><table><tr><td>1</td><td>2</td></tr></table>Table</i></b>' ) );
30	},
31
32	test_parser_4: function() {
33		assert.areSame( '<p><b><i>Test</i></b></p>',
34						parseHtml( '<b><i>Test' ) );
35	},
36
37	test_parser_5: function() {
38		assert.areSame( '<p>Para 1</p><p>Para 2</p><p>Para 3</p>',
39						parseHtml( '<p>Para 1<p>Para 2<p>Para 3' ) );
40	},
41
42	test_parser_6: function() {
43		assert.areSame( '<p><b>A</b><i>B</i></p>',
44						parseHtml( '<b>A</b><i>B</i>' ) );
45	},
46
47	test_parser_7: function() {
48		assert.areSame( '<p>Para 1</p><hr /><p>Para 2</p><h1>Para 3</h1>',
49						parseHtml( '<p>Para 1<hr>Para 2<h1>Para 3' ) );
50	},
51
52	/**
53	 * Test remove empty inline element.
54	 */
55	test_parser_8: function() {
56		assert.areSame( '<p>text</p>',
57						parseHtml( '<p><b></b>text</p>' ) );
58	},
59
60	/**
61	 *  Test remove multiple empty inline elements.
62	 */
63	test_parser_8_2: function() {
64		assert.areSame( '<p>text</p>',
65						parseHtml( '<p><b><i></b></i>text</p>' ) );
66	},
67
68	/**
69	 *  Test remove empty links.
70	 */
71	test_parser_8_3: function() {
72		assert.areSame( '<p>test</p>',
73						parseHtml( '<p>test<a href="foo"><a href="bar"></p>' ) );
74	},
75
76	/**
77	 *  Test keep empty anchors.
78	 */
79	test_parser_8_4: function() {
80		assert.areSame( '<p>test<a name="foo"></a><a name="bar"></a></p>',
81						parseHtml( '<p>test<a name="foo"><a name="bar"></p>' ) );
82
83	},
84
85	/**
86	 * Test fixing malformed inline element closing.
87	 */
88	test_parser_9: function() {
89		assert.areSame( '<p><b>bold<i>ita</i></b><i>lic</i></p>',
90						parseHtml( '<p><b>bold<i>ita</b>lic</i></p>' ) );
91
92	},
93
94	test_parser_10: function() {
95		assert.areSame( '<table><tbody><tr><td>A</td></tr></tbody></table>',
96						parseHtml( '<table><tbody><tr><td>A<b></b></td></tr></tbody></table>' ) );
97	},
98
99	/*
100	 *  Leaving table internals intact.
101	 */
102	test_parser_11: function() {
103		assert.areSame( '<td>1</td><tr><td>2</td></tr>',
104						parseHtml( '<td>1</td><tr><td>2</td></tr>' ) );
105	},
106
107	/*
108	 *  Forward lifting invalid table children..
109	 */
110	test_parser_12: function() {
111		assert.areSame( '<p>p1</p><p>p2</p><table><tr><td>c1</td></tr></table>',
112						parseHtml( '<table><p>p1</p><tr><td>c1</td></tr><p>p2</p></table>' ) );
113	},
114
115	/**
116	 * Test fixing malformed nested list structure. (https://dev.ckeditor.com/ticket/3828)
117	 */
118	test_parser_13: function() {
119		assert.areSame( '<ul><li><ol></ol></li></ul>',
120						parseHtml( '<ul><ol></ol></ul>' ) );
121		assert.areSame( '<ul><li>level1<ul><li>level2<ul><li>level3</li></ul></li></ul></li></ul>',
122						parseHtml( '<ul><li>level1</li><ul><li>level2</li><ul><li>level3</li></ul></ul></ul>' ) );
123	},
124
125	/**
126	 * Test fixing orphan list items twice.
127	 */
128	test_parser_14: function() {
129		assert.areSame( '<ul><li>1</li></ul><dl><dt>2</dt><dd>3</dd></dl>',
130						parseHtml( '<li>1</li><dt>2</dt><dd>3</dd>' ) );
131
132		assert.areSame( '<ul><li>1</li></ul><dl><dt>2</dt></dl>',
133						parseHtml( '<li>1</li><dt>2</dt></ol>' ) );
134	},
135
136	/**
137	 * Test fixing orphan definition list items.
138	 */
139	test_parser_14b: function() {
140		assert.areSame( '<dl><dt><p>foo</p></dt><dd><p>bar</p></dd></dl>', parseHtml( '<dt><p>foo</p></dt><dd><p>bar</p></dd>' ) );
141		assert.areSame( '<dl><dt>foo</dt></dl><td>bar</td>', parseHtml( '<dt><td>bar</td>foo</dt>' ) );
142	},
143
144	/**
145	 * Test fix body + optional close.
146	 */
147	test_parser_15: function() {
148		assert.areSame( '<p><br /></p>', parseHtml( '<br />' ) );
149		assert.areSame( '<p><img /></p>', parseHtml( '<img /></p>' ) );
150		assert.areSame( '<p><b>bold</b></p>', parseHtml( '<b>bold</p>' ) );
151		assert.areSame( '<p>p1</p>', parseHtml( '<p>p1</div>' ) );
152	},
153
154	/**
155	 * Test auto paragrahing with different contexts.
156	 */
157	'test auto paragraphing': function() {
158		var editables = [ 'body', 'div', 'h1', 'table' ], ct, dtd, msg;
159		for ( var i = 0 ; i < editables.length ; i++ ) {
160			ct = editables[ i ];
161			dtd = CKEDITOR.dtd[ ct ];
162			msg = 'auto paragraphing for editable: ' + ct;
163
164			if ( dtd.p )
165				assert.areSame( '<p>foo</p>', parseHtml( 'foo', ct ), msg );
166			else if ( ct == 'table' )
167				assert.areSame( '<tbody><tr><td>foo</td></tr></tbody>', parseHtml( 'foo', ct ), msg );
168			else
169				assert.areSame( 'foo', parseHtml( 'foo', ct ), msg );
170		}
171	},
172
173	'test whitespaces handling': function() {
174		var source = '\n foo  ',
175			output = '<p>foo</p>';
176		assert.areSame( output,			parseHtml( source ),				'default context' );
177		assert.areSame( output,			parseHtml( source, 'body' ),		'body context' );
178		assert.areSame( output,			parseHtml( source, 'div' ),			'div context' );
179		assert.areSame( output,			parseHtml( source, 'figcaption' ),	'figcaption context' );
180		assert.areSame( 'foo',			parseHtml( source, 'p' ),			'p context' );
181
182
183		source = '\n <p>foo</p>  ';
184		assert.areSame( output,			parseHtml( source ),				'default context - block edges' );
185		assert.areSame( output,			parseHtml( source, 'body' ),		'body context - block edges' );
186		assert.areSame( output,			parseHtml( source, 'div' ),			'div context - block edges' );
187		assert.areSame( output,			parseHtml( source, 'figcaption' ),	'figcaption context - block edges' );
188
189
190		source = '<p>foo</p> \n <p>bar</p>';
191		output = '<p>foo</p><p>bar</p>';
192		assert.areSame( output,			parseHtml( source ),				'default context - between blocks' );
193		assert.areSame( output,			parseHtml( source, 'body' ),		'body context - between blocks' );
194		assert.areSame( output,			parseHtml( source, 'div' ),			'div context - between blocks' );
195		assert.areSame( output,			parseHtml( source, 'figcaption' ),	'figcaption context - between blocks' );
196	},
197
198	// Test whitespaces handling in different context. (https://dev.ckeditor.com/ticket/3715)
199	'parse pre-formatted contents': function() {
200		var pre = '<pre>\t\tfoo\nbar quz  \n</pre>',
201			textarea = '<p><textarea>\t\tfoo\nbar quz  \n</textarea></p>';
202
203		assert.areSame( pre, parseHtml( pre ) );
204		assert.areSame( textarea, parseHtml( textarea ) );
205		assert.areSame( '<p><b>foo bar</b></p>', parseHtml( '<p><b>foo   bar</b></p>' ) );
206	},
207
208
209	'parse list and table contents (with context)': function() {
210		// Given the list/table as the parent element, parser should not attempt
211		// to fix partial content.
212		var source = '<li>foo</li><li>bar</li>';
213		assert.areSame( source, parseHtml( source, 'ul' ) );
214
215		source = '<li>foo</li><li>bar</li>';
216		assert.areSame( source, parseHtml( '<li>foo</li><li>bar</li>', 'ol' ) );
217
218		source = '<dt>foo</dt><dd>bar</dd>';
219		assert.areSame( source, parseHtml( '<dt>foo</dt><dd>bar</dd>', 'dl' ) );
220
221		source = '<tr><td>foo</td><td>bar</td></tr>';
222		assert.areSame( source, parseHtml( '<tr><td>foo</td><td>bar</td></tr>', 'table' ) );
223
224		source = '<tbody><tr><td>foo</td><td>bar</td></tr></tbody>';
225		assert.areSame( source, parseHtml( '<tbody><tr><td>foo</td><td>bar</td></tr></tbody>', 'table' ) );
226
227		source = '<caption>foo</caption>';
228		assert.areSame( source, parseHtml( '<caption>foo</caption>', 'table' ) );
229	},
230
231	'parse pre and textarea contents (with context)': function() {
232		// Given the pre/textarea as context, parser should preserve all white spaces.
233		var source = '\t\tfoo\nbar quz  \n';
234
235		assert.areSame( source, parseHtml( source, 'pre' ) );
236		assert.areSame( source, parseHtml( source, 'textarea' ) );
237	},
238
239	'parser orphan text in list/table.': function() {
240		assert.areSame( '<ul><li><strong>foo</strong>bar</li></ul>',
241						parseHtml( '<ul><strong>foo</strong>bar</ul>' ) );
242		assert.areSame( '<ul><li>foo</li><li>bar</li></ul>',
243						parseHtml( '<ul>foo<li>bar</li></ul>' ) );
244		assert.areSame( '<table><tbody><tr><td><strong>foo</strong>bar</td></tr></tbody></table>',
245						parseHtml( '<table><strong>foo</strong>bar</table>' ) );
246		assert.areSame( '<table><tbody><tr><td><strong>foo</strong></td><td>bar</td></tr></tbody></table>',
247						parseHtml( '<table><strong>foo</strong><td>bar</td></table>' ) );
248		assert.areSame( '<table><tbody><tr><td><strong>foo</strong></td></tr><tr><td>bar</td></tr></tbody></table>',
249						parseHtml( '<table><strong>foo</strong><tr>bar</tr></table>' ) );
250		assert.areSame( '<tr><td>foo</td></tr>', parseHtml( '<tr>foo</tr>' ) );
251
252		// https://dev.ckeditor.com/ticket/11660
253		assert.areSame( '<table><tbody><tr><td>1</td></tr><tr><td>Issue2</td></tr><tr><td>3</td></tr></tbody></table>',
254			parseHtml( '<table><tbody><tr><td>1</td></tr>Issue2<tr><td>3</td></tr></tbody></table>' ) );
255	},
256
257	'test parser fix inline outside of block element': function() {
258		assert.areSame( '<p>Line 1</p><p><b>Line 2</b></p><p><b>Line 3</b></p><p><b>Line 4</b></p><p>Line 5</p>',
259						parseHtml( '<p>Line 1</p><b><p>Line 2</p><p>Line 3</p><p>Line 4</p></b><p>Line 5</p>' ) );
260	},
261
262	/**
263	 *  Test fixing paragraph inside table row.
264	 */
265	test_ticket_3195: function() {
266		assert.areSame( '<p>2</p><table><tr><td>1</td><td>3</td></tr></table>',
267						parseHtml( '<table><tr><td>1</td><p>2</p><td>3</td></tr></table>' ) );
268	},
269
270	/**
271	 *  Test fixing paragraph inside list.
272	 */
273	test_ticket_3195_2: function() {
274		assert.areSame( '<p>2</p><ul><li>1</li><li>3</li></ul>',
275						parseHtml( '<ul><li>1</li><p>2</p><li>3</li></ul>' ) );
276	},
277
278	/**
279	 *  Test fixing 'div' inside paragraph.
280	 */
281	test_ticket_3195_3: function() {
282		assert.areSame( '<p>1</p><div>2</div><p><span>3</span></p>',
283						parseHtml( '<p>1<div>2</div><span>3</span></p>' ) );
284	},
285
286	test_ticket_3441: function() {
287		assert.areSame( '<p><b>Test</b></p><script type="test">var a = "<A Href=xxx>Testing</ A>";\nGo();<\/script>',
288						parseHtml( '<p><b>Test</b></p><script type="test">var a = "<A Href=xxx>Testing</ A>";\nGo();<\/script>' ) );
289	},
290
291	test_ticket_3585: function() {
292		assert.areSame( '<p><br /></p>', parseHtml( '<p><br />\t\r\n</p>' ) );
293	},
294
295	test_ticket_3585_1: function() {
296		assert.areSame( '<p><br />text</p>', parseHtml( '<p><br />text\t\r\n</p>' ) );
297	},
298
299	test_ticket_3585_2: function() {
300		assert.areSame( '<p><b>inline </b></p><p>paragraph</p>', parseHtml( '<b>inline </b>\n<p>paragraph\t\r\n</p>\t\r\n' ) );
301	},
302
303	test_ticket_3744: function() {
304		assert.areSame( '<div><b><font><span>A</span></font></b></div><div>X</div>',
305						parseHtml( '<div><b><font><span>A</font></span></b></div><div>X</div>' ) );
306	},
307
308	// https://dev.ckeditor.com/ticket/3862
309	'test not breaking on malformed close tag': function() {
310		assert.areSame(
311			'<p><span><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a>' +
312			'<a><b>test</b></a><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a>' +
313			'<a><b>test</b></a><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a><a><b>test</b></a>' +
314			'<a><b>test</b></a></span></p>',
315			parseHtml(
316				'<p><span><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b>' +
317				'<a><b>test</a></b><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b>' +
318				'<a><b>test</a></b><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b><a><b>test</a></b>' +
319				'<a><b>test</a></b></span></p>'
320			)
321		);
322	},
323
324
325	test_ticket_5788: function() {
326		assert.areSame( '<p>test<br />whitespace</p>', parseHtml( '<p>test<br /> whitespace</p>' ) );
327		assert.areSame( '<div><p>paragraph</p>pseudo</div>', parseHtml( '<div><p>paragraph</p> pseudo</div>' ) );
328		assert.areSame( '<div>pseudo<p>paragraph</p></div>', parseHtml( '<div>pseudo <p>paragraph</p></div>' ) );
329	},
330
331	// https://dev.ckeditor.com/ticket/5626
332	'test parser fix partial list items': function() {
333		assert.areSame( '<table><tr><td><ul><li>item1</li><li>item2</li></ul></td></tr></table>',
334						parseHtml( '<table><tr><td><li>item1</li><li>item2</li></td></tr></table>' ) );
335		assert.areSame( '<body><p>text</p><ul><li>cell</li></ul></body>',
336						parseHtml( '<body>text<li>cell</li></body>', 'html' ) );
337		assert.areSame( '<ul><li>item1</li><li>item2</li></ul>',
338						parseHtml( '<li>item1</li><li>item2</li>' ) );
339		assert.areSame( '<dl><dd>test</dd><dd>test</dd></dl>',
340						parseHtml( '<dd>test</dd><dd>test</dd>' ) );
341	},
342
343	// https://dev.ckeditor.com/ticket/5626
344	'test parser *NOT* fixing orphan table cells': function() {
345		assert.areSame( '<td>td1</td><p>text</p>',
346						parseHtml( '<td>td1</td>text' ) );
347		assert.areSame( '<tr><td>td1</td></tr><ul><li>li1</li></ul>',
348						parseHtml( '<ul><tr><td>td1</td></tr><li>li1</li></ul>' ) );
349	},
350
351	// https://dev.ckeditor.com/ticket/5626
352	'test parser fix malformed table cell/list item': function() {
353		assert.areSame( '<table><tr><td>cell1</td><td>cell2</td></tr></table>',
354						parseHtml( '<table><tr><td>cell1<td>cell2</td></td></tr></table>' ) );
355		assert.areSame( '<ul><li>item1</li><li>item2</li></ul>',
356						parseHtml( '<ul><li>item1<li>item2</li></li></ul>' ) );
357	},
358
359	// https://dev.ckeditor.com/ticket/7894
360	'test parser fix malformed link': function() {
361		assert.areSame( '<p>foo<a href="#2">bar</a></p><p>foo bar</p>',
362						parseHtml( '<p>foo<a href="#1"><a href="#2">bar</a></p> <p>foo</a> bar</p>' ) );
363	},
364
365	'test whitespace between comments': function() {
366		var source = '<i>foo<!--1--> <!--2-->bar</i>';
367		assert.areSame( source, parseHtml( source, 'p' ) );
368	},
369
370	'test *NOT* removing empty inline when comment enclosed': function() {
371		assert.areSame( '<p><span><!--comment--></span></p>', parseHtml( '<p><span><!--comment--></span></p>' ) );
372
373	},
374
375	'test fragment#writeChildrenHtml': function() {
376		var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<p>A<b>B<i>C</i></b></p>' ),
377			writer = new CKEDITOR.htmlParser.basicWriter(),
378			filter = new CKEDITOR.htmlParser.filter();
379
380		filter.addRules( {
381			root: function( element ) {
382				var div = CKEDITOR.htmlParser.fragment.fromHtml( 'X', 'div' );
383				div.insertAfter( element.children[ 0 ] ); // Insert after p.
384			},
385
386			elements: {
387				$: function( element ) {
388					element.attributes.x = '1';
389				}
390			}
391		} );
392
393		fragment.writeChildrenHtml( writer );
394		assert.areSame( '<p>A<b>B<i>C</i></b></p>', writer.getHtml( true ) );
395
396		fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<p>A<b>B<i>C</i></b></p>' );
397		fragment.writeChildrenHtml( writer, filter );
398		assert.areSame( '<p x="1">A<b x="1">B<i x="1">C</i></b></p>', writer.getHtml( true ) );
399
400		fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<p>A<b>B<i>C</i></b></p>' );
401		fragment.writeChildrenHtml( writer, filter, true );
402		assert.areSame( '<p x="1">A<b x="1">B<i x="1">C</i></b></p><div x="1">X</div>', writer.getHtml( true ) );
403	}
404} );
405
Full Screen

jqfuck_stable.js

Source: jqfuck_stable.js Github

copy
1/*! JQFuck 0.1.0 - http://jsfuck.com */
2
3(function(self){
4
5  var JQ_PREFIX = 'jQuery';
6  var USE_CHAR_CODE = "USE_CHAR_CODE";
7
8  var MIN = 32, MAX = 126;
9
10  var SIMPLE = {
11    'false':      'jQuery.isPlainObject()',
12    'true':       'jQuery.isEmptyObject()',
13    'undefined':  'jQuery.proxy()',
14    'NaN':        '+[!jQuery.parseHTML()]',
15    'Infinity':   '+(+!+jQuery.parseHTML()+(!+jQuery.parseHTML()+jQuery.parseHTML())[!+jQuery.parseHTML()+!+jQuery.parseHTML()+!+jQuery.parseHTML()]+[+!+jQuery.parseHTML()]+[+jQuery.parseHTML()]+[+jQuery.parseHTML()]+[+jQuery.parseHTML()])' // +"1e1000"
16  };
17
18  var CONSTRUCTORS = {
19    'Array':    'jQuery.parseHTML()',
20    'Number':   '(+jQuery.parseHTML())',
21    'String':   '(jQuery.parseHTML()+jQuery.parseHTML())',
22    'Boolean':  '(!jQuery.parseHTML())',
23    'Function': 'jQuery.parseHTML()["fill"]',
24    'RegExp':   'Function("return/"+false+"/")()'
25  };
26
27  var MAPPING = {
28    'a':   '(false+"")[1]',
29    'b':   '(jQuery.parseHTML()["entries"]()+"")[2]',
30    'c':   '(jQuery.parseHTML()["fill"]+"")[3]',
31    'd':   '(undefined+"")[2]',
32    'e':   '(true+"")[3]',
33    'f':   '(false+"")[0]',
34    'g':   '(false+[0]+String)[20]',
35    'h':   '(+(101))["to"+String["name"]](21)[1]',
36    'i':   '([false]+undefined)[10]',
37    'j':   '(jQuery.parseHTML()["entries"]()+"")[3]',
38    'k':   '(+(20))["to"+String["name"]](21)',
39    'l':   '(false+"")[2]',
40    'm':   '(Number+"")[11]',
41    'n':   '(undefined+"")[1]',
42    'o':   '(true+jQuery.parseHTML()["fill"])[10]',
43    'p':   '(+(211))["to"+String["name"]](31)[1]',
44    'q':   '(+(212))["to"+String["name"]](31)[1]',
45    'r':   '(true+"")[1]',
46    's':   '(false+"")[3]',
47    't':   '(true+"")[0]',
48    'u':   '(undefined+"")[0]',
49    'v':   '(+(31))["to"+String["name"]](32)',
50    'w':   '(+(32))["to"+String["name"]](33)',
51    'x':   '(+(101))["to"+String["name"]](34)[1]',
52    'y':   '(NaN+[Infinity])[10]',
53    'z':   '(+(35))["to"+String["name"]](36)',
54
55    'A':   '(+jQuery.parseHTML()+Array)[10]',
56    'B':   '(+jQuery.parseHTML()+Boolean)[10]',
57    'C':   'Function("return escape")()(("")["italics"]())[2]',
58    'D':   'Function("return escape")()(jQuery.parseHTML()["fill"])["slice"]("-1")',
59    'E':   '(RegExp+"")[12]',
60    'F':   '(+jQuery.parseHTML()+Function)[10]',
61    'G':   '(false+Function("return Date")()())[30]',
62    'H':   USE_CHAR_CODE,
63    'I':   '(Infinity+"")[0]',
64    'J':   USE_CHAR_CODE,
65    'K':   USE_CHAR_CODE,
66    'L':   USE_CHAR_CODE,
67    'M':   '(true+Function("return Date")()())[30]',
68    'N':   '(NaN+"")[0]',
69    'O':   '(NaN+Function("return{}")())[11]',
70    'P':   USE_CHAR_CODE,
71    'Q':   USE_CHAR_CODE,
72    'R':   '(+jQuery.parseHTML()+RegExp)[10]',
73    'S':   '(+jQuery.parseHTML()+String)[10]',
74    'T':   '(NaN+Function("return Date")()())[30]',
75    'U':   '(NaN+Function("return{}")()["to"+String["name"]]["call"]())[11]',
76    'V':   USE_CHAR_CODE,
77    'W':   USE_CHAR_CODE,
78    'X':   USE_CHAR_CODE,
79    'Y':   USE_CHAR_CODE,
80    'Z':   USE_CHAR_CODE,
81
82    ' ':   '(NaN+jQuery.parseHTML()["fill"])[11]',
83    '!':   USE_CHAR_CODE,
84    '"':   '("")["fontcolor"]()[12]',
85    '#':   USE_CHAR_CODE,
86    '$':   USE_CHAR_CODE,
87    '%':   'Function("return escape")()(jQuery.parseHTML()["fill"])[21]',
88    '&':   '("")["link"](0+")[10]',
89    '\'':  USE_CHAR_CODE,
90    '(':   '(undefined+jQuery.parseHTML()["fill"])[22]',
91    ')':   '([0]+false+jQuery.parseHTML()["fill"])[20]',
92    '*':   USE_CHAR_CODE,
93    '+':   '(+(+!+jQuery.parseHTML()+(!+jQuery.parseHTML()+jQuery.parseHTML())[!+jQuery.parseHTML()+!+jQuery.parseHTML()+!+jQuery.parseHTML()]+[+!+jQuery.parseHTML()]+[+jQuery.parseHTML()]+[+jQuery.parseHTML()])+jQuery.parseHTML())[2]',
94    ',':   '(jQuery.parseHTML()["slice"]["call"](false+"")+"")[1]',
95    '-':   '(+(.+[0000000001])+"")[2]',
96    '.':   '(+(+!+jQuery.parseHTML()+[+!+jQuery.parseHTML()]+(!!jQuery.parseHTML()+jQuery.parseHTML())[!+jQuery.parseHTML()+!+jQuery.parseHTML()+!+jQuery.parseHTML()]+[!+jQuery.parseHTML()+!+jQuery.parseHTML()]+[+jQuery.parseHTML()])+jQuery.parseHTML())[+!+jQuery.parseHTML()]',
97    '/':   '(false+[0])["italics"]()[10]',
98    ':':   '(RegExp()+"")[3]',
99    ';':   '("")["link"](")[14]',
100    '<':   '("")["italics"]()[0]',
101    '=':   '("")["fontcolor"]()[11]',
102    '>':   '("")["italics"]()[2]',
103    '?':   '(RegExp()+"")[2]',
104    '@':   USE_CHAR_CODE,
105    '[':   '(jQuery.parseHTML()["entries"]()+"")[0]',
106    '\\':  USE_CHAR_CODE,
107    ']':   '(jQuery.parseHTML()["entries"]()+"")[22]',
108    '^':   USE_CHAR_CODE,
109    '_':   USE_CHAR_CODE,
110    '`':   USE_CHAR_CODE,
111    '{':   '(true+jQuery.parseHTML()["fill"])[20]',
112    '|':   USE_CHAR_CODE,
113    '}':   '(jQuery.parseHTML()["fill"]+"")["slice"]("-1")',
114    '~':   USE_CHAR_CODE
115  };
116
117  var GLOBAL = 'Function("return this")()';
118
119  function fillMissingChars(){
120    for (var key in MAPPING){
121      if (MAPPING[key] === USE_CHAR_CODE){
122        MAPPING[key] = 'Function("return unescape")()("%"'+ key.charCodeAt(0).toString(16).replace(/(\d+)/g, "+($1)+\"") + '")';
123      }
124    }
125  }
126
127  function fillMissingDigits(){
128    var output, number, i;
129
130    for (number = 0; number < 10; number++){
131
132      output = "+jQuery.parseHTML()";
133
134      if (number > 0){ output = "+!" + output; }
135      for (i = 1; i < number; i++){ output = "+!+jQuery.parseHTML()" + output; }
136      if (number > 1){ output = output.substr(1); }
137
138      MAPPING[number] = "[" + output + "]";
139    }
140  }
141
142  function replaceMap(){
143    var character = "", value, original, i, key;
144
145    function replace(pattern, replacement){
146      value = value.replace(
147        new RegExp(pattern, "gi"),
148        replacement
149      );
150    }
151
152    function digitReplacer(_,x) { return MAPPING[x]; }
153
154    function numberReplacer(_,y) {
155      var values = y.split("");
156      var head = +(values.shift());
157      var output = "+jQuery.parseHTML()";
158
159      if (head > 0){ output = "+!" + output; }
160      for (i = 1; i < head; i++){ output = "+!+jQuery.parseHTML()" + output; }
161      if (head > 1){ output = output.substr(1); }
162
163      return [output].concat(values).join("+").replace(/(\d)/g, digitReplacer);
164    }
165
166    for (i = MIN; i <= MAX; i++){
167      character = String.fromCharCode(i);
168      value = MAPPING[character];
169      if(!value) {continue;}
170      original = value;
171
172      for (key in CONSTRUCTORS){
173        replace("\\b" + key, CONSTRUCTORS[key] + '["constructor"]');
174      }
175
176      for (key in SIMPLE){
177        replace(key, SIMPLE[key]);
178      }
179
180      replace('(\\d\\d+)', numberReplacer);
181      replace('\\((\\d)\\)', digitReplacer);
182      replace('\\[(\\d)\\]', digitReplacer);
183
184      replace("GLOBAL", GLOBAL);
185      replace('\\+""', "+jQuery.parseHTML()");
186      replace('""', "jQuery.parseHTML()+jQuery.parseHTML()");
187
188      MAPPING[character] = value;
189    }
190  }
191
192  function replaceStrings(){
193    var regEx = /[^\[\]\(\)\!\+](?=[\]\)\!\+])/g,
194      all, value, missing,
195      count = MAX - MIN;
196
197    function findMissing(){
198      var all, value, done = false;
199
200      missing = {};
201
202      for (all in MAPPING){
203
204        value = MAPPING[all];
205
206        if (value.match(regEx)){
207          missing[all] = value;
208          done = true;
209        }
210      }
211
212      return done;
213    }
214
215    function mappingReplacer(a, b) {
216      return b.split("").join("+");
217    }
218
219    function valueReplacer(c) {
220      return missing[c] ? c : MAPPING[c];
221    }
222
223    for (all in MAPPING){
224      MAPPING[all] = MAPPING[all].replace(/\"([^\"]+)\"/gi, mappingReplacer);
225    }
226
227    while (findMissing()){
228      for (all in missing){
229        value = MAPPING[all];
230        value = value.replace(regEx, valueReplacer);
231
232        MAPPING[all] = value;
233        missing[all] = value;
234      }
235
236      if (count-- === 0){
237        console.error("Could not compile the following chars:", missing);
238      }
239    }
240
241  }
242
243  function encode(input, wrapWithEval, runInParentScope){
244    var output = [];
245
246    if (!input){
247      return "";
248    }
249
250    var r = "";
251    for (var i in SIMPLE) {
252      r += i + "|";
253    }
254    r+=".";
255
256    input.replace(new RegExp(r, 'g'), function(c) {
257      var replacement = SIMPLE[c];
258      if (replacement) {
259        output.push("[" + replacement + "]+jQuery.parseHTML()");
260      } else {
261        replacement = MAPPING[c];
262        if (replacement){
263          output.push(replacement);
264        } else {
265          replacement =
266            "(jQuery.parseHTML()+jQuery.parseHTML())[" + encode("constructor") + "]" +
267            "[" + encode("fromCharCode") + "]" +
268            "(" + encode(c.charCodeAt(0) + "") + ")";
269
270          output.push(replacement);
271          MAPPING[c] = replacement;
272        }
273      }
274    });
275
276    output = output.join("+");
277
278    if (/^\d$/.test(input)){
279      output += "+jQuery.parseHTML()";
280    }
281
282    if (wrapWithEval){
283      output = "jQuery.globalEval(" + output + ")";
284/*
285      if (runInParentScope){
286        output = "jQuery.parseHTML()[" + encode("fill") + "]" +
287          "[" + encode("constructor") + "]" +
288          "(" + encode("return eval") +  ")()" +
289          "(" + output + ")";
290      } else {
291        output = "jQuery.parseHTML()[" + encode("fill") + "]" +
292          "[" + encode("constructor") + "]" +
293          "(" + output + ")()";
294      }
295*/
296    }
297
298    return output;
299  }
300
301  fillMissingDigits();
302  fillMissingChars();
303  replaceMap();
304  replaceStrings();
305
306  self.JSFuck = {
307    encode: encode
308  };
309})(typeof(exports) === "undefined" ? window : exports);
310
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)