<?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>Rest Valley &#187; GreaseMonkey</title> <atom:link href="http://lihdd.net/tag/greasemonkey/feed/" rel="self" type="application/rss+xml" /><link>http://lihdd.net</link> <description>The scratchpad of quark</description> <lastBuildDate>Sat, 09 Oct 2010 13:56:19 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=</generator> <item><title>防止Google对搜索结果重定向</title><link>http://lihdd.net/stop-google-relink/</link> <comments>http://lihdd.net/stop-google-relink/#comments</comments> <pubDate>Fri, 30 Oct 2009 06:46:44 +0000</pubDate> <dc:creator>quark</dc:creator> <category><![CDATA[Script]]></category> <category><![CDATA[Google]]></category> <category><![CDATA[GreaseMonkey]]></category><guid
isPermaLink="false">http://lihdd.net/?p=256</guid> <description><![CDATA[最近，hzqtc 推荐了一个GreaseMonkey脚本，可以把Google搜索的结果分两栏显示，自动加载后一页的内容，防止结果经过重定向，还可以为结果编号，加载favicon等等。 这个脚本目前在我这里会有一个问题，会导致Google的“Show more results from xxxx”失效。我会用到这个功能，于是只好不用这个“神一样的GM脚本”了 那么还是有其它做法达到一些关键功能的，比如自动加载后一页可以用Firefox的AutoPager扩展完成，在支持CSS3的Firefox中用Stylish扩展，为搜索结果页应用 .med { -moz-column-count: 2;} 这样的样式就有两栏了。 关于Google把搜索结果重定向，跟踪用户点击这一点，确实令人很不爽。hzqtc曾经介绍的方法现在由于Google使用AJAX加载搜索结果，变得不能用了。那么再做一个可以用的吧 Google搜索结果的链接都写有onmousedown="rwt(....)"，这个rwt函数会改写用户单击的链接： window.rwt=function&#40;a,d,e,i,j,f,k,l&#41;&#123; try&#123; if&#40;a===window&#41;&#123; a=window.event.srcElement; while&#40;a&#41;&#123; if&#40;a.href&#41;break; a=a.parentNode &#125; &#125; var b=encodeURIComponent&#124;&#124;escape; var m=&#91;&#34;/url?sa=t&#34;,&#34;\x26source\x3dweb&#34;,d?&#34;&#38;oi=&#34;+b&#40;d&#41;:&#34;&#34;,e?&#34;&#38;cad=&#34;+b&#40;e&#41;:&#34;&#34;,&#34;&#38;ct=&#34;,b&#40;i&#124;&#124;&#34;res&#34;&#41;,&#34;&#38;cd=&#34;,b&#40;j&#41;,&#34;&#38;ved=&#34;,b&#40;l&#41;,&#34;&#38;url=&#34;,b&#40;a.href&#41;.replace&#40;/\+/g,&#34;%2B&#34;&#41;,&#34;&#38;ei=&#34;,&#34;dIHqSoSTDsOXkAX9huGPDw&#34;,f?&#34;&#38;usg=&#34;+f:&#34;&#34;,k&#93;.join&#40;&#34;&#34;&#41;; a.href=m;a.onmousedown=&#34;&#34; &#125; catch&#40;n&#41;&#123;&#125; return true &#125;; 那么不同的对策也有了 :-) 消灭（带有rwt函数的）onmousedown 由于Google使用AJAX加载搜索结果，要在其加载完成后才去做这个事情 替换掉rwt函数 这里我使用第二种方法，比较简单一些，如何用GreaseMonkey脚本替换一个js函数在GreaseMonkey的Wiki有说明。 最后的脚本就是这样的，可以在这里找到： function rwt&#40;&#41; &#123; return true; &#125; &#160; function embedFunction&#40;s&#41; &#123; document.body.appendChild&#40;document.createElement&#40;'script'&#41;&#41;.innerHTML=s.toString&#40;&#41;.replace&#40;/([\s\S]*?return;){2}([\s\S]*)}/,'$2'&#41;; &#125; &#160; embedFunction&#40;rwt&#41;;]]></description> <content:encoded><![CDATA[<p>最近，<a
href="http://hzqtcblog.appspot.com/">hzqtc</a> <a
href="http://hzqtcblog.appspot.com/article.jsp?articleid=lmshcyirks">推荐了一个GreaseMonkey脚本</a>，可以把Google搜索的结果分两栏显示，自动加载后一页的内容，防止结果经过重定向，还可以为结果编号，加载favicon等等。</p><p>这个脚本目前在我这里会有一个问题，会导致Google的“Show more results from xxxx”失效。我会用到这个功能，于是只好不用这个“神一样的GM脚本”了 <img
src='http://lihdd.net/wp-includes/images/smilies/icon_redface.gif' alt=':oops:' class='wp-smiley' /></p><p>那么还是有其它做法达到一些关键功能的，比如自动加载后一页可以用Firefox的AutoPager扩展完成，在支持CSS3的Firefox中用Stylish扩展，为搜索结果页应用 <code>.med { -moz-column-count: 2;}</code> 这样的样式就有两栏了。</p><p>关于Google把搜索结果重定向，跟踪用户点击这一点，确实令人很不爽。<a
href="http://hzqtcblog.appspot.com/article.jsp?articleid=owbecsnjch">hzqtc曾经介绍的方法</a>现在由于Google使用AJAX加载搜索结果，变得不能用了。那么再做一个可以用的吧 <img
src='http://lihdd.net/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' /> <span
id="more-256"></span></p><p>Google搜索结果的链接都写有<code>onmousedown="rwt(....)"</code>，这个rwt函数会改写用户单击的链接：</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">rwt</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>d<span style="color: #339933;">,</span>e<span style="color: #339933;">,</span>i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>f<span style="color: #339933;">,</span>k<span style="color: #339933;">,</span>l<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">===</span>window<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			a<span style="color: #339933;">=</span>window.<span style="color: #660066;">event</span>.<span style="color: #660066;">srcElement</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span><span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
				a<span style="color: #339933;">=</span>a.<span style="color: #660066;">parentNode</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003366; font-weight: bold;">var</span> b<span style="color: #339933;">=</span>encodeURIComponent<span style="color: #339933;">||</span>escape<span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> m<span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;/url?sa=t&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>26source<span style="color: #000099; font-weight: bold;">\x</span>3dweb&quot;</span><span style="color: #339933;">,</span>d<span style="color: #339933;">?</span><span style="color: #3366CC;">&quot;&amp;oi=&quot;</span><span style="color: #339933;">+</span>b<span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>e<span style="color: #339933;">?</span><span style="color: #3366CC;">&quot;&amp;cad=&quot;</span><span style="color: #339933;">+</span>b<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&amp;ct=&quot;</span><span style="color: #339933;">,</span>b<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">||</span><span style="color: #3366CC;">&quot;res&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&amp;cd=&quot;</span><span style="color: #339933;">,</span>b<span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&amp;ved=&quot;</span><span style="color: #339933;">,</span>b<span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&amp;url=&quot;</span><span style="color: #339933;">,</span>b<span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\+/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;%2B&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&amp;ei=&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;dIHqSoSTDsOXkAX9huGPDw&quot;</span><span style="color: #339933;">,</span>f<span style="color: #339933;">?</span><span style="color: #3366CC;">&quot;&amp;usg=&quot;</span><span style="color: #339933;">+</span>f<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		a.<span style="color: #660066;">href</span><span style="color: #339933;">=</span>m<span style="color: #339933;">;</span>a.<span style="color: #660066;">onmousedown</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div><p>那么不同的对策也有了 :-)</p><ul><li>消灭（带有rwt函数的）onmousedown<br
/> 由于Google使用AJAX加载搜索结果，要在其加载完成后才去做这个事情</li><li>替换掉rwt函数</li></ul><p>这里我使用第二种方法，比较简单一些，如何用GreaseMonkey脚本替换一个js函数在<a
href="http://wiki.greasespot.net/Code_snippets#Embed_a_function_in_the_current_page">GreaseMonkey的Wiki</a>有说明。</p><p>最后的脚本就是这样的，可以在<a
href="http://userscripts.org/scripts/show/60856">这里</a>找到：</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> rwt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> embedFunction<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span>s.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/([\s\S]*?return;){2}([\s\S]*)}/</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'$2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
embedFunction<span style="color: #009900;">&#40;</span>rwt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>]]></content:encoded> <wfw:commentRss>http://lihdd.net/stop-google-relink/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: lihdd.net @ 2012-05-19 12:51:01 -->
