forked from lurongkai/anti-baidu
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
146 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
// Author: http://weibo.com/fanweixiao | ||
// Revision: http://weibo.com/lengleng3898 | ||
// Version: 0.5 | ||
|
||
(function(){ | ||
"use strict"; | ||
|
||
var jQuery_cdn = "http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"; | ||
var js_files = "http://lurongkai.github.com/anti-baidu/js/jquery.bpopup-0.8.0.min.js"; | ||
|
||
var jQueryLoader = function(){ | ||
// Only do anything if jQuery isn't defined | ||
if (typeof jQuery === 'undefined') { | ||
var getScript = function(url, successFunction) { | ||
var script = document.createElement('script'); | ||
script.src = url; | ||
(function() { | ||
"use strict"; | ||
|
||
var head = document.getElementsByTagName('head')[0], | ||
done = false; | ||
// Attach handlers for all browsers | ||
script.onload = script.onreadystatechange = function() { | ||
if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) { | ||
done = true; | ||
// callback function provided as param | ||
successFunction(); | ||
script.onload = script.onreadystatechange = null; | ||
head.removeChild(script); | ||
} | ||
}; | ||
head.appendChild(script); | ||
}; | ||
var js_files = ["http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js", "http://lurongkai.github.com/anti-baidu/js/jquery.bpopup-0.8.0.min.js"]; | ||
|
||
getScript(jQuery_cdn, function() { | ||
if (typeof jQuery === 'undefined') { // Super failsafe - still somehow failed... | ||
return; | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
var antiBaiduPopup = function($){ | ||
$.getScript(js_files[0]); | ||
$(document).ready(function(){ | ||
var antiDiv = '<div id="nobaidu_dlg" style="background-color:#fff; border-radius:15px;color:#000;display:none;padding:20px;min-width:450px;min-height:180px;"><img src="http://lurongkai.github.com/anti-baidu/images/nobaidu.jpg" align="left"><p style="margin-left:200px;margin-top: 20px; line-height: 30px;">检测到你还在使用百度这个搜索引擎,<br>作为一个程序员,这是一种自暴自弃!<br><br></p><p align="center" style="margin-top:20px;"><b><a href="http://coolshell.cn/articles/9308.html">做环保的程序员,从不用百度开始!</a></b></p></div>'; | ||
$("body").append(antiDiv); | ||
// Actually, When antiBaidu Popup function be invoked, it is already proved that refer is Baidu. | ||
$('#nobaidu_dlg').bPopup(); | ||
}); | ||
}; | ||
|
||
var antiBaiduHandler = function(){ | ||
jQueryLoader(); | ||
antiBaiduPopup(jQuery); | ||
}; | ||
|
||
var isReferBaidu = function(){ | ||
var url=document.referrer; | ||
if (url && url.search("http://")>-1) { | ||
var refurl = url.match(/:\/\/(.[^/]+)/)[1]; | ||
if(refurl.indexOf("baidu.com")>-1){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
if (isReferBaidu) { | ||
antiBaiduHandler(antiBaiduPopup); | ||
} | ||
})(); | ||
var jQueryLoader = function(loadSuccessCallback) { | ||
// Only do anything if jQuery isn't defined | ||
if (typeof jQuery === 'undefined') { | ||
var getScript = function(url, successFunction) { | ||
var script = document.createElement('script'); | ||
script.src = url; | ||
|
||
var head = document.getElementsByTagName('head')[0], | ||
done = false; | ||
// Attach handlers for all browsers | ||
script.onload = script.onreadystatechange = function() { | ||
if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) { | ||
done = true; | ||
// callback function provided as param | ||
successFunction(jQuery); | ||
script.onload = script.onreadystatechange = null; | ||
head.removeChild(script); | ||
} | ||
}; | ||
head.appendChild(script); | ||
}; | ||
|
||
getScript(js_files[0], function() { | ||
if (typeof jQuery === 'undefined') { // Super failsafe - still somehow failed... | ||
return; | ||
} | ||
loadSuccessCallback(jQuery); | ||
}); | ||
} | ||
}; | ||
|
||
var antiBaiduPopup = function($) { | ||
$.getScript(js_files[1]); | ||
$(document).ready(function() { | ||
var antiDiv = '<div id="nobaidu_dlg" style="background-color:#fff; border-radius:15px;color:#000;display:none;padding:20px;min-width:450px;min-height:180px;"><img src="http://lurongkai.github.com/anti-baidu/images/nobaidu.jpg" align="left"><p style="margin-left:200px;margin-top: 20px; line-height: 30px;">检测到你还在使用百度这个搜索引擎,<br>作为一个程序员,这是一种自暴自弃!<br><br></p><p align="center" style="margin-top:20px;"><b><a href="http://coolshell.cn/articles/9308.html">做环保的程序员,从不用百度开始!</a></b></p></div>'; | ||
$("body").append(antiDiv); | ||
// Actually, When antiBaidu Popup function be invoked, it is already proved that refer is Baidu. | ||
$('#nobaidu_dlg').bPopup(); | ||
}); | ||
}; | ||
|
||
var antiBaiduHandler = function() { | ||
jQueryLoader(antiBaiduPopup); | ||
}; | ||
|
||
var isReferBaidu = function() { | ||
var url = document.referrer; | ||
if (url && url.search("http://") > -1) { | ||
var refurl = url.match(/:\/\/(.[^/]+)/)[1]; | ||
if (refurl.indexOf("baidu.com") > -1) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
if (isReferBaidu) { | ||
antiBaiduHandler(); | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
// Author: http://weibo.com/fanweixiao | ||
// Revision: http://weibo.com/lengleng3898 | ||
// Version: 0.5 | ||
|
||
(function(){ | ||
"use strict"; | ||
|
||
var jQuery_cdn = "http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"; | ||
var js_files = "http://lurongkai.github.com/anti-baidu/js/jquery.bpopup-0.8.0.min.js"; | ||
|
||
var jQueryLoader = function(){ | ||
// Only do anything if jQuery isn't defined | ||
if (typeof jQuery === 'undefined') { | ||
var getScript = function(url, successFunction) { | ||
var script = document.createElement('script'); | ||
script.src = url; | ||
(function() { | ||
"use strict"; | ||
|
||
var head = document.getElementsByTagName('head')[0], | ||
done = false; | ||
// Attach handlers for all browsers | ||
script.onload = script.onreadystatechange = function() { | ||
if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) { | ||
done = true; | ||
// callback function provided as param | ||
successFunction(); | ||
script.onload = script.onreadystatechange = null; | ||
head.removeChild(script); | ||
} | ||
}; | ||
head.appendChild(script); | ||
}; | ||
var js_files = ["http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js", "http://lurongkai.github.com/anti-baidu/js/jquery.bpopup-0.8.0.min.js"]; | ||
|
||
getScript(jQuery_cdn, function() { | ||
if (typeof jQuery === 'undefined') { // Super failsafe - still somehow failed... | ||
return; | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
var antiBaiduPopup = function($){ | ||
$.getScript(js_files[0]); | ||
$(document).ready(function(){ | ||
var antiDiv = '<div id="nobaidu_dlg" style="background-color:#fff; border-radius:15px;color:#000;display:none;padding:20px;min-width:450px;min-height:180px;"><img src="http://lurongkai.github.com/anti-baidu/images/nobaidu.jpg" align="left"><p style="margin-left:200px;margin-top: 20px; line-height: 30px;">检测到你还在使用百度这个搜索引擎,<br>作为一个程序员,这是一种自暴自弃!<br><br></p><p align="center" style="margin-top:20px;"><b><a href="http://coolshell.cn/articles/9308.html">做环保的程序员,从不用百度开始!</a></b></p></div>'; | ||
$("body").append(antiDiv); | ||
// Actually, When antiBaidu Popup function be invoked, it is already proved that refer is Baidu. | ||
$('#nobaidu_dlg').bPopup(); | ||
}); | ||
}; | ||
|
||
var antiBaiduHandler = function(){ | ||
jQueryLoader(); | ||
antiBaiduPopup(jQuery); | ||
}; | ||
|
||
var isReferBaidu = function(){ | ||
var url=document.referrer; | ||
if (url && url.search("http://")>-1) { | ||
var refurl = url.match(/:\/\/(.[^/]+)/)[1]; | ||
if(refurl.indexOf("baidu.com")>-1){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
if (isReferBaidu) { | ||
antiBaiduHandler(antiBaiduPopup); | ||
} | ||
})(); | ||
var jQueryLoader = function(loadSuccessCallback) { | ||
// Only do anything if jQuery isn't defined | ||
if (typeof jQuery === 'undefined') { | ||
var getScript = function(url, successFunction) { | ||
var script = document.createElement('script'); | ||
script.src = url; | ||
|
||
var head = document.getElementsByTagName('head')[0], | ||
done = false; | ||
// Attach handlers for all browsers | ||
script.onload = script.onreadystatechange = function() { | ||
if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) { | ||
done = true; | ||
// callback function provided as param | ||
successFunction(jQuery); | ||
script.onload = script.onreadystatechange = null; | ||
head.removeChild(script); | ||
} | ||
}; | ||
head.appendChild(script); | ||
}; | ||
|
||
getScript(js_files[0], function() { | ||
if (typeof jQuery === 'undefined') { // Super failsafe - still somehow failed... | ||
return; | ||
} | ||
loadSuccessCallback(jQuery); | ||
}); | ||
} | ||
}; | ||
|
||
var antiBaiduPopup = function($) { | ||
$.getScript(js_files[1]); | ||
$(document).ready(function() { | ||
var antiDiv = '<div id="nobaidu_dlg" style="background-color:#fff; border-radius:15px;color:#000;display:none;padding:20px;min-width:450px;min-height:180px;"><img src="http://lurongkai.github.com/anti-baidu/images/nobaidu.jpg" align="left"><p style="margin-left:200px;margin-top: 20px; line-height: 30px;">检测到你还在使用百度这个搜索引擎,<br>作为一个程序员,这是一种自暴自弃!<br><br></p><p align="center" style="margin-top:20px;"><b><a href="http://coolshell.cn/articles/9308.html">做环保的程序员,从不用百度开始!</a></b></p></div>'; | ||
$("body").append(antiDiv); | ||
// Actually, When antiBaidu Popup function be invoked, it is already proved that refer is Baidu. | ||
$('#nobaidu_dlg').bPopup(); | ||
}); | ||
}; | ||
|
||
var antiBaiduHandler = function() { | ||
jQueryLoader(antiBaiduPopup); | ||
}; | ||
|
||
var isReferBaidu = function() { | ||
var url = document.referrer; | ||
if (url && url.search("http://") > -1) { | ||
var refurl = url.match(/:\/\/(.[^/]+)/)[1]; | ||
if (refurl.indexOf("baidu.com") > -1) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
if (isReferBaidu) { | ||
antiBaiduHandler(); | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>anti-baidu-test</title> | ||
<script type="text/javascript" src="js/anti-baidu-latest.js" charset="UTF-8"></script> | ||
</head> | ||
<body> | ||
change isReferBaidu before test. | ||
</body> | ||
</html> |