(function () {
var hook_eventNames = "contextmenu|select|selectstart|copy|cut|dragstart".split("|");
var unhook_eventNames = "mousedown|mouseup|keydown|keyup".split("|");
var eventNames = hook_eventNames.concat(unhook_eventNames);
var storageName = getRandStr('qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM', parseInt(Math.random() * 12 + 8));
var EventTarget_addEventListener = EventTarget.prototype.addEventListener;
var document_addEventListener = document.addEventListener;
var Event_preventDefault = Event.prototype.preventDefault;
function addEventListener(type, func, useCapture) {
var _addEventListener = this === document ? document_addEventListener : EventTarget_addEventListener;
if (hook_eventNames.indexOf(type) >= 0) {
_addEventListener.apply(this, [type, returnTrue, useCapture]);
} else if (unhook_eventNames.indexOf(type) >= 0) {
var funcsName = storageName + type + (useCapture ? 't' : 'f');
if (this[funcsName] === undefined) {
this[funcsName] = [];
_addEventListener.apply(this, [type, useCapture ? unhook_t : unhook_f, useCapture]);
}
this[funcsName].push(func);
} else {
_addEventListener.apply(this, arguments);
}
}
function clearLoop() {
var elements = getElements();
for (var i in elements) {
for (var j in eventNames) {
var name = 'on' + eventNames[j];
if (elements[i][name] != null && elements[i][name] != onxxx) {
if (unhook_eventNames.indexOf(eventNames[j]) >= 0) {
elements[i][storageName + name] = elements[i][name];
elements[i][name] = onxxx;
} else {
elements[i][name] = null;
}
}
}
}
}
function returnTrue(e) {
return true;
}
function unhook_t(e) {
return unhook(e, this, storageName + e.type + 't');
}
function unhook_f(e) {
return unhook(e, this, storageName + e.type + 'f');
}
function unhook(e, self, funcsName) {
var list = self[funcsName];
for (var i in list) {
list[i](e);
}
e.returnValue = true;
return true;
}
function onxxx(e) {
var name = storageName + 'on' + e.type;
this[name](e);
e.returnValue = true;
return true;
}
function getRandStr(chs, len) {
var str = '';
while (len--) {
str += chs[parseInt(Math.random() * chs.length)];
}
return str;
}
function getElements() {
var elements = Array.prototype.slice.call(document.getElementsByTagName('*'));
elements.push(document);
return elements;
}
function addStyle(css) {
var style = document.createElement('style');
style.innerHTML = css;
document.head.appendChild(style);
}
function init() {
setInterval(clearLoop, 30 * 1000);
setTimeout(clearLoop, 2500);
window.addEventListener('load', clearLoop, true);
clearLoop();
EventTarget.prototype.addEventListener = addEventListener;
document.addEventListener = addEventListener;
Event.prototype.preventDefault = function () {
if (eventNames.indexOf(this.type) < 0) {
Event_preventDefault.apply(this, arguments);
}
};
Event.prototype.__defineSetter__('returnValue', function () {
if (this.returnValue != true && eventNames.indexOf(this.type) >= 0) {
console.log(this);
this.returnValue = true;
}
});
console.debug('storageName:' + storageName);
addStyle('html,*,:not(input):not(textarea):not(select), input[type="image"], input[type="file"], input[type="submit"], input[type="button"], input[type="reset"] {-webkit-user-select:text!important;-moz-user-select:text!important;user-select:text!important;}');
}
init();
})();