Skip to content

Commit

Permalink
Update Fallen_London_Contacts_Favours.user.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurvin authored Oct 3, 2018
1 parent cc3641e commit 0d790ff
Showing 1 changed file with 64 additions and 63 deletions.
127 changes: 64 additions & 63 deletions Fallen_London_Contacts_Favours.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// @namespace Fallen London Contacts Favours
// @author Laurvin
// @description Shows the Favours at the top of the page; you will need to refresh manually by clicking the bell icon.
// @version 1.0
// @version 2.0
// @icon http://i.imgur.com/XYzKXzK.png
// @downloadURL https://github.com/Laurvin/Fallen-London-Contacts-Favours/raw/master/Fallen_London_Contacts_Favours.user.js
// @include http://fallenlondon.storynexus.com/Gap/Load*
// @include https://fallenlondon.storynexus.com/Gap/Load*
// @include http://fallenlondon.storynexus.com/Me/StatusesForCategory?category=Contacts
// @include https://fallenlondon.com/*
// @include https://www.fallenlondon.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @grant none
// @grant GM_xmlhttpRequest
// @run-at document-idle
// ==/UserScript==

Expand Down Expand Up @@ -58,76 +57,78 @@ function addGlobalStyle(css)
head.appendChild(style);
}

function ReloadIFrame()
{
document.getElementById('gmIframe').contentWindow.location.reload();
}

function addHTMLElements() // Adds a div for Contact icons and reload button.
{
$('#nav1').after('<div id="FLCF"> Loading Contact Favours... </div>');
$('.site-title').append('<div id="FLCF"> Loading Contact Favours... </div>');
$("body").append('<div id="ContactPage1point0" style="display:none !important;"></div>');
}

function LoadFavours()
function GetFavors()
{
$('span.tt > strong').each(function()
{
if($(this).text().indexOf("Favours:") >= 0)
{
Faction = $(this).text().substring(9, $(this).text().length-2);

FavAmount = $(this).text().slice(-1);

Favours[Faction] = FavAmount;
}
});
}

function receiveMessage (event)
{
if (event.origin != "http://fallenlondon.storynexus.com") return;

$("#FLCF").html (event.data);

$('#FLCFreload').click(function()
{
$('#FLCF').text("Loading Contact Favours...");
ReloadIFrame();
});
$("#ContactPage1point0").html('');

GM_xmlhttpRequest({
method: 'GET',
url: 'http://fallenlondon.storynexus.com/Me/StatusesForCategory?category=Contacts',
timeout: 2000,
onload: function (response)
{
$("#ContactPage1point0").html(response.responseText);

$('#ContactPage1point0 span.tt > strong').each(function()
{
if($(this).text().indexOf("Favours:") >= 0)
{
Faction = $(this).text().substring(9, $(this).text().length-2);

FavAmount = $(this).text().slice(-1);

Favours[Faction] = FavAmount;
}
});

var CreatedHTML = "";

$.each(Favours, function(faction, amount)
{
CreatedHTML += '<div class="FLCFdivs"><img height="26" width="20" border="0" src="https://images.fallenlondon.com/icons/' + FactionIcon[faction] + '.png" /> ' + amount + '</div>';
});

CreatedHTML += '<div class="FLCFdivs">&nbsp;</div><div class="FLCFdivs" id="FLCFreload" style="cursor:pointer"><img height="26" width="20" border="0" title="Reload" src="http://images.fallenlondon.com/icons/bellsmall.png" /></div>';

$("#FLCF").html(CreatedHTML);

$('#FLCFreload').click(function(event)
{
event.preventDefault();
$('#FLCF').text("Loading Contact Favours...");
GetFavors();
});
},
onerror: function (response)
{
alert('Failed loading.');
},
ontimeout: function (response)
{
alert('Timed out loading.');
}
});
}

$(document).ready(function ()
{
'use strict';

// console.log("Starting!");
// console.log("Starting!");

addGlobalStyle('#FLCF { float: left; margin-left: 25px; font-size: 12px; line-height: 10px; width: 72%; text-transform: none; }');
addGlobalStyle('.site-title { background: none !important; cursor: auto !important; color: #bdb29e !important;}');
addGlobalStyle('#FLCF { margin-top: 7px; font-size: 14px; }');
addGlobalStyle('.FLCFdivs { float: left; width: 7%; }');


if (location.href == 'http://fallenlondon.storynexus.com/Me/StatusesForCategory?category=Contacts')
{
LoadFavours();

var CreatedHTML = "";

$.each(Favours, function(faction, amount)
{
CreatedHTML += '<div class="FLCFdivs"><img height="26" width="20" border="0" src="http://images.fallenlondon.com/icons/' + FactionIcon[faction] + '.png" /> ' + amount + '</div>';
});

CreatedHTML += '<div class="FLCFdivs">&nbsp;</div><div class="FLCFdivs" id="FLCFreload" style="cursor:pointer"><img height="26" width="20" border="0" title="Reload" src="http://images.fallenlondon.com/icons/bellsmall.png" /></div>';

window.top.postMessage (CreatedHTML, "*");
}
else
{
addHTMLElements();

window.addEventListener ("message", receiveMessage, false);

$("body").append('<iframe style="display:none !important;" src="http://fallenlondon.storynexus.com/Me/StatusesForCategory?category=Contacts" id="gmIframe"></iframe>');

}
// console.log("Ending!");
setTimeout(addHTMLElements, 2 * 1000); // 2 seconds
setTimeout(GetFavors, 2 * 1000); // 2 seconds

// console.log("Ending!");
});

0 comments on commit 0d790ff

Please sign in to comment.