Skip to content

Instantly share code, notes, and snippets.

@yesmeck
Created November 20, 2012 06:01
Show Gist options
  • Save yesmeck/4116308 to your computer and use it in GitHub Desktop.
Save yesmeck/4116308 to your computer and use it in GitHub Desktop.
阿尔法城的出租车~
// ==UserScript==
// @name AlphaTaxi
// @namespace http://yesmeck.com
// @description 阿尔法城出租车
// @include http://alphatown.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @version 1.0
// ==/UserScript==
$(function() {
var Taxi = function() {
this.place = 'road';
this.guidArrow = $('span.guide-arrow');
};
Taxi.prototype.run = function() {
var _this = this;
if (this.isGuideStart()) {
console.log('Running...');
var intervalId = setInterval(function() {
var moveButton;
if (_this.amIIn('road') && !_this.isGuideStart()) {
clearInterval(intervalId);
console.log('到达目的地');
return;
}
console.log(_this.iAmIn());
if (_this.amIIn('subway')) {
_this.click($('.mark-target strong'));
_this.iAmIn('room');
return;
}
if (_this.amIIn('room')) {
moveButton = _this.guidArrow.prevAll('a.toward');
_this.click(moveButton);
_this.iAmIn('road');
return;
}
moveButton = _this.guidArrow.prev();
if (moveButton.hasClass('shop-overlap')) {
_this.iAmIn('subway');
} else {
_this.iAmIn('road');
}
_this.click(moveButton);
}, 5000);
} else {
console.log('导航未开始');
}
};
Taxi.prototype.isGuideStart = function() {
return (this.guidArrow.length > 0 && this.guidArrow.css('display') !== 'none');
};
Taxi.prototype.iAmIn = function(palce) {
this.place = palce || this.place;
return this.place;
};
Taxi.prototype.amIIn = function(place) {
return this.place === place;
};
Taxi.prototype.click = function(jQueryDOM) {
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent('click', true, true);
return jQueryDOM[0].dispatchEvent(clickEvent);
};
$('body').append('<a id="take-taxi" href="javascript:;">打的</a>');
$('#take-taxi').css({
position: 'absolute',
left: '50%',
top: '10px',
'z-index': 1000
});
$('body').delegate('#take-taxi', 'click', function() {
var taxi = new Taxi;
taxi.run();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment