Skip to content

Instantly share code, notes, and snippets.

@jm42
Created December 10, 2015 00:58
Show Gist options
  • Save jm42/adb176bdd80a4be1c541 to your computer and use it in GitHub Desktop.
Save jm42/adb176bdd80a4be1c541 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name OK Plus
// @namespace guide42
// @description Enchant OK Cupid
// @include http://www.okcupid.com/*
// @include https://www.okcupid.com/*
// @version 0.1
// ==/UserScript==
;(function($, window, undefined) {
var OkPlus = {
toolbar: null,
routes: {},
initToolbar: function() {
this.toolbar = $('<ul></ul>')
.css({
'float': 'right',
'margin-right': '25px'
})
;
$('#ratings_heading').append(this.toolbar);
},
addButton: function(label, callback) {
if (this.toolbar === null) {
this.initToolbar();
}
var button = $('<a href="#">' + label + '</a>')
.click(function() { callback.call(this); return false; })
;
this.toolbar.append(button);
},
dispatch: function() {
for (var route in this.routes) {
var regexp = new RegExp('^https?://www\.okcupid\.com' + route, 'i');
if (window.location.href.match(regexp)) {
this.routes[route].call(this);
}
}
}
};
OkPlus.routes['/quickmatch'] = function() {
this.addButton('Vote', function() {
var button = $(this);
if (button.html() === 'Vote') {
var interval = function() {
var data = button.data();
data.count++;
window.document.getElementById("stars").getElementsByTagName("li")[3].getElementsByTagName('a')[0].click();
button.html('Stop Vote (' + data.count + ')');
button.data(data);
};
button.html('Stop Vote');
button.data({'interval': setInterval(interval, 1000), 'count': 0});
} else {
clearInterval(button.data()['interval']);
button.html('Vote');
button.data({'interval': null, 'count': 0});
}
});
};
$(function() {
OkPlus.dispatch();
});
})(jQuery, this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment