<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>风雪之隅 &#187; 开心网</title>
	<atom:link href="http://www.laruence.com/tag/%e5%bc%80%e5%bf%83%e7%bd%91/feed" rel="self" type="application/rss+xml" />
	<link>http://www.laruence.com</link>
	<description>PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 - 左手代码 右手诗</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:12:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>开心网偷菜外挂</title>
		<link>http://www.laruence.com/2009/06/01/905.html</link>
		<comments>http://www.laruence.com/2009/06/01/905.html#comments</comments>
		<pubDate>Mon, 01 Jun 2009 09:33:26 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[偷菜]]></category>
		<category><![CDATA[外挂]]></category>
		<category><![CDATA[开心网]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=905</guid>
		<description><![CDATA[  一个基于greaseMonkey的开心网(kaixin001)牧场偷菜外挂.

  这个版本:

      1. 修整了一个问题应付最近的开心网调整. 

      2. 使用OOP重写
    
      3. 应对了开心网2009.06.09的接口调整

  如果不知道怎么使用,请google"greaseMonkey".
  
  基于Gxd(<a href='http://onemouse.cn/i/608' target='_blank'>onmouse.cn</a>)的version 0.0.1重写]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/06/01/905.html"  title="Permanet Link to 开心网偷菜外挂" >http://www.laruence.com/2009/06/01/905.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>  一个基于greaseMonkey的开心网(kaixin001)偷菜外挂.</p>
<p>  这个版本:</p>
<p>      1. 修整了一个问题应付最近的开心网调整. </p>
<p>      2. 使用OOP重写</p>
<p>  如果不知道怎么使用,请google&#8221;greaseMonkey&#8221;.</p>
<p>  changelog:<br/>
  version 1.0.2:开心网调整了URL, 已经调整相应策略. 2009.06.09</p>
<p>  基于Gxd(<a href="http://onemouse.cn/i/608"  target="_blank" >onmouse.cn</a>)的version 0.0.1重写
</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
// ==UserScript==
// @name           kaixin.app.garden
// @namespace      Kaixin.app.garden
// @description    Garden for kaixin001.com
// @version 	   1.0.3
// @author		   laruence based on Gxd(onemouse.cn) version 1.0.0
// @include        http://www.kaixin001.com/!house/garden/index.php*
// ==/UserScript==

var Ganov = function() {
	/**
	 * various url we need to post/get
	 */
	var conf_url = 'http://www.kaixin001.com/!house/!garden/getconf.php';
	var friend_url = 'http://www.kaixin001.com/interface/suggestfriend.php?type=all';
	var havest_url = 'http://www.kaixin001.com/!house/!garden/havest.php';
	var mature_url = 'http://www.kaixin001.com/!house/!garden/getfriendmature.php';
	var water_url = 'http://www.kaixin001.com/!house/!garden/water.php';

	/**
	 * refer to the host function
	 */
	var verify = unsafeWindow.g_verify;

	/**
	 * running state relative variables
	 */
	var _self = this;

	var msgDiv = 0;
	var btn  = null;
	var flag = false;

	var friends = [];

	var links = [];
	var cursor = 0;
	var done = 1;
	var running = 0;

	if ( !Ganov.__intialized__ ) {
		Ganov.prototype.ownerInfo = function(name, uid){
			var xurl = conf_url + '?fuid=' + uid + '&amp;r=' + Math.random() + '&amp;verify=' + verify;
			GM_xmlhttpRequest( {
				method : &quot;GET&quot;,
				url : xurl,
				onload : function(o) {
					var txt = o.responseText;
					// 没有安装该应用
					if(txt.substr(0, 5).replace(/(\s*)/,&quot;&quot;) != &quot;&lt;conf&quot;) {
						return;
					}
					// 去掉某些不可见字符。
					txt = txt.replace(/&lt;steal&gt;(.*)&lt;\/steal&gt;/,&quot;&quot;);
					var docParser = new DOMParser();
					try {
						var doc = docParser.parseFromString(txt, &quot;application/xml&quot;);

						var xml = xml2array(doc);
						var items = xml.conf.garden.item;
						var name = xml.conf.account.name
					        for(var i in items) {
							var farmNum = items[i].farmnum;

							//0 非爱心田， 1 爱心田
							var shared = items[i].shared;
							if(shared == 1) {
								//GM_log(&quot; shared go&quot;);
								continue;
							}

							var status = items[i].status;
							if(status  &lt; 1) {
								//GM_log(&quot; status go &quot;);
								continue;
							}
							/*
							var cropsid = items[i].cropsid;
							if(cropsid &lt; 1) {
								continue;
							}
							*/
							//cropsStatus = 1 , 未成熟，2 成熟, -1 偷完了。
							var cropsStatus = items[i].cropsstatus;

							if(cropsStatus != 2) {
								continue;
							}
							/*
							var water = items[i].water;
							GM_log(water);
							if(water &lt; 5) {
								// XXX to water
								_self.water(uid, farmNum);
							}
							*/
							var crops = items[i].crops;
							if(crops.indexOf(&quot;已偷&quot;) &lt; 1) {
								links.push({'name' : name, 'farmNum' : farmNum, 'fuid' : uid});
								_self.beginSteal();
							} else {
								_self.log(&quot;已经偷过 &quot; + name + &quot; &quot; + '的第' + farmNum + &quot;块地的菜了&quot;);
							}
						}

					} catch(e) {
						_self.log(e);
						_self.log(txt);
					}
				}
			});
		}

		Ganov.prototype.beginSteal = function(){
			if( !running ) {
				_self.doSteal();
				running = 1;
			}
		}

		Ganov.prototype.doSteal = function(){
			if ( done ) {
				done = 0;
				if(cursor &lt; links.length) {
					var curData = links[cursor];
					var murl = (havest_url + '?farmnum=' + curData.farmNum + '&amp;verify=' + verify + '&amp;seedid=0&amp;r=' + Math.random() + '&amp;fuid=' + curData.fuid);
					GM_xmlhttpRequest({
						method : 'GET',
						url : murl,
						onload : function(o) {
							var xml = o.responseText;
							var parser = new DOMParser();
							var doc = parser.parseFromString(xml, &quot;application/xml&quot;);
							var d = xml2array(doc);

							if(d.data.ret &amp;&amp; d.data.ret == 'fail') {
								_self.log(&quot;偷 &quot; + curData.name + &quot; 失败，原因: &quot; + d.data.reason);
							} else if(d.data.ret &amp;&amp; d.data.ret == 'succ'){
								_self.log(&quot;您偷了&quot; + curData.name + &quot;　&quot; + d.data.stealnum + ' 个 '　+　d.data.seedname);
							} else {
								_self.log(&quot;Some error occur when steal &quot; + curData.name + &quot;:&quot;　+ murl);
							}
							done = 1;
						}
					});
					cursor ++;
				}
			}
			setTimeout(_self.doSteal, 3000);
		}

		Ganov.prototype.start = function(){
			var murl = mature_url + '?verify=' + verify + '&amp;r=' + Math.random();
			GM_xmlhttpRequest(
			{
				method : 'GET',
				url : murl,
				onload : function (o) {
					var txt = o.responseText;
					var ret = [];
					try {
						eval(&quot;ret = &quot; + txt + &quot;;&quot;);
					} catch(e) {
						GM_log(&quot;get data error &quot; + murl);
						GM_log(&quot;return is &quot; + txt);
					}

					ret.friend.forEach(function(user){
						_self.ownerInfo(user.realname, user.uid);
					});
				}
			}
			);
		}

		Ganov.prototype.init = function(){
			if(!btn) {
				var x = document.createElement(&quot;div&quot;);
				x.id = &quot;m-btn-o&quot;;
				x.innerHTML = &quot;&lt;style&gt;#m-btn-o{border:solid 2px red;background-color:#ccc;left:740px;top:110px;position:absolute;}&lt;/style&gt;&quot;;
				x.innerHTML += &quot;&lt;button id='m-btn'&gt;Begin to Steal&lt;/button&gt;&quot;;
				document.body.appendChild(x);
				btn = document.getElementById(&quot;m-btn&quot;);
				btn.addEventListener(&quot;click&quot;, _self.start, false);
			}
		}

		Ganov.prototype.log = function(msg){
			if(!msgDiv) {
				var c = document.createElement(&quot;div&quot;);
				c.id = &quot;m-msg-o&quot;;
				c.innerHTML = &quot;&lt;style&gt;#m-msg{border:solid 2px red;background-color:#ccc;position:absolute;left:10px;top:100px;}&lt;/style&gt;&quot;;
				c.innerHTML += &quot;&lt;div class='title'&gt;&lt;/div&gt;&lt;div class='body' id='m-msg'&gt;&lt;/div&gt;&lt;div class='footer'&gt;&lt;/div&gt;&quot;;
				document.body.appendChild(c);
				msgDiv = document.getElementById(&quot;m-msg&quot;);
				msgDiv.innerHTML = &quot;结果:&lt;br/&gt;&quot;;
			}
			msgDiv.innerHTML += msg + &quot;&lt;br/&gt;&quot;;
		}

		Ganov.prototype.water = function(fuid, farmNum){
			GM_xmlhttpRequest({
				method : 'GET',
				url : water_url + '?fuid=' + fuid + '&amp;verify' + verify + '&amp;seedid=0&amp;farmnum=' +farmNum + '&amp;r=' + Math.random(),
				onload:function(o){GM_log(&quot;done&quot;);},
				onfaiure : function(o){GM_log(&quot;fail&quot;);}
			});
		}
		Ganov.__intialized__ = true;
	}
}

//copy from http://www.openjs.com/scripts/xml_parser/xml2array.js
var not_whitespace = new RegExp(/[^\s]/);
//This can be given inside the funciton - I made it a global variable to make the scipt a little bit faster.
var parent_count;

function xml2array(xmlDoc, parent_count){
	var arr;
	var parent = &quot;&quot;;
	parent_count = parent_count || new Object;

	var attribute_inside = 0; /*:CONFIG: Value - 1 or 0
							   *	If 1, Value and Attribute will be shown inside the tag - like this...
							   *	For the XML string...
							   *	&lt;guid isPermaLink=&quot;true&quot;&gt;http://www.bin-co.com/&lt;/guid&gt;
							   *	The resulting array will be...
							   *	array['guid']['value'] = &quot;http://www.bin-co.com/&quot;;
							   *	array['guid']['attribute_isPermaLink'] = &quot;true&quot;;
							   *
							   *	If 0, the value will be inside the tag but the attribute will be outside - like this...
							   *	For the same XML String the resulting array will be...
							   *	array['guid'] = &quot;http://www.bin-co.com/&quot;;
							   *	array['attribute_guid_isPermaLink'] = &quot;true&quot;;
							   */

	if(xmlDoc.nodeName &amp;&amp; xmlDoc.nodeName.charAt(0) != &quot;#&quot;) {
		if(xmlDoc.childNodes.length &gt; 1) { //If its a parent
			arr = new Object;
			parent = xmlDoc.nodeName;

		}
	}
	var value = xmlDoc.nodeValue;
	if(xmlDoc.parentNode &amp;&amp; xmlDoc.parentNode.nodeName &amp;&amp; value) {
		if(not_whitespace.test(value)) {//If its a child
			arr = new Object;
			arr[xmlDoc.parentNode.nodeName] = value;
		}
	}

	if(xmlDoc.childNodes.length) {
		if(xmlDoc.childNodes.length == 1) { //Just one item in this tag.
			arr = xml2array(xmlDoc.childNodes[0],parent_count); //:RECURSION:
		} else { //If there is more than one childNodes, go thru them one by one and get their results.
			var index = 0;

			for(var i=0; i&lt;xmlDoc.childNodes.length; i++) {//Go thru all the child nodes.
				var temp = xml2array(xmlDoc.childNodes[i],parent_count); //:RECURSION:
				if(temp) {
					var assoc = false;
					var arr_count = 0;
					for(key in temp) {
						if(isNaN(key)) assoc = true;
						arr_count++;
						if(arr_count&gt;2) break;//We just need to know wether it is a single value array or not
					}

					if(assoc &amp;&amp; arr_count == 1) {
						if(arr[key]) { 	//If another element exists with the same tag name before,
							//		put it in a numeric array.
							//Find out how many time this parent made its appearance
							if(!parent_count || !parent_count[key]) {
								parent_count[key] = 0;

								var temp_arr = arr[key];
								arr[key] = new Object;
								arr[key][0] = temp_arr;
							}
							parent_count[key]++;
							arr[key][parent_count[key]] = temp[key]; //Members of of a numeric array
						} else {
							parent_count[key] = 0;
							arr[key] = temp[key];
							if(xmlDoc.childNodes[i].attributes &amp;&amp; xmlDoc.childNodes[i].attributes.length) {
								for(var j=0; j&lt;xmlDoc.childNodes[i].attributes.length; j++) {
									var nname = xmlDoc.childNodes[i].attributes[j].nodeName;
									if(nname) {
										/* Value and Attribute inside the tag */
										if(attribute_inside) {
											var temp_arr = arr[key];
											arr[key] = new Object;
											arr[key]['value'] = temp_arr;
											arr[key]['attribute_'+nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
										} else {
											/* Value in the tag and Attribute otside the tag(in parent) */
											arr['attribute_' + key + '_' + nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
										}
									}
								} //End of 'for(var j=0; j&lt;xmlDoc. ...'
							} //End of 'if(xmlDoc.childNodes[i] ...'
						}
					} else {
						arr[index] = temp;
						index++;
					}
				} //End of 'if(temp) {'
			} //End of 'for(var i=0; i&lt;xmlDoc. ...'
			}
		}
		if(parent &amp;&amp; arr) {
			var temp = arr;
			arr = new Object;

			arr[parent] = temp;
		}
		return arr;
}
var ganov = new Ganov();
ganov.init();
</pre>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/01</a>, <a href="http://onemouse.cn"  rel="external nofollow"  class="url" >anders</a> writes: 我已经决定不玩了这个东西了，本来我以为，我可以买所有的菜以后，我就不玩了，没有想到他又出来一个养动物的，太麻烦了，所以就戒了!</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/01</a>, laruence writes: 恩, 我是拿来练练手, 最近研究JS的一些机制</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/01</a>, <a href="http://www.neatcn.com"  rel="external nofollow"  class="url" >膘叔</a> writes: 想不到。。。用JS来完成这些操作，很意外。。
不过没测试过</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/03</a>, anders writes: 一样的名字么？</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/05</a>, toms writes: 不好意思， 我又来了，我怎么在在父框架调用iframe里的函数啊</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/05</a>, laruence writes: 可以通过iframe.contentWindow来获取iframe的window对象</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/07</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 开心网最近搞了个"花园精灵",类似图片验证码之类的, 导致这个脚本运行的时候可能会不作用, 这个时候需要手动输入下那个验证就可以继续使用了</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/09</a>, eve writes: 忠实用户觉得最好把爱心地也能自动收获了，最好把自己田里的也收获了</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/12/17</a>, <a href="http://www.mreporter.net/page/24/"  rel="external nofollow"  class="url" >Тамара</a> writes: Кажется, это подойдет.</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2010/05/05</a>, apple writes: 好，不错</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/05/21/829.html"  title="JS文件装载器(Eve Js Loader)" >JS文件装载器(Eve Js Loader)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/06/01/905.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

