Something NEW: Hey I did some programming for... - No Smoking Day

No Smoking Day

5,216 members32,485 posts

Something NEW

nsd_user663_2507 profile image
11 Replies

Hey I did some programming for fun...

Copy and Paste thie following code to notepad and save it as HTML code. For instance save it as quit.html to your desktop then open it with your browser. Don't forget to change your inputs listed on the top...

Oh yea and ignore the PHP code header... It should really say JavaScript but was unavailable.

If you guys have idea to write a program that will help us quitters please let me know your ideas and we can try to paint it to reality...:)

[PHP]

<script language="JavaScript">

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

//*** Put your input here *****\\

//-----------------------------------------------------------------------//

PricePerPack = 4.25;

//-----------------------------------------------------------------------//

TargetDate = "Thursday, November 22, 2007 12:00 AM";

//-----------------------------------------------------------------------//

SmokedFor = "20 Cigarettes per day for approx. 22 years";

//-----------------------------------------------------------------------//

BackColor = "yellow";

//-----------------------------------------------------------------------//

ForeColor = "navy";

//-----------------------------------------------------------------------//

CountActive = true;

//-----------------------------------------------------------------------//

CountStepper = 1;

//-----------------------------------------------------------------------//

LeadingZero = true;

//-----------------------------------------------------------------------//

DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds";

//-----------------------------------------------------------------------//

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

function calcage(secs, num1, num2) {

s = ((Math.floor(secs/num1))%num2).toString();

if (LeadingZero && s.length < 2)

s = "0" + s;

return "<b>" + s + "</b>";

}

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

function CountBack(secs) {

if (secs < 0) {

document.getElementById("cntdwn").innerHTML = FinishMessage;

return;

}

DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));

DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));

DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));

DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

document.getElementById("cntdwn").innerHTML = DisplayStr;

if (CountActive)

setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);

}

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

function putspan(backcolor, forecolor) {

var dquit = new Date(TargetDate);

var dtoday = new Date();

var diff = new Date(dtoday-dquit);

var s = Math.floor(diff.valueOf()/1000);

var money = Math.floor( (s/86400)%100000 );

var saved = PricePerPack * money;

document.write("<br />" + "Quit: " + TargetDate);

document.write("<br />" + "Smoked: " + SmokedFor);

document.write("<br />" + "Price per pack: " + formatCurrency(PricePerPack));

document.write("<br />" + "Method: Cold Turkey");

document.write("<br />" + "<br />" + "Quit: ");

document.write("<span id='cntdwn' style='background-color:" + backcolor +

"; color:" + forecolor + "'></span>&nbsp;days ago...");

document.write("<br />Saved: ");

document.write("<strong><span id='saved' style='background-color:" + BackColor +

"; color:" + ForeColor + "'>" + formatCurrency(saved) + "</span></strong>");

}

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

function formatCurrency(num)

{

num = num.toString().replace(/\$|\,/g,'');

if(isNaN(num))

num = "0";

sign = (num == (num = Math.abs(num)));

num = Math.floor(num*100+0.50000000001);

cents = num%100;

num = Math.floor(num/100).toString();

if(cents<10)

cents = "0" + cents;

for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)

num = num.substring(0,num.length-(4*i+3))+','+

num.substring(num.length-(4*i+3));

return (((sign)?'':'-') + '$' + num + '.' + cents);

}

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

if (typeof(BackColor)=="undefined")

BackColor = "white";

if (typeof(ForeColor)=="undefined")

ForeColor= "black";

if (typeof(TargetDate)=="undefined")

TargetDate = "12/31/2020 5:00 AM";

if (typeof(DisplayFormat)=="undefined")

DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";

if (typeof(CountActive)=="undefined")

CountActive = true;

if (typeof(FinishMessage)=="undefined")

FinishMessage = "";

if (typeof(CountStepper)!="number")

CountStepper = -1;

if (typeof(LeadingZero)=="undefined")

LeadingZero = true;

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

CountStepper = Math.ceil(CountStepper);

if (CountStepper == 0)

CountActive = false;

var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;

putspan(BackColor, ForeColor);

var dthen = new Date(TargetDate);

var dnow = new Date();

if(CountStepper>0)

ddiff = new Date(dnow-dthen);

else

ddiff = new Date(dthen-dnow);

gsecs = Math.floor(ddiff.valueOf()/1000);

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

CountBack(gsecs);

////////////////////////////////////////////////////////////////////////

</script>

[/PHP]

Happy programming! :)

Written by
nsd_user663_2507 profile image
nsd_user663_2507
To view profiles and participate in discussions please or .
11 Replies
nsd_user663_2291 profile image
nsd_user663_2291

Whooshhhhhhhhhhhhhhhhhhh:rolleyes:

nsd_user663_1744 profile image
nsd_user663_1744

I think most people on here know I am pc challenged. Hell I have enough trouble

trying to work out how to use my mobile phone!:o:o:o

nsd_user663_2421 profile image
nsd_user663_2421

LOL LOL me too Kazza. that was just jargon to me Dhoh !

nsd_user663_2485 profile image
nsd_user663_2485

Programming

Well, I'm a programmer (C#, VB.Net, VB6, T-SQL, Flash, JavaScript, etc., etc...), but I don't have the time

:-(

Your post got me thinking....I googled yahoo widgets and found a number of desktop widgets that counted cigs not smoked & cetera. Seems as though the most popular one is a German widget (Nichtraucher--sounds German to me), with 17,237 downloads; there are 3 or 4 English widgets, too.

To look at them go here: widgets.yahoo.com/search/?q...

Rob W

nsd_user663_1744 profile image
nsd_user663_1744

Well, I'm a programmer (C#, VB.Net, VB6, T-SQL, Flash, JavaScript, etc., etc...), but I don't have the time

:-(

Your post got me thinking....I googled yahoo widgets and found a number of desktop widgets that counted cigs not smoked & cetera. Seems as though the most popular one is a German widget (Nichtraucher--sounds German to me), with 17,237 downloads; there are 3 or 4 English widgets, too.

To look at them go here: widgets.yahoo.com/search/?q...

Rob W

I thought widgets were the things inside cans of John Smiths?:confused:

nsd_user663_2421 profile image
nsd_user663_2421

i use the stayfagfree quitmeter. got it from someone on this forum. its on my tool bar now and how i access the forum.

nsd_user663_2507 profile image
nsd_user663_2507

I played, I played, I played

can you make like a little dude who sits on your desk top like the cat out of word, I kinda lurves that cat he shows me his baked bean feet and everything :D

What?? LOL Can you send me a link to something describing this?

nsd_user663_2507 profile image
nsd_user663_2507

Well, I'm a programmer (C#, VB.Net, VB6, T-SQL, Flash, JavaScript, etc., etc...), but I don't have the time

:-(

Your post got me thinking....I googled yahoo widgets and found a number of desktop widgets that counted cigs not smoked & cetera. Seems as though the most popular one is a German widget (Nichtraucher--sounds German to me), with 17,237 downloads; there are 3 or 4 English widgets, too.

To look at them go here: widgets.yahoo.com/search/?q...

Rob W

Hey a Widget for the Desktop now that sounds like a very nice idea hey!

What will you guys like to see in a little gadget on your desktop?

For smoker:

A way to create a data graber every time you smoked then based on your consistencies in your smoking patterns suggest a time to cut a habit.

To grab data the user can manually enter it or use their cell phone with internet access or a place with internet to log their smoking times...

For quiters:

Time since stop date

money saved

time saved

health diagnosis options

Any more ideas?

:D Killing time hey :D

nsd_user663_2142 profile image
nsd_user663_2142

I played - that was fun! Thank you :D

nsd_user663_2142 profile image
nsd_user663_2142

Yama can you code in Delphi?

nsd_user663_2507 profile image
nsd_user663_2507

Yama can you code in Delphi?

Nope I am C++, C#, Java, and everything that puts together a web, mobile, or windows application...

You may also like...

DAY something and something

Something terrible happened

Day 4 and in something like a routine!!!

day 4. The story now is wake up, old patch off, new patch on. Get the hell out off bed. Make a...

I think i may be onto something!

Every failed attempt teaches you something!

time you fail it teaches you about yourself and your weaknesses, my 1st reaction was that if every...