Request: Get Remote Text

baldylox

New Member
I am an extra-life charity team member and we have been trying for several years to be able to track our donations similar to other resources available. it seems this year the xsplit users have finally gotten this to work, but the function does not appear to be available in obs, yet.

it seem you can add custom scripting to a remote url in the xsplit text editor. here is the code the folks are using to snag the donation data. Can this be quickly added to existing resources or could someone make a new one? the Extra-Life OBS user community would LOVE IT!!!!!

Code:
/*
    The script will check the local file for any changes in text every [UPDATEINTERVAL] milliseconds
    which will automatically update the text within the stage.
    Setting it to 0 or lower disables auto-update.
*/


/**
* @name URLTOLOAD
* @label Participant ID
* @type text
* @description The numbers at the end of your extra-life donation page
*/
var URLTOLOAD = "91438";


/**
* @name DISPLAYLASTDONOR
* @label Display Previous Donor
* @type boolean
* @description Optional. Will attempt to display the previous donor and what they donated.
*/
var DISPLAYLASTDONOR = true;


/*Do not modify anything below*/
// ^---this person is not the boss of you.
var oldResponse;
var thanksText;
var thanksCount = 1;
var exclamatories = ["WOW!", "AWESOME!", "SWEET!", "OMG!", "THANKS!", "COOL!", "ROCK ON!"];
var DELIMETER_1 = "actualAmount=";
var DELIMETER_2 = "&goal";
var DELIMETER_3 = "<strong class=\"block\">";
var DELIMETER_4 = "</strong>";
var UPDATEINTERVAL = 30;

function GetTextFromRemote() {
    $.ajax({
        url: "http://www.extra-life.org/index.cfm?fuseaction=donorDrive.participantDonations&participantID=" + URLTOLOAD,
        type: "GET",
        dataType: "text",
        complete: function () {
            if (UPDATEINTERVAL > 0)
                smlTitleTimeouts = setTimeout(function () { GetTextFromRemote(); }, UPDATEINTERVAL * 1000);
        },
        success: function (response) {
            var responseCleaned = response.replace(/(\r\n|\n|\r)/gm, " ");
            var totalDollars = "";
            var lastDonor = "";
            var currentResponse = "";


            if (DELIMETER_1 != "" && DELIMETER_2 != "") {
                totalDollars = "$" + getDesiredString(responseCleaned, DELIMETER_1, DELIMETER_2);
            }


            if (DISPLAYLASTDONOR && DELIMETER_3 != "" && DELIMETER_4 != "") {
                lastDonor = getDesiredString(responseCleaned, DELIMETER_3, DELIMETER_4) + "!";
            }


            //now that data has been parsed from the response, let's format the text to display based on the user's settings.
            if (!DISPLAYLASTDONOR) {
                currentResponse = totalDollars;
            }


            if (DISPLAYLASTDONOR) {
                currentResponse = totalDollars + " raised so far! " + exclamatories[thanksCount] + " " + lastDonor;
            }


            if (oldResponse != currentResponse) {
                thanksCount++;
                if (thanksCount == exclamatories.length) {
                    thanksCount = 0;
                }
                SetText(currentResponse.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), "Remote URL: " + URLTOLOAD);
            }
            oldResponse = currentResponse;
        }
    });
}

//this function takes the entire page, the string that leads up to the string you want, and the string that comes after the string you want.
function getDesiredString(text, startString, endString) {
    var responseCleanedLength = text.length;
    var indexOfDelim1 = text.indexOf(startString) > -1 ? (text.indexOf(startString) + startString.length) : 0;
    var substringResponseCleaned = text.substring(indexOfDelim1);
    var substringResponseCleanedLength = substringResponseCleaned.length;

    var initialIndexOfDelim2 = substringResponseCleaned.indexOf(endString) > -1 ? substringResponseCleaned.indexOf(endString) : responseCleanedLength;
    var indexOfDelim2 = responseCleanedLength;
    if (initialIndexOfDelim2 != responseCleanedLength) {
        indexOfDelim2 = initialIndexOfDelim2 + (responseCleanedLength - substringResponseCleanedLength);
    }

    if (indexOfDelim2 <= indexOfDelim1)
        indexOfDelim2 = text.length - 1;
    return text.substring(indexOfDelim1, indexOfDelim2).trim().replace("&nbsp;", " ");
}

GetTextFromRemote();
 

Sapiens

Forum Moderator
There are several tools in the resources section that might meet your needs - TeeBoard, SubAlert, Free Stream Notifications, etc.
 

baldylox

New Member
TYVM for a response and I am aware of those tools already (use teeboard). They do not work with what I have posted and am asking for some help getting to work. i am not a programmer, only posting what I found capable w/ xsplit that is not in obs so the obs users can hopefully get on the same page.

most of those notification tools seem to run off some sort of output to a text file on my end that the tool reads from. xsplit is allowing the coding above directy into the text window vs reading a file.
 

Jack0r

The Helping Squad
Wouldnt it be possible to use the browser plugin for this? It looks like a script that could be put into a webpage.
Streamcontrol uses a similar system that checks a local file for changes.
 

baldylox

New Member
That is the first thing I thought of too, but i dont know how take it to the next step. It would be great if we could add custom scripts. here is how xsplit is handling it. I think CLR could grab the website w/no issues, but there is no way that I can see to handle the scripting.

2hzxUK3.png
GhrOhbj.png
 

baldylox

New Member
someone on the extra-life forum looked into this a big and we found we can update our data using a chrome extension (super auto refresh) to auto refresh a page and using window capture. we tried using clrbrowser, but it would never update in the stream once the website updated.
 
Top