每天拿出一分钟来学习,你的生命会更加精彩。

浏览器随机指纹js代码

发布:洪雨2021-1-20 18:22分类: 编程相关 标签: 编程

  const toBlob = HTMLCanvasElement.prototype.toBlob;
  const toDataURL = HTMLCanvasElement.prototype.toDataURL;

  HTMLCanvasElement.prototype.manipulate = function() {
    const {width, height} = this;
    const context = this.getContext('2d');
    const shift = {
      'r': Math.floor(Math.random() * 10) - 5,
      'g': Math.floor(Math.random() * 10) - 5,
      'b': Math.floor(Math.random() * 10) - 5
    };
    const matt = context.getImageData(0, 0, width, height);
    for (let i = 0; i < height; i += Math.max(1, parseInt(height / 10))) {
      for (let j = 0; j < width; j += Math.max(1, parseInt(width / 10))) {
        const n = ((i * (width * 4)) + (j * 4));
        matt.data[n + 0] = matt.data[n + 0] + shift.r;
        matt.data[n + 1] = matt.data[n + 1] + shift.g;
        matt.data[n + 2] = matt.data[n + 2] + shift.b;
      }
    }
    context.putImageData(matt, 0, 0);

  };

  Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
    value: function() {
     
        try {
          this.manipulate();
        }
        catch(e) {
          console.warn('manipulation failed', e);
        }

      return toBlob.apply(this, arguments);
    }
  });
  Object.defineProperty(HTMLCanvasElement.prototype, 'toDataURL', {
    value: function() {

        try {
          this.manipulate();
        }
        catch(e) {
          console.warn('manipulation failed', e);
        }

      return toDataURL.apply(this, arguments);
    }
  });

温馨提示如有转载或引用以上内容之必要,敬请将本文链接作为出处标注,谢谢合作!

已有 0/2336 人参与

发表评论:

欢迎使用手机扫描访问本站,还可以关注微信哦~