Skip to content

Instantly share code, notes, and snippets.

@aggieben
Created July 11, 2012 23:41
Show Gist options
  • Select an option

  • Save aggieben/3094482 to your computer and use it in GitHub Desktop.

Select an option

Save aggieben/3094482 to your computer and use it in GitHub Desktop.
Co-Op Spotter
// ==UserScript==
// @name Co-Op Spotter
// @namespace https://gist.github.com/aggieben
// @downloadURL https://gist.github.com/raw/3094482/coopspotter.user.js
// @updateURL https://gist.github.com/raw/3094482/coopspotter.user.js
// @description Script to audibly alert the user to changes in the main content div of Harvest Co-op.
// @match http://*coopapp.com/*
// @match https://*coopapp.com/*
// @resource alertSound http://goo.gl/IDn7c
// @resource alertSoundAll http://goo.gl/sQgvK
// @resource cobotSound http://goo.gl/TvEJG
// @require http://code.jquery.com/jquery.min.js
// @version 1.2.0
// ==/UserScript==
// Settings for users to modify.
var setting_freq = 1; // this value will depend on how frequently the site will update
var setting_vol = 1.0; // this value may need to change, depending on what alert sound is used
//////////////////////////////////////////////////////////////////////////////////////
var snd = null;
var filters = {};
GM_log("Loaded Co-Op Spotter " + GM_info.script.version);
if (html5_audio()) {
var res = "data:audio/mp3;base64,";
snd = new Audio(res + GM_getResourceURL("alertSound"));
snd.volume = setting_vol;
snd.load();
filters["cobot"] = new Audio(res + GM_getResourceURL("cobotSound"));
filters["all"] = new Audio(res + GM_getResourceURL("alertSoundAll"));
var filter_count = 0;
for (f in filters) {
filters[f].load();
filter_count++;
}
GM_log("loaded " + filter_count + " filters.");
}
else {
GM_log("something's wrong; you can't play HTML5 audio");
}
var g_latestNode = $(".entry").first().attr('id');
setInterval(function() {
var latestNode = $(".entry").first().attr('id');
if (latestNode != g_latestNode)
{
GM_log("new entry!");
if (!processFilters(latestNode)) {
snd.play();
}
g_latestNode = latestNode;
}
}, setting_freq*1000);
function processFilters(nodeId) {
GM_log("processing filters for " + nodeId);
if($("#" + nodeId).hasClass("user_0")) {
GM_log("matched Cobot user on " + nodeId);
filters["cobot"].play();
return true;
}
var nodeText = $("#display_text_" + nodeId).text();
if (nodeText.toLowerCase().match("@all")) {
GM_log("matched \'all\' filter on " + nodeId);
filters["all"].play();
return true;
}
}
function html5_audio(){
var a = document.createElement('audio');
return !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment