【转】Chrome去除干扰码插件,简单快捷!

来自:http://www.ra1nker.com/99.html

清除隐藏文字的脚本,方便拷贝一些经过特别处理过的网页文字,快捷键alt+q
将以下代码保存为cleanhidemod.user.js。再增加插件

// ==UserScript==
// @name ra1nker.com// @match http://*/*
// ==/UserScript==
var debug=false; //debug or release switch!!
var CleanHideObj=new CleanHideClass();
function CleanHideClass()
{
//functions;id mean cleanhid ,AppID mean call from firefox or mozilla (different! call from overlayFF or overlayMZ!)
this.on=function(id,bMZ)
{
//this.strBundle = document.getElementById("cleanhide-strings"); //get the strings use in js!
if(id == 0)
{
var page=/* document.getElementById("content").contentDocument */document; //main page
this.RemoveHide(page,"span");
this.RemoveHide(page,"font");
this.RemoveHide(page,"div");
this.RemoveHide(page,"p");
//alert(this.strBundle.getString("CleanHideSuccess"));
//document.getElementById("statusbar-display").label=this.strBundle.getString("CleanHideSuccess");
}}
this.getobjstyle=function(node,prop)
{
try
{
return node.ownerDocument.defaultView.getComputedStyle(node, "").getPropertyValue(prop);
}
catch(e)
{
if(debug)
{
alert(e.message);
}return "200";
}
}
this.RemoveHide=function(page,objname)
{
try
{
var minValue=25;
var objs=page.getElementsByTagName(objname); //get all element

if(objs.length == 0) //no span or font object found!
{
if(debug)
{
alert("no object found!:"+objname);
}
}
else
{
//determean every object!
for(var i=objs.length-1;i>=0;i--) //must from last to first!!! for detect every element!!
{
var node=objs.item(i); //get one element

//if this object is invisible,we delete it!!
if(this.getobjstyle(node,"display") == "none" ||
this.getobjstyle(node,"visibility") =="hidden" ||
parseInt(this.getobjstyle(node,"font-size")) == 0) //if this element'style is none,than remove it!!
{
if(debug)
{
alert("remove invisiable!");
}
node.parentNode.removeChild(node);

}
else //normal object!have color!
{
if(node.parentNode) //if it has parent node!!
{
var orgNode=node;
var orgColor=this.getobjstyle(orgNode,"color");
var orgRGB=getRGB(orgColor); //get org node's RGB only color.
var parentNode=node.parentNode
var parentBgColor=this.getobjstyle(parentNode,"background-color");

var isLast=false;
regtest=/rgba\((\s)*0,(\s)*0,(\s)*0,(\s)*0\)/;
while(regtest.test(parentBgColor)) //parent bg is transparent!!,get last no transparent node!!
{

if(parentNode.parentNode == null)
{
isLast=true;
break;
}
parentNode=parentNode.parentNode;
parentBgColor=this.getobjstyle(parentNode,"background-color");
parentBgColor=parentBgColor+"";
if(!regtest.test(parentBgColor))
{

break;
}
}
if(isLast) //body is RGB(255,255,255)!!!
{
if(debug)
{
alert("last!!");
}
if((Math.abs(orgRGB[0]-255)<=minValue)&&(Math.abs(orgRGB[1]-255)<=minValue)&&(Math.abs(orgRGB[2]-255)<=minValue))
{
orgNode.parentNode.removeChild(orgNode); //color is near white,we delete it!
}
}
else
{
if(debug)
{
alert("compare color and parent bgcolor!");
}
parentBgRGB=getRGB(parentBgColor);
if((Math.abs(orgRGB[0]-parentBgRGB[0])<=minValue)&&(Math.abs(orgRGB[1]-parentBgRGB[1])<=minValue)&&(Math.abs(orgRGB[2]-parentBgRGB[2])<=minValue))
{
orgNode.parentNode.removeChild(orgNode); //color is near white,we delete it!
}
}
}//end of hava parent
}//if invisible
}//for ... every object
}//object lentgth == 0

//find sub frames
var itemFrames = page.getElementsByTagName("frame");
var itemiFrames = page.getElementsByTagName("iframe");

var frame, iframe;
if (itemFrames.length > 0)
{
for (var i = 0 ; i< itemFrames.length ; i++)
{
frame = itemFrames[i].contentDocument;
this.RemoveHide(frame,objname); // recursion for frames
}
}
if (itemiFrames.length > 0)
{
for (var i = 0 ; i < itemiFrames.length ; i++)
{
iframe = itemiFrames[i].contentDocument;
this.RemoveHide(iframe,objname); // recursion for iframes
}
}
}
catch(e)
{
if(debug)
{
alert(e.message);
}
}
}

}
//this function for get R G B data from string rgb(r,g,b) or blue,etc
function getRGB(colorString)
{
var RGB = new Array;
var tempSting=colorString.substring(4,colorString.length-1);
var tempArray=tempSting.split(",");

RGB[0]=parseInt(tempArray[0]);
RGB[1]=parseInt(tempArray[1]);
RGB[2]=parseInt(tempArray[2]);

return RGB;
}
function keys(evt)
{ //var evt=evt?evt:(window.event?window.event:null);

if(evt.keyCode == 81 && !evt.shiftKey && !evt.ctrlKey && evt.altKey)
{
CleanHideObj.on(0,1);
alert("Ra1nker:成功去除干扰码");
}

}
document.addEventListener('keydown', keys, false);

【原创】Nginx Accesskey使用COOKIE作为KEY

网上有一篇文章是介绍使用COOKIE作为ACCESSKEY的KEY值的文章,以下是完整的方案:

NGINX 虚拟主机配置:

server
  {
    listen 80;
    server_name  www.yourdomian.com;
    root  /home/wwwroot/test;

if ( $http_cookie ~* " ng_cookie=(.+?)(?:;|$)")
{
    set $ng_cookie $1;
}

location /down/ {
  accesskey             on;
  accesskey_hashmethod  sha1;
  accesskey_arg         "token";
  accesskey_signature   "jzbk$ng_cookie";

}

location ~ .*\.(php|php5)?$ {
include php.conf;
        }

}

PHP部分:

0) $r.=$a{mt_rand(0,$l)}; 
   return $r; 
}
$key=code('32');//生成一个32位的随机值

$File='pure-ftpd'; //文件名

if(!isset($_COOKIE['ng_cookie'])) {
setcookie("ng_cookie",$key,time()+1800); //设置COOKIE有效期半小时
header("Refresh: 0"); //刷新页面
}

$token=sha1(jzbk.$_COOKIE['ng_cookie']); //KEY

echo '
'; echo "http://www.yourdomian.com/down/$File?token=$token"; //下载地址 echo '
'; echo $_COOKIE['ng_cookie']; ?>

FreeBSD开机自动同步时间。

最近把VPS系统换成了FreeBSD,发现每次重启之后时间都会不正确,使用以下的方法可以让FreeBSD在开机的时候自动使用NTP来校对时间。

编辑 /etc/rc.conf 加入以下代码:

ntpdate_enable="YES" # Run ntpdate to sync time on boot (or NO). 
ntpdate_program="ntpdate" # path to ntpdate, if you want a different one. 
ntpdate_flags="us.pool.ntp.org" # Flags to ntpdate (if enabled). 

WordPress前台不加载自带jQuery,去版本号等信息

现在很多WordPress主题和插件都使用jQuery,而且一般会直接调用Google的jQuery库,减轻我们服务器的负担,但WordPress本身会加载jQuery,这样就造成了重复载入,如下图所示:

那么如何让WordPress前台不加载本身jQuery?其实很简单,直接打开/wp-includes/script-loader.php文件,查找“jquery.js”字符串,在第122行能找到这么一句:

	$scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.7.2' );

