Improvement submition

in
Subscribe to Improvement submition 2 posts, 2 voices



RogerGoGo User
ChromeWindows

I did some improvement on the script:
1. Added delay between link clicks, to prevent being banned by kaixin001
2. Added some necessary breaks on the link iteration, to avoid the confusing js execution
3. Sleep only when there's nothing to do, to make the sleeping time more accurate.

[code]
// ==UserScript==
// @name kaixin001 cafe helper
// @namespace http://userscripts.org/users/muzik
// @include http://wap.kaixin001.com/cafe/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3...
// ==/UserScript==

(function() {
//设置
var setting = {
//默认菜单 id为dishid,weight为随机权重
//[{id:5,weight:5},{id:7,weight:4}],即5/9做红烧茄子,4/9做炸酱面
//如只需做一种菜,[{id:5}]即可
dish: [{id:10,weight:49},{id:50,weight:1}],
//刷新间隔,单位为毫秒。60000即60秒。
reloadInterval:300000,
clickDelay: 9000,
//移至餐台后是否继续做该菜 true/false
cookLastDish:false
};
//25级及以下菜单dishid对照表
/*var menu = {
'宫保鸡丁':4,
'抹茶慕斯':23,
'莲藕炖排骨':8,
'清蒸江团鱼':26,
'红烧茄子':5,
'京酱肉丝':6,
'美容猪手':22,
'炸酱面':7,
'麻婆豆腐':51,
'东坡肉':16,
'清炒鸡毛菜':9,
'红烧狮子头':19,
'水煮鱼':27,
'奶油蘑菇汤':24,
'葱包桧':32,
'糖醋小排':41,
'可乐鸡翅':40,
'陕西凉皮':10,
'菠萝古老肉':15,
'芝士蛋糕':50,
};*/
$(document).ready(function() {
(new Cafe()).loadFunc();
});

var Cafe = function() {
goHome = function(){
$('a').each(function(){
if($(this).text()=='返回我的餐厅'){
var url = $(this).attr('href');
window.setTimeout(function() {
window.location.href= url;
},setting.clickDelay)
}
})
}
goTo = function(str){
var linkExist = false;
$('a').each(function(){
if($(this).text()==str){
var url = $(this).attr('href');
window.setTimeout(function() {
window.location.href= url
},setting.clickDelay);
linkExist = true;
return false; //stop the each excution
}
})
return linkExist;
}
goContinue = function(){
$('a').each(function(){
var patt = new RegExp('继续做该菜');
var url = $(this).attr('href');
if(patt.test($(this).text())){
window.setTimeout(function() {
window.location.href= url
},setting.clickDelay)
}
})
}
goAnother = function(){
$('a').each(function(){
var patt = new RegExp('其他菜');
var url = $(this).attr('href');
if(patt.test($(this).text())){
window.setTimeout(function() {
window.location.href= url
},setting.clickDelay)
}
})
}
isLocation = function(str){
var patt = new RegExp(str)
return patt.test(window.location)
}
goDish = function(num){
$('a').each(function(){
if($(this).text()=='做菜'){
var url = $(this).attr('href').replace(/dishid=\d+/gi, "dishid="+String(num));
window.setTimeout(function() {
window.location.href= url
},setting.clickDelay)
return false; //stop the each execution.
}
})
}
runThis = function(){
if (isLocation('/index.php')) {
if (!goTo('移至餐台')) {
if (!goTo('清洁')) {
if (!goTo('做菜')) {
if (!goTo('继续做菜')) {
GM_log('Sleeping for '+ setting.reloadInterval /1000 + ' seconds now');
window.setTimeout('window.location.reload()',setting.reloadInterval)
}
}
}
}
}else if(isLocation('/menu.php')){
dishid=randDishID()
goDish(dishid)
}else if (isLocation('/clean.php')) {
goTo('做菜')
}else if (isLocation('/cook.php')) {
goHome()
}else {
if(setting.cookLastDish==true)
goContinue()
else
goAnother()
//goHome()
}
}
this.loadFunc = function() {
runThis()
}
randDishID = function(){
if(setting.dish.length > 1){
weight=0
for(i=0;i<setting>
weight+=setting.dish[i].weight
setting.dish[i].position=weight
}
r=Math.random()*weight
for(i=0;i<setting>
if(r < setting.dish[i].position){
dishid=setting.dish[i].id
break;
}
}

}else if(setting.dish.length == 1){
dishid=setting.dish[0].id
}
return dishid;
}
}
})()
[/code]

 
MaShize User
FirefoxWindows

It doesn't work.

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel