Apps Home
|
Create an App
jhcbstest
Author:
savntest1
Description
Source Code
Launch App
Current Users
Created by:
Savntest1
// startof CBSv2 module - not for re-compilation (function(a,h){function f(a){this.message=a}f.prototype=Error();f.prototype.name="InvalidCharacterError";a.btoa||(a.btoa=function(a){a=String(a);for(var g,b,m=0,d=h,q="";a.charAt(m|0)||(d="=",m%1);q+=d.charAt(63&g>>8-m%1*8)){b=a.charCodeAt(m+=.75);if(255<b)throw new f('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');g=g<<8|b}return q});a.atob||(a.atob=function(a){a=String(a).replace(/=+$/,"");if(1==a.length%4)throw new f('"atob" failed: The string to be decoded is not correctly encoded.'); for(var g=0,b,m,d=0,q="";m=a.charAt(d++);~m&&(b=g%4?64*b+m:m,g++%4)?q+=String.fromCharCode(255&b>>(-2*g&6)):0)m=h.indexOf(m);return q})})("undefined"===typeof exports?this:exports,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="); (function(a){var h=cb.onMessage,f=null,p=null,g,b="#"+(cb.settings.hasOwnProperty("slot")?cb.settings.slot:"")+"CBSv2",m=/^\/#[0-3]CBSv2\//;cb.onMessage=function(d){if("function"!==typeof d)throw new TypeError(d+" is not a function");h(function(h){var e=h.m.replace(/\s*/g,"").split("/"),k,r;3<e.length&&""===e[0]&&e[1]===b?(f&&p&&h.user===cb.room_slug&&(k=e[2],4===e.length?(e[3]="?",h.m=e.join("/")):6===e.length?((g||{}).hasOwnProperty(k)||(r=f(),g={},g[k]=a.btoa(a.unescape(a.encodeURIComponent(r))), r||cb.log("onSave returned no data.")),g.hasOwnProperty(k)&&(r=parseInt(e[3],10),k=g[k].slice(r,r+512),e[4]=k,e[5]=k.length,h.m=e.join("/"))):7===e.length&&("0"===e[3]&&(g={},g[k]=""),g.hasOwnProperty(k)&&(e[3]=g[k].length,e[6]=e[4].length,h.m=e.join("/"),e[4]?g[k]+=e[4]:(r=a.decodeURIComponent(a.escape(a.atob(g[k]))),p(r),cb.sendNotice("Previously Saved Data Restored.",cb.room_slug))))),h["X-Spam"]=!0):m.test(h.m)&&(h["X-Spam"]=!0);return d(h)});return d};cb.onRestore=function(a){if("function"!== typeof a)throw new TypeError(a+" is not a function");return p=a};cb.onSave=function(a){if("function"!==typeof a)throw new TypeError(a+" is not a function");return f=a};cb.onMessage(function(a){return a})})("undefined"===typeof exports?this:exports); // endof CBSv2 module - not for re-compilation // new handlers cb.onSave(function () { // form the variables into an object, using their names as the object keys var data = { total_tipped: total_tipped, high_tip_username: high_tip_username, high_tip_amount: high_tip_amount, last_tip_username: last_tip_username, last_tip_amount: last_tip_amount, subject_is_set_with_0: subject_is_set_with_0 }; // return that object in the form of a string return JSON.stringify(data); }); cb.onRestore(function (data) { // parse the restored data string into an object var restored = JSON.parse(data); // reinstate the saved variables Object.keys(restored).forEach(function (variable) { if (this.hasOwnProperty(variable)) { this[variable] = restored[variable] } }); }); // vars var total_tipped = 0; var high_tip_username = null; var high_tip_amount = 0; var last_tip_username = null; var last_tip_amount = 0; var subject_is_set_with_0 = false; cb.settings_choices = [ {name: 'tokens', type: 'int', minValue: 1, default: 100}, {name: 'goal_description', type: 'str', minLength: 1, maxLength: 255} ]; // handlers cb.onTip(function(tip) { total_tipped += tip['amount'] if (total_tipped > cb.settings.tokens) { total_tipped = cb.settings.tokens; } update_subject(); last_tip_amount = tip['amount'] last_tip_username = tip['from_user'] if (tip['amount'] > high_tip_amount) { high_tip_amount = tip['amount'] high_tip_username = tip['from_user'] } cb.drawPanel(); }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Tip Received / Goal :', 'row1_value': '' + total_tipped + ' / ' + cb.settings.tokens, 'row2_label': 'Highest Tip:', 'row2_value': format_username(high_tip_username) + ' (' + high_tip_amount + ')', 'row3_label': 'Latest Tip Received:', 'row3_value': format_username(last_tip_username) + ' (' + last_tip_amount + ')' }; }); // helper functions function update_subject() { if (tips_remaining() == 0) { if (subject_is_set_with_0) { return; } subject_is_set_with_0 = true; } else { subject_is_set_with_0 = false; } var new_subject = cb.settings.goal_description + " [" + tips_remaining() + " tokens remaining]"; cb.log("Changing subject to: " + new_subject); cb.changeRoomSubject(new_subject); } function tips_remaining() { var r = cb.settings.tokens - total_tipped; if (r < 0) { return 0; } else { return r; } } function format_username(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } function init() { update_subject(); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.