Apps Home
|
Create an App
countdown
Author:
philwhelp
Description
Source Code
Launch App
Current Users
Created by:
Philwhelp
//working test 2 b repeat goal test.. // topic settings tags = cb.settings.tags; RoomSubject = cb.settings.RoomSubject; //goal settings apG = cb.settings.apG; // amount per goal tpG= cb.settings.tpG; // time per goal ntpG = tpG*60; TTG = 0; // total tipped goal needed = apG; //timer settings var timer = tpG*60; var t; // tippers settings tipper =[]; var TT = 0; // total tips var HTU = "----"; // high tipper Username var HTA = 0; // high tip[er Amount var LTU = "----"; // last tipper Username var LTA = 0; // last tipper Amount var KTU = "----"; // King tipper Username var KTA = 0; // King tipper Amount cb.settings.tags && (tags = cb.settings.tags.trim() ? cb.settings.tags : ''), (!tags || tags < 0) && (tags += ""); var e = mySplit(tags); tags = ""; for (var t = 0; t < e.length; t++) tags += "#" == e[t].substring(0, 1) ? e[t] : "#" + e[t]; cb.settings_choices = [ {name: "RoomSubject", label: "Room Topic", type: 'str', minLength: 1, maxLength: 255}, {name:'tpG', label: "Time add per reached goal(in minutes)", type:'int', minValue:1, maxValue:999, defaultValue:30}, {name:'apG', label: "Goal Amount", type:'int', minValue:1, maxValue:999, defaultValue:300}, {name: 'tags',label: "tags(#)", type: 'str', minLength: 1, maxLength: 255, defaultValue:"asian"}, ]; function disTime(Y) { var hours = Math.floor(Y / 3600); time = Y - hours * 3600; var minutes = Math.floor(time / 60); var seconds = time - minutes * 60; var finalTime = str_pad_left(hours,'0',2)+':'+str_pad_left(minutes,'0',2)+':'+str_pad_left(seconds,'0',2); return finalTime; } //-------- function str_pad_left(string,pad,length) { return (new Array(length+1).join(pad)+string).slice(-length); } //--------- function mySplit(e) { return e.trim().replace(/\s+/g, " ").split(" ") } function smGoal(X) { X ? X : 0; TTG += X; lst =''; lst2 =''; if (TTG >= apG) { TTG-=apG; addTime(tpG); return smGoal(0);} needed = apG - TTG; runTopic(); cb.drawPanel(); //end } function runTopic() { cb.changeRoomSubject(RoomSubject +" - add "+ tpG +" minutes to clock at goal ["+needed+" tokens needed] "+tags); } // on tip settings cb.onTip(function(tip) { if(tipper[tip.from_user] == null) {tipper[tip.from_user] = tip.amount;} else {tipper[tip.from_user] += tip.amount;} if (tipper[tip.from_user] > KTA) { if (tipper[tip.from_user] > 100) { KTA = tipper[tip.from_user]; KTU = tip.from_user;} } TT += tip.amount; nLTA = tip.amount; LTA = tip.amount; LTU = tip.from_user; if (tip.amount > HTA) { HTA = tip.amount; HTU = tip.from_user; } smGoal(tip.amount); }); function startGT() { if (timer > 0) {timer--;} cb.drawPanel(); if (timer > 0) {t = cb.setTimeout(startGT, 1000);} } function stopGT() { cb.cancelTimeout(t); } function addTime(X) { timer += (X* 60); cb.drawPanel(); } function removeTime(X) { timer -= (X* 60); cb.drawPanel(); } function setTime(X) { timer = (X* 60); cb.drawPanel(); } function remove(LA) { last_TA_R = Math.floor((LA+TTG)/apG); if ((last_TA_R > 0) && (LA > apG)) {TTG = ((last_TA_R)*apG)+TTG-LA; timer = timer- ((last_TA_R)*ntpG) } else if (TTG-LA < 0) {TTG = TTG-LA+apG; timer = timer- ntpG}//good else {TTG = TTG-LA} //good if (timer <= 0) {timer = 0;} needed = apG - TTG; runTopic(); cb.drawPanel(); } cb.onMessage(function (msg) { str = msg.m; if ((str.includes("!")) && (msg.user == cb.room_slug)) {msg['X-Spam'] = true;} if ((str.includes("!start")) && (msg.user == cb.room_slug)){ startGT(); } else if ((str.includes("!stop")) && (msg.user == cb.room_slug)){ stopGT(); } else if ((str.includes("!removeLast")) && (msg.user == cb.room_slug)){ remove(LTA); } else if ((str.includes("!removeTokens")) && (msg.user == cb.room_slug)){ nub =str.match(/[1-9][0-9]{0,3}/g)? str.match(/[1-9][0-9]{0,3}/g)[0] : 0; if (nub > 0) {remove(nub);} } else if ((str.includes("!addTime")) && (msg.user == cb.room_slug)){ nub =str.match(/[1-9][0-9]{0,3}/g)? str.match(/[1-9][0-9]{0,3}/g)[0] : 0; if (nub > 0) {addTime(nub);} } else if ((str.includes("!removeTime")) && (msg.user == cb.room_slug)){ nub =str.match(/[1-9][0-9]{0,3}/g)? str.match(/[1-9][0-9]{0,3}/g)[0] : 0; if (nub > 0) {removeTime(nub);} } else if ((str.includes("!setTime")) && (msg.user == cb.room_slug)){ nub =str.match(/[1-9][0-9]{0,3}/g)? str.match(/[1-9][0-9]{0,3}/g)[0] : 0; if (nub > 0) {setTime(nub);} } return msg; }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Received/Goal(total): ', 'row1_value': TTG + "/" + apG +"("+TT+")", 'row2_label': 'time left: ', 'row2_value':disTime(timer), 'row3_label': 'Best Tip Received: ', 'row3_value': HTU + " ("+ HTA +")" }; }); smGoal(0);
© Copyright Chaturbate 2011- 2024. All Rights Reserved.