由于在后台必须得用到这个库,我们不能将这一句直接删除或者注释掉。那么加个判断,让这一句只在后台的时候运行就信了,将其改为:

	if(is_admin()){
	$scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.7.2' );}

这样就OK啦!

注:由于直接修改了WordPress核心文件,如果你以后进行版本升级,记得查看这次修改是否被覆盖!

去掉版本号等信息

WordPress默认会加载wp_head,里面包含了版本号在内的很多信息,如下图所示:

如何去除这些多余的信息呢?也许你会说直接删除,但是你安装的插件一般都需要wp_head来加载插件必须的css和JS文件,所以我们不能直接删除。只要在主题根目录下的function.php中加入如下代码:

//移除顶部多余信息
function wpbeginner_remove_version() { 
return ; 
} add_filter('the_generator', 'wpbeginner_remove_version');//wordpress的版本号
remove_action('wp_head', 'feed_links', 2);// 包含文章和评论的feed 
remove_action('wp_head', 'index_rel_link');//当前文章的索引 
remove_action('wp_head', 'feed_links_extra', 3);// 额外的feed,例如category, tag页 
remove_action('wp_head', 'start_post_rel_link', 10, 0);// 开始篇 
remove_action('wp_head', 'parent_post_rel_link', 10, 0);// 父篇 
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // 上、下篇. 
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );//rel=pre
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 );//rel=shortlink 
remove_action('wp_head', 'rel_canonical' ); 
remove_action('wp_head', 'wlwmanifest_link'); // 外部编辑器
remove_action( 'wp_head','rsd_link');//ML-RPC

P.S:大部分内容来自:http://www.cmhello.com/remove-wordpress-jquery-and-other-information.html

使用SAE的jQuery节约又拍流量

使用又拍云加速BLOG几天了,在又拍后台的日志里看到,每日使用流量最多的就是jquery,为了节约又拍的流量,并且更好的加速,我们把jquery换成SAE的链接,方法如下。

P.S:如果你和我一样在WP中设置了CDN,我觉得只有方法1适合你!

1.在主题的header.php中找到相关语句改成一下样式:




2.或者是在主题的functions.php添加以下的代码:

//Making jQuery Google API in SAE
function my_scripts_method() {
if (!is_admin()){
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://lib.sinaapp.com/js/jquery/1.7.2/jquery.js');
wp_enqueue_script( 'jquery' );
}
}
add_action(‘wp_enqueue_scripts‘, ‘my_scripts_method’);

如果你需要其他版本,可以访问 http://lib.sinaapp.com/?path=/jquery 获取链接。

NGINX下可用的WP super cache规则

最近把BLOG的缓存换成了WP super cache,但是这个插件默认是运行在APACHE下面的,根据各种度娘谷歌后找到了对应的NGINX下的规则。
1.简洁形:

location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

2.完整形:

location / 
{ 

set $wp_super_cache_file ''; 
set $wp_super_cache_uri $request_uri;

if ( $request_method = POST ) 
{ 
set $wp_super_cache_uri ''; 
}

if ( $query_string ) 
{ 
set $wp_super_cache_uri ''; 
}

if ( $http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) 
{ 
set $wp_super_cache_uri ''; 
}

if ( $wp_super_cache_uri ~ ^(.+)$ ) 
{ 
set $wp_super_cache_file /wp-content/cache/wp_super_cache/$http_host/$1index.html; 
}

if ( -f $document_root$wp_super_cache_file ) 
{ 
rewrite ^(.*)$ $wp_super_cache_file break; 
}

if (-f $request_filename) 
{ 
expires 30d; 
break; 
}

if (!-e $request_filename) 
{ 
rewrite ^(.+)$ /index.php?q=$1 last; 
} 
}

说实话,对于这两种规则的区别不大搞得清,但是经测试都是可以用的,而且根据查看源码显示的都能正确读取到缓存,具体用哪一种就看自己的喜好了。

[转]WordPress在Nginx中启用Apache的mod_rewrite

其实不是真的可以另到 Nginx 支持 Apache 的 mod_rewrite 的.因为如果你的web服务器是 Nginx ,那么你的 WordPress 就会提示你的服务器环境不支持 mod_rewrite 了,但实际上是支持的,例如安装了 WP Super Cache 这插件就有这样的提示了,现在我们只要添加一行代码就可以关闭这个提示,欺骗WordPress ,让它认为是支持 mod_rewrite 方法是在主题的 functions.php 文件添加下面的代码:

add_filter('got_rewrite', 'nginx_has_rewrites');
function nginx_has_rewrites() {
    return true;
}

另外,因为Nginx运行PHP是用PHP-FPM的,所以有时会导致WordPress认为php没有写权限,表现为无法自动升级,和升级插件等,下面这个代码可以修改这个错误.

add_filter('filesystem_method', 'nginx_make_filesystem_direct');
function nginx_make_filesystem_direct() {
    return 'direct';
}

