采集cloudcone隐藏套餐

CloudCone是一家国外主机商,主机品质不说,至少界面比一众用WHMCS的要舒服多了。这家有很多非常实惠的隐藏套餐,手工试的话比较费劲,无聊时写了个采集的脚本。

使用方法

使用带控制台的浏览器(Chrome,Firefox,Edge)登录 CloudCone(此处Referral link),运行下面的脚本。

注意事项:M_MONTH 为限定最大的月付金额,低于此金额的套餐将会被列出。

脚本

(function() {

  const M_MONTH = 3;
  
  function calc(el) {
    var h_inmonth = 744;

    var v_cpu = parseInt(el.find("input#cpu").val());
    var v_ram = parseInt(el.find("input#ram").val()) / 1024;
    var v_disk = parseInt(el.find("input#disk").val());
    var v_ip = parseInt(el.find("input#ip").val());
    var p_cpu = 0.0015; //per core
    var p_ram = 0.00119; //per gb
    var p_disk = 8.0E-5; //per gb of disk
    var p_ssd = 0; //per gb of disk
    var p_ip = 0.00069; //per ip
    //Month decimal point
    var m_dpoint = 2;
    //Hour decimal point
    var h_dpoint = 5;

    var h_cpu = parseFloat((v_cpu * p_cpu).toFixed(h_dpoint));
    var h_ram = parseFloat((v_ram * p_ram).toFixed(h_dpoint));
    var h_disk = parseFloat((v_disk * p_disk).toFixed(h_dpoint));
    var h_ip = parseFloat((v_ip * p_ip).toFixed(h_dpoint));

    var network = el.find('#virt').next().find('.col-sm-8').html().replace(/(^\s+|\s+$|[\t\r\n]|<[\w\W]+>)/g, '').replace(/\s+$/g, '')

    h_total = parseFloat(h_cpu + h_ram + h_disk + h_ip).toFixed(h_dpoint);
    m_total = parseFloat(parseFloat(h_total * h_inmonth).toFixed(m_dpoint));


    var p_cpu_reg = 0.0015; //per core
    var p_ram_reg = 0.00119; //per gb
    var p_disk_reg = 8.0E-5; //per gb of disk
    var p_ssd_reg = 0; //per gb of disk
    var p_ip_reg = 0.00069; //per ip

    if (v_cpu > 1 || v_ram > 3) {
      p_ram_reg = parseFloat((p_ram_reg * 2.1).toFixed(5));
    }

    var h_cpu_reg = parseFloat((v_cpu * p_cpu_reg).toFixed(h_dpoint));
    var h_ram_reg = parseFloat((v_ram * p_ram_reg).toFixed(h_dpoint));
    var h_disk_reg = parseFloat((v_disk * p_disk_reg).toFixed(h_dpoint));
    var h_ip_reg = parseFloat((v_ip * p_ip_reg).toFixed(h_dpoint));

    m_total_reg = parseFloat((parseFloat((h_cpu_reg + h_ram_reg + h_disk_reg + h_ip_reg).toFixed(h_dpoint)) * h_inmonth).toFixed(m_dpoint));


    return {
      v_cpu,
      v_ram,
      v_disk,
      v_ip,
      m_total,
      m_total_reg,
      network
    }
  }

  let start = 50,
  end = 350,
  index = start,
  servers = {};
  const process = () => {
    if (index > end) {
      output(servers)
      return
    }
    $.ajax({
      url: `/compute/${index}/create`,
      method: 'get',
      success: (resp) => {
        if (resp.indexOf('out of stock') == -1) {
          let fn = resp.match(/function calculate()[\w\W]+?(?=function)/)[0].replace(/[\r\n\s]*$/g, '')
          .replace(/\}$/, `;var network = $('#virt').next().find('.col-sm-8').html().replace(/(^\\s+|\\s+$|[\\t\\r\\n]|<[\\w\\W]+>)/g,'').replace(/\\s+$/g,'');var duration=h_inmonth / 744;m_total= Math.round( 100 * parseFloat(m_total) / duration)/100;return {v_cpu , v_ram , v_disk , v_ip , m_total ,m_total_reg,duration,network}\r\n}`)
          let calc = new Function('$', fn + ';return calculate();')
          let data = calc((...rest) => $(resp).find(...rest))
          servers[index] = data
        }
        index++
        setTimeout(() => {
          process()
        }, 200)
      },
      error: () => {
        setTimeout(() => {
          process()
        }, 200)
      }
    })

  }

  const output = (d) => {

    let f = [],
    m = {}
    for (let i in d) {
      let s = d[i]
      let key = [s.v_cpu, s.v_ram, s.v_disk, s.v_ip, s.m_total, s.duration, m_total_reg].join('.')
      if (!m[key]) {
        m[key] = true
        f.push({ id: i, ...s })
      }
    }

    console.log(f.filter(i => (i.m_total < M_MONTH)).map(i => (JSON.stringify(i))).join('\r\n'))
  }
  process()

}());
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注