Skip to content

Instantly share code, notes, and snippets.

@jackkoppa
Created March 14, 2016 03:31
Show Gist options
  • Save jackkoppa/0d01cfd6a036d4d7511b to your computer and use it in GitHub Desktop.
Save jackkoppa/0d01cfd6a036d4d7511b to your computer and use it in GitHub Desktop.
Open EventSpot Events by Keyword
// ==UserScript==
// @name Open EventSpot Events by Keyword
// @namespace http://jackkoppa.com
// @version 0.1.1
// @description From the main page of EventSpot, open all events that match a user-given keyword (in this case, Professor's last name)
// @author jackkoppa
// @match https://ui.constantcontact.com/rnavmap/evp/manage
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
// Anonymous "self-invoking" function
(function() {
// Load the script
var script = document.createElement("SCRIPT");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(script);
})();
function noticeOfScript() {
var checkReady = function(callback) {
if (window.jQuery) {
callback(jQuery);
}
else {
window.setTimeout(function() { checkReady(callback); }, 100);
}
};
// Start polling...
checkReady(function($) {
$("div.pagetitlearea").append("<h1 style=\"color:#B82727\"><em>Peaks and Professors script is successfully running on this page. Press \"ALT + O\" to select a Trip, & open all 3 events for that Trip</em></h1>");
});
};
function openEventTabs() {
// Poll for jQuery to come into existance
var checkReady = function(callback) {
if (window.jQuery) {
callback(jQuery);
}
else {
window.setTimeout(function() { checkReady(callback); }, 100);
}
};
// Start polling...
checkReady(function($) {
function nth_occurrence (string, char, nth) {
var first_index = string.indexOf(char);
var length_up_to_first_index = first_index + 1;
if (nth == 1) {
return first_index;
} else {
var string_after_first_occurrence = string.slice(length_up_to_first_index);
var next_occurrence = nth_occurrence(string_after_first_occurrence, char, nth - 1);
if (next_occurrence === -1) {
return -1;
} else {
return length_up_to_first_index + next_occurrence;
}
}
}
var professor = prompt("Enter Professor Last Name");
var tripTypes = ["STANDARD", "DRIVER", "WAITLIST"];
var i;
for (i = 0; i <= 2; i++) {
if (professor) {
var tripType = tripTypes[i];
var element = $( "a:contains(" + professor + "):contains(" + tripType + ")");
console.log(element);
var clickFunction = element.attr("onclick");
var third_apos_position = nth_occurrence(clickFunction,'\'',3);
var fourth_apos_position = nth_occurrence(clickFunction,'\'',4);
var eventID = clickFunction.substring(third_apos_position+1,fourth_apos_position);
console.log("Opening " + tripType + ", with eventID: " + eventID);
window.open("https://ui.constantcontact.com/rnavmap/evp/hub/details?id=" + eventID, "_blank");
}
}
});
}
document.onkeyup=function(e){
var e = e || window.event; // for IE to cover IEs window event-object
if(e.altKey && e.which == 79) {
openEventTabs();
return false;
}
}
noticeOfScript();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment