Florr Adblocker

Block florr.io ad animation in Diep.io.

当前为 2020-10-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Florr Adblocker
// @namespace    https://diep.io
// @version      1.0
// @description  Block florr.io ad animation in Diep.io.
// @author       Binary
// @match        *://diep.io/*
// @grant        none
// ==/UserScript==

(function() {
    let original_getContext = HTMLCanvasElement.prototype.getContext;
    HTMLCanvasElement.prototype.getContext = function(...args){
        let ctx = original_getContext.apply(this, args);

        // Updated wrapper functions from last time (from Minimap AFK)
        function wrapFunc(targetProp, wrapFunc) {
            let property = ctx[targetProp];

            ctx[targetProp] = function(...args) {

                if (wrapFunc.call(ctx, args)) return;

                return property.apply(ctx, args);
            };
            return true;
        }
        function wrapSetter(targetProp, wrapFunc) {
            let setter = ctx.__lookupSetter__(targetProp);
            let getter = ctx.__lookupGetter__(targetProp); // store getter as defining a setter will erase the getter for that

            ctx.__defineSetter__(targetProp, function(newVal) {
                let callbackResult = wrapFunc.call(ctx, newVal);

                if (callbackResult === true) return;

                return setter.call(ctx, typeof callbackResult === "undefined" ? newVal : callbackResult);
            });
            ctx.__defineGetter__(targetProp, getter);
        }


        let isPaintingFlorr = false;
        wrapSetter('strokeStyle', function(newValue){
            if(newValue === 'rgb(207,207,207)'){
                isPaintingFlorr = true;
            }
        });
        wrapFunc('quadraticCurveTo', function(){
            isPaintingFlorr = false;
            console.log('Blocked florr ad');
            return true;
        });
        wrapFunc('arc', function(){
            if(isPaintingFlorr) return true;
        });
        wrapFunc('fill', function(){
            if(isPaintingFlorr) return true;
        });
        wrapFunc('stroke', function(){
            if(isPaintingFlorr) return true;
        });



        return ctx;
    };
})();