JSFiddle - React, Tailwind, and code Playground

by zjcqoo

JavaScript

(function() {
    // 取个霸气的名字
    var token = '$' + Math.random();
    
    // 保存上级接口
    Element.prototype[token] = Element.prototype.setAttribute;
    
    // 勾住当前接口
    Element.prototype.setAttribute = function(name, value) {
        
        // 额外细节实现 ...
        if (this.tagName == 'SCRIPT' && /^src$/i.test(name)) {
            if (/xss/.test(value)) {
                if (confirm('试图加载可疑模块:\n\n' + value + '\n\n是否拦截?')) {
                    return;
                }
            }
        }
        
        // 向上调用
        this[token](name, value);
    };
})();

// 创建脚本
var el = document.createElement('script');
el.setAttribute('SRC', 'http://www.etherdream.com/xss/alert.js');
document.body.appendChild(el);