mine

try to take over the world!

目前為 2020-10-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         mine
// @namespace    http://tampermonkey.net/
// @version      0.0.0.1
// @description  try to take over the world!
// @author       LaoTie
// @match        https://www.element3ds.com/plugin.php?id=yw_mine:front&mod=mineDetail&mineId=*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(async function() {
    'use strict';
    var mineinfo={}
    await start();
    await getStartTime(mineinfo);
    await GM_setObject(mineinfo.mineid,mineinfo)
    console.log("gm_getobject:"+JSON.stringify(await GM_getObject(mineinfo.mineid)))
    setInterval(function(){
        console.log('time is over!')
        window.location.reload()
    },1800000);
})();
//开始时间
async function getStartTime(mineinfo){
    mineinfo.mineid=getQuery('mineId')
    jQuery('.yun_mine_detail div span').each(function(i,e){
        if(i==5){//获取矿工数量
            if(e.innerHTML>0){
                mineinfo.worker=e.innerHTML
            }
        }
        if(i==8){//获取到期时间
            if(e.innerHTML.indexOf('到期')>0){
                mineinfo.endtime=e.innerHTML.replace(' 到期',':30')
            }
        }
    })
}
//开始采矿
async function start(){
    let cangku={}
    cangku.lingqu=[];
    let list=findele('.yun_user_ore')
    if(list.length>0){
        for(let i=0;i<list.length;i++){
            if(list[i].children.length>0){
                for(let j=0;j<list[i].children.length;j++){
                    if(list[i].children[j].children[0].innerHTML>0&&list[i].children[j].children[0].innerHTML!='480'){
                        let name=list[i].children[j].children[1].innerHTML
                        let cminfo={};
                        cminfo.name=name;
                        cminfo.ele=list[i].children[j].children[1];
                        cangku.lingqu.push(cminfo);
                    }
                }
            }
        }
    }
   firstclick(cangku.lingqu);
}
//执行收取操作
async function firstclick(eles){
    console.log('开始采集');
    for(let i=0;i<eles.length;i++){
        if(eles[i].name=='领取'){
            getMine(eles[i]);
            await sleep(3000);
        }
    }
    for(let i=0;i<eles.length;i++){
        if(eles[i].name=='出售'){
            getMine(eles[i]);
            await sleep(3000);
        }
    }
    console.log('结束采集')
}
//执行确认操作
async function getMine(ele){
    console.log(ele.name);
    ele.ele.click()
    console.log(Date.parse(new Date()))
    await sleep(3000)
    console.log(Date.parse(new Date()))
    let buts= jQuery('#yunform .yunw_button input')
    console.log(buts)
    if(buts.length>0){
        console.log(buts[0].value)
        buts[0].click()
        await sleep(1000) //
        jQuery('#enter').click()
    }
    console.log('getMine:结束了');
}
//找到目标元素
function findele(cls){
    let list=[]
    jQuery(cls).each(function(i,e){
        list.push(e)
    })
    return list
}
//等待时间
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
//获取地址参数
function getQuery(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
}

async function GM_setObject(name, value) {
	if (value instanceof Object) {
		// 使用 JSON.stringify 将值转换为文本。
		GM_setValue (name, JSON.stringify (value));
	}
}

async function GM_getObject(name, undefined) {
	try {
		return JSON.parse (GM_getValue (name, '') || '{}');
	} catch (e) {
		// 如果抓取的数据有误报错就直接返回默认值。
		return undefined;
	}
};