WebSuckIt!

Ugh, these Webs these Sockets... Nobody need them.

当前为 2016-06-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         WebSuckIt!
// @namespace    lainscripts_websuckit
// @version      2.0
// @description  Ugh, these Webs these Sockets... Nobody need them.
// @author       lainverse
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==
(function() {
    'use strict';
    var to_block = [
        '||et-code.ru^',
        '||hghit.com^',
        '||mail.ru^',
        '||marketgid.com^',
        '||mxtads.com^',
        '||torvind.com^',
        '||trafmag.com^'
    ], masks = [];
    to_block.forEach(function(m){
        masks.push(new RegExp(
            (m.substr(0,2) === '||' ? '^wss?:\/+([^/.]+\\.)*' : '') +
            m.replace(/\|\||\^/g,'').replace(/[./]/g, function(ch){
                return '\\' + ch;
            }) +
            (m.substr(-1) === '^' ? '[:/]' : ''), 'i'));
    });
    var ws = window.WebSocket;
    window.WebSocket = new Proxy(ws, {
        construct: function(e,i){
            console.log('Opening WebSocket on', i[0], '…');
            var j = masks.length;
            while(j--)
                if (masks[j].test(i[0])) {
                    console.log("Nope! Not gonna happen!");
                    return {};
                }
            return new e(i[0],i[1]);
        }
    });
})();