Question

So I found a script that allows me to grab the current day's Dilbert comic. It's in JavaScript:

<script>
    var now = new Date();
    var day = now.getDate();
    var month = now.getMonth() + 1;
    var year = now.getFullYear()%100;
    var dayofweek = (now.getDay() == 0) ? 's' : 'd';
    if (day < 10) day = '0' + day;
    if (month < 10) month = '0' + month;
    document.write('<img src="http://thedilbertstore.com/images/periodic_content/dilbert/dt' + year + '' + month + '' + day + dayofweek + 'hct.jpg">');
</script>

I've barely touched the language, but I am fluent in ActionScript 3.0, and I can roughly tell what's going on. It appears that the end result is that it adds the image to the page in an <img> tag.

Personally, I would like to be able to have this file itself kind of "be" the image file. That is, I want to link to this file using forum [img] tags and get today's Dilbert comic. As I said I've not very knowledgeable about JavaScript and I'm not sure how to do this, or if it's even possible.

Can anybody give me some advice as to how I go about doing something like this? Preferably I would like to be able to upload this to Dropbox where I can link to it directly, as I don't currently have my own website.

Was it helpful?

Solution

like doorknob said there is no way to do that...but by visiting the site once a day you could check inside the function if you image exists.

if not post the image to your dropbox.

now... problems... you need prolly a userid and password to post something to your dropbox account.

  1. you cannot store passwords inside your javascript because everyone can read that.

  2. to execute the code (update the image) you need to visit the page.

  3. you need some sort of serverwhere you wanna store this html/javascript.


anyway here is a working function function that updates the image if you can host this code somewhere.

function update(){
 var now=new Date(),
 day=now.getDate(),
 month=now.getMonth()+1,
 year=now.getFullYear()%100,
 dayofweek=now.getDay()==0?'s':'d',
 url='http://thedilbertstore.com/images/periodic_content/dilbert/dt',
 img=document.getElementsByTagName('img')[0];
 day=day<10?'0'+day:day;
 month=month<10?'0'+month:month;
 img.src=url+year+month+day+dayofweek+'hct.jpg';
}
window.onload=update;

you could search for a free php hosting site wich has also cron jobs wich execute periodically.

how this works:

find a php host that has cron jobs..

create a php script that is similar to this javascript update function.

inside the function check if this image(same named) exists on you dropbox.

then you need to create a credentials script to login to dropbox and you can send the image if it does not exist.

now in the host's admin panel you need to link the php scrip to the periodical cron job.

and it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top