<commit_before>/**
 * 网站浏览模块
 * 开写：2016/07/01
 */

const CookieMgr = require('./cookiemgr');
const LANG = antSword.language['viewsite'];
const LANG_T = antSword.language['toastr'];

class ViewSite {
  constructor(opts) {
    const hash = String(Math.random()).substr(2, 10);

    // 初始化UI::tabbar
    const tabbar = antSword['tabbar'];
    tabbar.addTab(
      `tab_viewsite_${hash}`,
      `<i class="fa fa-chrome"></i> ${opts['ip']}`,
      null, null, true, true
    );
    tabbar.attachEvent('onTabClick', (id,lid) => {
      if (id !== `tab_viewsite_${hash}`) { return };
    });

    this.opts = opts;
    this.cell = tabbar.cells(`tab_viewsite_${hash}`);
    this.useproxy = antSword.aproxymode !== "noproxy";
    // 初始化工具栏
    this.toolbar = this._initToolbar();

    this.grid = this._initGrid();

    // 定时刷新Cookie
    this._refreshCookie();
    const inter = setInterval(() => {
      if (this.grid.clearAll instanceof Function) {
        this._refreshCookie();
      } else {
        clearInterval(inter);
      }
    }, 1000);

    // 打开浏览窗口
    // this._loadURL(opts.url);
  }

  /**
   * 初始化工具栏
   * @return {[type]} [description]
   */
  _initToolbar() {
    const toolbar = this.cell.attachToolbar();
    toolbar.loadStruct([
      { id: 'url', width: 400, type: 'buttonInput', value: this.opts.url || 'loading..' },
      { type: 'separator' },
      { id: 'useproxy', type: 'buttonTwoState', icon: 'paper-plane', text: LANG['toolbar'].useproxy(this.useproxy), pressed: this.useproxy, disabled: antSword.aproxymode === "noproxy"},
      { type: 'separator' },
      { id: 'view', type: 'button', icon: 'chrome', text: LANG['toolbar'].view },
      { type: 'separator' },
      { id: 'save', type: 'button', icon: 'save', text: LANG['toolbar'].save },
    ]);
    toolbar.attachEvent('onStateChange', (id, state) => {
      switch(id) {
        case 'useproxy':
          this.useproxy = state;
          toolbar.setItemText('useproxy', `<i class="fa fa-paper-plane"></i> ${LANG['toolbar'].useproxy(this.useproxy)}`);
        break;
      }
    });
    toolbar.attachEvent('onClick', (id) => {
      switch(id) {
        case 'save':
          this._saveCookie();
          break;
        case 'view':
          let url = toolbar.getInput('url').value;
          this._loadURL(url);
      }
    });
    toolbar.attachEvent('onEnter', (id, value) => {
      switch(id) {
        case 'url':<commit_msg>(Fix:ViewSite) 修正ViewSite URL 处的 self-xss<commit_after>/**
 * 网站浏览模块
 * 开写：2016/07/01
 */

const CookieMgr = require('./cookiemgr');
const LANG = antSword.language['viewsite'];
const LANG_T = antSword.language['toastr'];

class ViewSite {
  constructor(opts) {
    const hash = String(Math.random()).substr(2, 10);

    // 初始化UI::tabbar
    const tabbar = antSword['tabbar'];
    tabbar.addTab(
      `tab_viewsite_${hash}`,
      `<i class="fa fa-chrome"></i> ${opts['ip']}`,
      null, null, true, true
    );
    tabbar.attachEvent('onTabClick', (id,lid) => {
      if (id !== `tab_viewsite_${hash}`) { return };
    });

    this.opts = opts;
    this.cell = tabbar.cells(`tab_viewsite_${hash}`);
    this.useproxy = antSword.aproxymode !== "noproxy";
    // 初始化工具栏
    this.toolbar = this._initToolbar();

    this.grid = this._initGrid();

    // 定时刷新Cookie
    this._refreshCookie();
    const inter = setInterval(() => {
      if (this.grid.clearAll instanceof Function) {
        this._refreshCookie();
      } else {
        clearInterval(inter);
      }
    }, 1000);

    // 打开浏览窗口
    // this._loadURL(opts.url);
  }

  /**
   * 初始化工具栏
   * @return {[type]} [description]
   */
  _initToolbar() {
    const toolbar = this.cell.attachToolbar();
    toolbar.loadStruct([
      { id: 'url', width: 400, type: 'buttonInput', value: antSword.noxss(this.opts.url) || 'loading..' },
      { type: 'separator' },
      { id: 'useproxy', type: 'buttonTwoState', icon: 'paper-plane', text: LANG['toolbar'].useproxy(this.useproxy), pressed: this.useproxy, disabled: antSword.aproxymode === "noproxy"},
      { type: 'separator' },
      { id: 'view', type: 'button', icon: 'chrome', text: LANG['toolbar'].view },
      { type: 'separator' },
      { id: 'save', type: 'button', icon: 'save', text: LANG['toolbar'].save },
    ]);
    toolbar.attachEvent('onStateChange', (id, state) => {
      switch(id) {
        case 'useproxy':
          this.useproxy = state;
          toolbar.setItemText('useproxy', `<i class="fa fa-paper-plane"></i> ${LANG['toolbar'].useproxy(this.useproxy)}`);
        break;
      }
    });
    toolbar.attachEvent('onClick', (id) => {
      switch(id) {
        case 'save':
          this._saveCookie();
          break;
        case 'view':
          let url = toolbar.getInput('url').value;
          this._loadURL(url);
      }
    });
    toolbar.attachEvent('onEnter', (id, value) => {
      switch(id) {
        case 'url':
{'fraction_non_alphanumeric': 0.18872950819672132, 'fraction_numerical': 0.007377049180327869, 'mean_word_length': 2.6782215523737753, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1057769', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1731, 'n_words': 307}