Skip to content

Instantly share code, notes, and snippets.

@skttl
Created March 10, 2017 14:45
Show Gist options
  • Select an option

  • Save skttl/ef0f7fc8e634bba5dc32c632870ef6cb to your computer and use it in GitHub Desktop.

Select an option

Save skttl/ef0f7fc8e634bba5dc32c632870ef6cb to your computer and use it in GitHub Desktop.
lydeffekter på metalligaen.dk
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://metalligaen.dk/*
// @grant none
// ==/UserScript==
(function ($, window, undefined) {
/// <param name="$" type="jQuery" />
"use strict";
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
}
var signalR = $.signalR;
function makeProxyCallback(hub, callback) {
return function () {
// Call the client hub method
callback.apply(hub, $.makeArray(arguments));
};
}
function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;
for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];
if (!(hub.hubName)) {
// Not a client hub
continue;
}
if (shouldSubscribe) {
// We want to subscribe to the hub events
subscriptionMethod = hub.on;
} else {
// We want to unsubscribe from the hub events
subscriptionMethod = hub.off;
}
// Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];
if (!$.isFunction(memberValue)) {
// Not a client hub function
continue;
}
subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue));
}
}
}
}
}
$.hubConnection.prototype.createHubProxies = function () {
var proxies = {};
this.starting(function () {
// Register the hub proxies as subscribed
// (instance, shouldSubscribe)
registerHubProxies(proxies, true);
this._registerSubscribedHubs();
}).disconnected(function () {
// Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs.
// (instance, shouldSubscribe)
registerHubProxies(proxies, false);
});
proxies['sportsAdminLiveHub2'] = this.createHubProxy('sportsAdminLiveHub');
proxies['sportsAdminLiveHub2'].client = { };
proxies['sportsAdminLiveHub2'].server = {
getSchedule: function (tournamentID) {
return proxies['sportsAdminLiveHub2'].invoke.apply(proxies['sportsAdminLiveHub2'], $.merge(["GetSchedule"], $.makeArray(arguments)));
},
getStats: function (tournamentID) {
return proxies['sportsAdminLiveHub2'].invoke.apply(proxies['sportsAdminLiveHub2'], $.merge(["GetStats"], $.makeArray(arguments)));
},
register: function (tournamentID, getNews, getLiveBlog) {
return proxies['sportsAdminLiveHub2'].invoke.apply(proxies['sportsAdminLiveHub2'], $.merge(["Register"], $.makeArray(arguments)));
},
registerSchedule: function (tournamentID) {
return proxies['sportsAdminLiveHub2'].invoke.apply(proxies['sportsAdminLiveHub2'], $.merge(["RegisterSchedule"], $.makeArray(arguments)));
},
registerStats: function (tournamentID) {
return proxies['sportsAdminLiveHub2'].invoke.apply(proxies['sportsAdminLiveHub2'], $.merge(["RegisterStats"], $.makeArray(arguments)));
},
threadPoolCallback: function (threadContext) {
return proxies['sportsAdminLiveHub2'].invoke.apply(proxies['sportsAdminLiveHub2'], $.merge(["ThreadPoolCallback"], $.makeArray(arguments)));
}
};
return proxies;
};
signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false });
$.extend(signalR, signalR.hub.createHubProxies());
}(window.jQuery, window));
$(function () {
$("body").append("<style type='text/css'>.pulse { border:10px solid #f00;animation: pulse 1s infinite;box-sizing:border-box; } @keyframes pulse { 0%, 100% { border-width:10px; } 50% { border-width:0px } }</style>");
console.log("Userscript enabled");
var alreadyCalled = [];
// Reference the auto-generated proxy for the hub.
var hub = $.connection.sportsAdminLiveHub2;
//var div = document.getElementById("WeeklyStats");
//div.style.display = 'none';
// Create functions that the hub can call back.
hub.client.initializeLiveControls = function (view) {
};
hub.client.refreshControl = function (view) {
if (alreadyCalled.indexOf(view.gameComment + view.gameID) < 0) {
var add = false;
if (view.gameComment.indexOf("periode er slut") > -1) {
var audio = new Audio('https://dl.dropboxusercontent.com/u/57005195/sounds/periode-slut.mp3');
audio.play();
console.log("CustomRefresh: perioden er slut", view);
document.title = view.gameComment;
add = true;
}
if (view.gameComment.indexOf("periode er igang") > -1) {
var audio = new Audio('https://dl.dropboxusercontent.com/u/57005195/sounds/periode-start.mp3');
audio.play();
console.log("CustomRefresh: perioden er i gang", view);
document.title = view.gameComment;
add = true;
}
if (view.gameComment.indexOf("idømmes en udvisning") > -1) {
var audio = new Audio('https://dl.dropboxusercontent.com/u/57005195/sounds/udvisning.mp3');
audio.play();
console.log("CustomRefresh: udvisning", view);
document.title = view.gameComment;
add = true;
}
if (view.gameComment.indexOf("skudt pucken i mål") > -1) {
var audio = new Audio('https://dl.dropboxusercontent.com/u/57005195/sounds/maal.mp3');
audio.play();
console.log("CustomRefresh: mål", view);
document.title = view.gameComment;
add = true;
}
if (add) { alreadyCalled.push(view.gameComment + view.gameID);
console.log("add to alreadyCalled", view.gameComment, view);
pulseLogo(view.gameID);
}
}
else {
console.log("this is alreadyCalled");
}
};
hub.client.tick = function (view) {
//Refreshes the game
};
function pulseLogo(id) {
console.log("pulseLogo " + id + " " +".game[id=" + id + "] #gameLogo", $(".game[id=" + id + "] #gameLogo"));
$(".game[id=" + id + "] > img:first-child").addClass("pulse");
setTimeout(function() {$(".game[id=" + id + "] > img:first-child").removeClass("pulse"); }, 15000);
}
// Start the connection.
//$.connection.hub.start()
$.connection.hub.start().done(function () {
console.log('Connected to SignalR hub');
hub.server.register(1254, true, true); //parameters tournamentid, show rss feed, show live blog
console.log('Registered to SignalR hub');
}).fail(function (err) {
console.log('Failed to connect to SignalR hub ' + err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment