JavaScript - Ayuda funcionamiento y/o fuente de código en js

   
Vista:

Ayuda funcionamiento y/o fuente de código en js

Publicado por Sebastian (1 intervención) el 23/03/2016 15:51:26
Hola, me gustaría que alguien me ayudara identificando, ya sea el funcionamiento o la fuente del código encontrado en el DOM de una página mientras navegaba en la web:

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
var originalOpenWndFnKey = "originalOpenFunction";
 
var originalWindowOpenFn 	= window.open,
	originalCreateElementFn = document.createElement,
	originalCreateEventFn 	= document.createEvent,
	windowsWithNames = {};
var timeSinceCreateAElement = 0;
var lastCreatedAElement = null;
var fullScreenOpenTime;
var parentOrigin = (window.location != window.parent.location) ? document.referrer: document.location;
 
window[originalOpenWndFnKey] = window.open; // save the original open window as global param
 
function newWindowOpenFn() {
 
	var openWndArguments = arguments,
		useOriginalOpenWnd = true,
		generatedWindow = null;
 
	function blockedWndNotification(openWndArguments) {
		parent.postMessage({ type: "blockedWindow", args: JSON.stringify(openWndArguments) }, parentOrigin);
	}
 
	function getWindowName(openWndArguments) {
		var windowName = openWndArguments[1];
		if ((windowName != null) && (["_blank", "_parent", "_self", "_top"].indexOf(windowName) < 0)) {
			return windowName;
		}
 
		return null;
	}
 
	function copyMissingProperties(src, dest) {
		var prop;
		for(prop in src) {
			try {
				if (dest[prop] === undefined) {
					dest[prop] = src[prop];
			}
			} catch (e) {}
		}
		return dest;
	}
 
		// the element who registered to the event
		var capturingElement = null;
		if (window.event != null) {
			capturingElement = window.event.currentTarget;
		}
 
		if (capturingElement == null) {
			var caller = openWndArguments.callee;
			while ((caller.arguments != null) && (caller.arguments.callee.caller != null)) {
				caller = caller.arguments.callee.caller;
			}
			if ((caller.arguments != null) && (caller.arguments.length > 0) && (caller.arguments[0].currentTarget != null)) {
				capturingElement = caller.arguments[0].currentTarget;
			}
		}
 
	/////////////////////////////////////////////////////////////////////////////////
	// Blocked if a click on background element occurred (<body> or document)
	/////////////////////////////////////////////////////////////////////////////////
 
		if ((capturingElement != null) && (
				(capturingElement instanceof Window) ||
				(capturingElement === document) ||
				(
					(capturingElement.URL != null) && (capturingElement.body != null)
				) ||
				(
					(capturingElement.nodeName != null) && (
						(capturingElement.nodeName.toLowerCase() == "body") ||
						(capturingElement.nodeName.toLowerCase() == "#document")
					)
				)
			)) {
				window.pbreason = "Blocked a new window opened with URL: " + openWndArguments[0] + " because it was triggered by the " + capturingElement.nodeName + " element";
				// console.info(window.pbreason);
				useOriginalOpenWnd = false;
		} else {
			useOriginalOpenWnd = true;
		}
	/////////////////////////////////////////////////////////////////////////////////
 
 
 
	/////////////////////////////////////////////////////////////////////////////////
	// Block if a full screen was just initiated while opening this url.
	/////////////////////////////////////////////////////////////////////////////////
 
		// console.info("fullscreen: " + ((new Date()).getTime() - fullScreenOpenTime));
		// console.info("webkitFullscreenElement: " + document.webkitFullscreenElement);
		var fullScreenElement = document.webkitFullscreenElement || document.mozFullscreenElement || document.fullscreenElement
		if ((((new Date()).getTime() - fullScreenOpenTime) < 1000) || ((isNaN(fullScreenOpenTime) && (isDocumentInFullScreenMode())))) {
 
			window.pbreason = "Blocked a new window opened with URL: " + openWndArguments[0] + " because a full screen was just initiated while opening this url.";
			// console.info(window.pbreason);
 
			/* JRA REMOVED
			if (window[script_params.fullScreenFnKey]) {
				window.clearTimeout(window[script_params.fullScreenFnKey]);
			}
			*/
 
			if (document.exitFullscreen) {
				document.exitFullscreen();
			}
			else if (document.mozCancelFullScreen) {
				document.mozCancelFullScreen();
			}
			else if (document.webkitCancelFullScreen) {
				document.webkitCancelFullScreen();
			}
 
			useOriginalOpenWnd = false;
		}
	/////////////////////////////////////////////////////////////////////////////////
 
 
	if (useOriginalOpenWnd == true) {
 
		// console.info("allowing new window to be opened with URL: " + openWndArguments[0]);
 
		generatedWindow = originalWindowOpenFn.apply(this, openWndArguments);
 
		// save the window by name, for latter use.
		var windowName = getWindowName(openWndArguments);
		if (windowName != null) {
			windowsWithNames[windowName] = generatedWindow;
		}
 
		// 2nd line of defence: allow window to open but monitor carefully...
 
		/////////////////////////////////////////////////////////////////////////////////
		// Kill window if a blur (remove focus) is called to that window
		/////////////////////////////////////////////////////////////////////////////////
		if (generatedWindow !== window) {
			var openTime = (new Date()).getTime();
			var originalWndBlurFn = generatedWindow.blur;
			generatedWindow.blur = function() {
				if (((new Date()).getTime() - openTime) < 1000 /* one second */) {
					window.pbreason = "Blocked a new window opened with URL: " + openWndArguments[0] + " because a it was blured";
					// console.info(window.pbreason);
					generatedWindow.close();
					blockedWndNotification(openWndArguments);
				} else {
					// console.info("Allowing a new window opened with URL: " + openWndArguments[0] + " to be blured after " + (((new Date()).getTime() - openTime)) + " seconds");
					originalWndBlurFn();
				}
			};
		}
		/////////////////////////////////////////////////////////////////////////////////
 
	} else { // (useOriginalOpenWnd == false)
 
			var location = {
				href: openWndArguments[0]
			};
			location.replace = function(url) {
				location.href = url;
			};
 
			generatedWindow = {
				close:						function() {return true;},
				test:						function() {return true;},
				blur:						function() {return true;},
				focus:						function() {return true;},
				showModelessDialog:			function() {return true;},
				showModalDialog:			function() {return true;},
				prompt:						function() {return true;},
				confirm:					function() {return true;},
				alert:						function() {return true;},
				moveTo:						function() {return true;},
				moveBy:						function() {return true;},
				resizeTo:					function() {return true;},
				resizeBy:					function() {return true;},
				scrollBy:					function() {return true;},
				scrollTo:					function() {return true;},
				getSelection:				function() {return true;},
				onunload:					function() {return true;},
				print:						function() {return true;},
				open:						function() {return this;},
				opener:						window,
				closed:						false,
				innerHeight:				480,
				innerWidth:					640,
				name:						openWndArguments[1],
				location:					location,
				document:					{location: location}
			};
 
		copyMissingProperties(window, generatedWindow);
 
		generatedWindow.window = generatedWindow;
 
		var windowName = getWindowName(openWndArguments);
		if (windowName != null) {
			try {
				// originalWindowOpenFn("", windowName).close();
				windowsWithNames[windowName].close();
				// console.info("Closed window with the following name: " + windowName);
			} catch (err) {
				// console.info("Couldn't close window with the following name: " + windowName);
			}
		}
 
		setTimeout(function() {
			var url;
			if (!(generatedWindow.location instanceof Object)) {
				url = generatedWindow.location;
			} else if (!(generatedWindow.document.location instanceof Object)) {
				url = generatedWindow.document.location;
			} else if (location.href != null) {
				url = location.href;
			} else {
				url = openWndArguments[0];
			}
			openWndArguments[0] = url;
			blockedWndNotification(openWndArguments);
		}, 100);
	}
 
	return generatedWindow;
}
 
 
/////////////////////////////////////////////////////////////////////////////////
// Replace the window open method with Poper Blocker's
/////////////////////////////////////////////////////////////////////////////////
window.open = function() {
	try {
		return newWindowOpenFn.apply(this, arguments);
	} catch(err) {
		return null;
	}
};
/////////////////////////////////////////////////////////////////////////////////
 
 
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Monitor dynamic html element creation to prevent generating <a> elements with click dispatching event
//////////////////////////////////////////////////////////////////////////////////////////////////////////
document.createElement = function() {
 
		var newElement = originalCreateElementFn.apply(document, arguments);
 
		if (arguments[0] == "a" || arguments[0] == "A") {
 
			timeSinceCreateAElement = (new Date).getTime();
 
			var originalDispatchEventFn = newElement.dispatchEvent;
 
			newElement.dispatchEvent = function(event) {
				if (event.type != null && (("" + event.type).toLocaleLowerCase() == "click")) {
					window.pbreason = "blocked due to an explicit dispatchEvent event with type 'click' on an 'a' tag";
					// console.info(window.pbreason);
					parent.postMessage({type:"blockedWindow", args: JSON.stringify({"0": newElement.href}) }, parentOrigin);
					return true;
				}
 
				return originalDispatchEventFn(event);
			};
 
			lastCreatedAElement = newElement;
 
		}
 
		return newElement;
};
/////////////////////////////////////////////////////////////////////////////////
 
 
 
 
/////////////////////////////////////////////////////////////////////////////////
// Block artificial mouse click on frashly created <a> elements
/////////////////////////////////////////////////////////////////////////////////
document.createEvent = function() {
	try {
		if ((arguments[0].toLowerCase().indexOf("mouse") >= 0) && ((new Date).getTime() - timeSinceCreateAElement) <= 50) {
			window.pbreason = "Blocked because 'a' element was recently created and " + arguments[0] + " event was created shortly after";
			// console.info(window.pbreason);
			arguments[0] = lastCreatedAElement.href;
			parent.postMessage({ type: "blockedWindow", args: JSON.stringify({"0": lastCreatedAElement.href}) }, parentOrigin);
			return null;
		}
		return originalCreateEventFn.apply(document, arguments);
	} catch(err) {}
};
/////////////////////////////////////////////////////////////////////////////////
 
 
 
 
 
/////////////////////////////////////////////////////////////////////////////////
// Monitor full screen requests
/////////////////////////////////////////////////////////////////////////////////
function onFullScreen(isInFullScreenMode) {
		if (isInFullScreenMode) {
			fullScreenOpenTime = (new Date()).getTime();
			// console.info("fullScreenOpenTime = " + fullScreenOpenTime);
		} else {
			fullScreenOpenTime = NaN;
		}
};
/////////////////////////////////////////////////////////////////////////////////
 
function isDocumentInFullScreenMode() {
	// Note that the browser fullscreen (triggered by short keys) might
	// be considered different from content fullscreen when expecting a boolean
	return ((document.fullScreenElement && document.fullScreenElement !== null) ||    // alternative standard methods
		((document.mozFullscreenElement != null) || (document.webkitFullscreenElement != null)));                   // current working methods
}
 
document.addEventListener("fullscreenchange", function () {
	onFullScreen(document.fullscreen);
}, false);
 
document.addEventListener("mozfullscreenchange", function () {
	onFullScreen(document.mozFullScreen);
}, false);
 
document.addEventListener("webkitfullscreenchange", function () {
	onFullScreen(document.webkitIsFullScreen);
}, false);
 
} inject()</script>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder