class DevicePixelRatio {
  _getSystem() {
    const agent = navigator.userAgent.toLowerCase();
    if (agent.indexOf('windows') >= 0) {
      return true;
    }
  }
  _addHandler(element, type, handler) {
    if (element.addEventListener) {
      element.addEventListener(type, handler, false);
    } else if (element.attachEvent) {
      element.attachEvent('on' + type, handler);
    } else {
      element['on' + type] = handler;
    }
  }
  _correct() {
    const size = 1 / window.devicePixelRatio;
    const size2 = 100 / size + '%';
    document.getElementsByTagName('body')[0].style.transform = 'scale(' + size + ')';
    document.getElementsByTagName('body')[0].style.transformOrigin = '0 0';
    document.getElementsByTagName('body')[0].style.width = size2;
    document.getElementsByTagName('body')[0].style.height = size2;
  }
  _watch() {
    this._addHandler(window, 'resize', () => {
      this._correct();
    });
  }
  init() {
    if (this._getSystem()) {
      this._correct();
      this._watch();
    }
  }
}
export default DevicePixelRatio;