来自:http://imcat.in/wordpress-on-nginx-apache-mod_rewrite-enabled/

[转载]准确判断PHP上传的文件头

上传文件的功能是各类站点的基本功能,但是网络上也存在一些用心不良的人伪装图片或其他文件,上传一些木马或病毒到服务器上。普通php函数文件类型函数无法正确识别,安全的做法应该是头文件判断:

";
echo "gif:".checkTitle('img/weather.gif')."
"; echo "gif:".checkTitle('img/7768752.gif')."
"; echo "gif:".checkTitle('img/gif001.gif')."
"; echo "gif:".checkTitle('img/gif002.gif')."
"; echo "gif:".checkTitle('img/gif007.gif')."
"; echo "jpeg:".checkTitle('img/weather.jpg')."
"; echo "jpeg:".checkTitle('img/0001.jpg')."
"; echo "jpeg:".checkTitle('img/1.jpg')."
"; echo "jpeg:".checkTitle('img/0002.jpg')."
"; echo "jpeg:".checkTitle('img/4.jpg')."
"; echo "jpeg:".checkTitle('img/5.jpg')."
"; echo "jpeg:".checkTitle('img/71885.jpg')."
"; echo "jpeg:".checkTitle('img/imgad.jpg')."
"; echo "png:".checkTitle('img/weather.png')."
"; echo "png:".checkTitle('img/1.png')."
"; echo "png:".checkTitle('img/2.png')."
"; echo "png:".checkTitle('img/3.png')."
"; echo "png:".checkTitle('img/4.png')."
"; echo "png:".checkTitle('img/5.png')."
"; echo hexdec(89)."
"; echo hexdec(50)."
"; //6072,102119 ?>

使用WP Super Cache+CDN Sync Tool自动同步图片损坏的解决办法

今天终于把大家推荐的W3TC给换掉了,原因无他。消耗资源过多,并且效果不好。根据各种GOOGLE发现可以使用CDN Sync Tool+WP Super Cache来替代W3TC,在经过各种测试之后发现通过CDN Sync Tool自动同步到又拍云的图片全部都无法打开,把图片下载回本地发现无法打开,直接报错,如下图:

 

在使用Beyond CompareHA的16以16进制方式对文件进行对比后发现从又拍云中取回的文件比原始的多了一些0D并且比原始文件要稍微大一点。

根据各种GOOGLE之后得知,CDN Sync Tool使用的是FTP_ACSII方式对文件进行上传的。

 

ASCII模式
复制时候会进行调整,主要体现为对不同操作系统的回车/换行/结束符等进行转译。
比如,回车符号在Unix下是\n(0A),Windows下是\r\n(0D0A),Mac下是\r(0D)。当在一个Windows操作系统上用ASCII方式从Unix服务器上下载文件时——无论是文本文件还是二进制文件——都会进行检测和转换:每检测到一个0A,则认为是回车符号,自动插入0D形成Windows下的回车符。显然,如果下载的是文本文件,这种转换是很有用的——我们能在Windows下看到分行后的文本,否则我们看到的是中间夹杂着小黑方块的不换行的一堆文字;然而如果下载的是二进制文件(比如exe或rar),这种转换无异于画蛇添足,破坏了整个文件。

 

根据GOOGLE到的东西,我们来对源码做一点小手术,强制CDN Sync Tool来使用FTP_BINARY的二进制方式来上传文件。

1.打开 wp-content/plugins/cdn-sync-tool/lib/Cst.php
2.找到 ftp_put($this->cdnConnection, $filename, $file, FTP_ACSII); 这一句
3.修改成 ftp_put($this->cdnConnection, $filename, $file, FTP_BINARY);

现在再重新上传图片,就不会出问题了。

巧用nginx的sendfiles设置404

使用LNMP架构的朋友会知道,如果直接在PHP中进行header 404设置用户会访问到一个空白的页面,为了解决这种问题,我们可以使用NGINX的SENDFILE特性来让用户直接看到NGINX默认的404页面。

header('status: 404 Not Found');
header('X-Accel-Redirect: '.'1.exe');


这样设置,用户直接看到的就会直接是NGINX默认的404页面了。

设置前:

设置后: