Skip to content

Instantly share code, notes, and snippets.

View firedfox's full-sized avatar
🎯
Focusing

Daniel Wang firedfox

🎯
Focusing
  • Weimob
  • Shanghai, China
  • 17:20 (UTC +08:00)
View GitHub Profile
@firedfox
firedfox / gist:1729012
Created February 3, 2012 08:28
sampling code for zhidao
var isPicked = function(rate) {
var id = baidu.cookie.get('BAIDUID');
if (!id) { return false; }
id = id.replace(/:.*/, '');
for (var i = 0, l = id.length, sum = 0; i < l; i++) {
sum += id.charCodeAt(i);
}
return (sum % 100 < rate);
};
if (isPicked(30)) {
@firedfox
firedfox / gist:1922806
Created February 27, 2012 09:35
phantomjs page.onLoadFinished
var server = require('webserver').create();
var service = server.listen(8080, function (request, response) {
response.statusCode = 200;
response.write('\
<script> \
document.addEventListener("DOMContentLoaded", function() { console.log("DOMContentLoaded"); }, false); \
window.addEventListener("load", function() { console.log("window.onload"); }, false); \
</script>');
response.close();
@firedfox
firedfox / gist:1929623
Created February 28, 2012 04:45
gift_exchange_paging css
.gift_exchange_paging td {
width:16px;
height:16px;
text-align: center;
font-weight:bold;
border: 0px solid #006AB3;
font-size:12px;
}
.gift_exchange_paging td.current {
@firedfox
firedfox / gist:1929655
Created February 28, 2012 04:48
gift_exchange_paging html
<table class="gift_exchange_paging" cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="prev">&nbsp;</td>
<td class="current">1</td>
<td><a href="http://bb-testing-ps110.vm.baidu.com:8080/index.php/crowdtest/gift/exchange/type/3/page/2">2</a></td>
<td class="next"><a href="http://bb-testing-ps110.vm.baidu.com:8080/index.php/crowdtest/gift/exchange/type/3/page/2"></a></td>
</tr>
</table>
@firedfox
firedfox / gist:1966848
Created March 3, 2012 16:17
test "phantomjs --web-security=no"
var page = require('webpage').create();
page.settings.loadImages = false;
page.onConsoleMessage = function(msg) { console.log(msg); };
var count = 0;
page.onLoadFinished = function() {
(0 == count++) && page.evaluate(function() {
// cross-domain iframe access
var i = document.createElement('iframe');
i.src = 'http://www.phantomjs.org/';
@firedfox
firedfox / gist:2037411
Created March 14, 2012 15:49
check google ads with phantomjs
var page = require('webpage').create();
page.settings.loadImages = false;
page.onConsoleMessage = function(msg) { console.log(msg); };
var pageUrl = 'http://www.bloggersentral.com/2010/08/how-put-add-adsense-on-blogger.html';
var num = 0;
var max = 2;
page.onLoadFinished = function() {
var text = page.evaluate(function() {
@firedfox
firedfox / gist:2037945
Created March 14, 2012 17:09
find google ads with phantomjs
var page = require('webpage').create();
page.settings.loadImages = false;
page.onConsoleMessage = function(msg) { console.log(msg); };
page.onLoadFinished = function() {
page.evaluate(function() {
var getFrames = function(doc) {
var frames = doc.querySelectorAll('iframe');
for (var i = frames.length - 1; i >= 0; i--) {
var fdoc = frames[i].contentWindow.document;
@firedfox
firedfox / test.html
Created April 12, 2012 06:50
phantomjs googlegroup discussion - Click onto an image
<html>
<body>
<table width="251" cellspacing="0" cellpadding="0" align="left" valign="bottom">
<tr>
<td>
<div id="show_cart">
<a href="next.htm">
<img src="cart.png" border="0" width="251" height="71">
</a>
@firedfox
firedfox / onDOMContentLoaded.js
Created April 24, 2012 02:12
phantomjs onDOMContentLoaded
const PHANTOM_FUNCTION_PREFIX = '/* PHANTOM_FUNCTION */';
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
if (msg.indexOf(PHANTOM_FUNCTION_PREFIX) === 0) {
eval('(' + msg + ')()');
} else {
console.log(msg);
}
@firedfox
firedfox / links.js
Created May 9, 2012 01:42
document.links in phantomjs