Skip to content

Instantly share code, notes, and snippets.

@gialloporpora
Last active October 6, 2015 06:07
Show Gist options
  • Save gialloporpora/2948523 to your computer and use it in GitHub Desktop.
Save gialloporpora/2948523 to your computer and use it in GitHub Desktop.
With this code (PHP) you can create an URL that automatically redirect to the APOD (Astronomy Image Of the Day)
/*
With the following code you can create a static url that automatically redirect to the apod (Astronomy Image of the day
* You can use it like wallpaper in your Firefox's about:home page. Look at next file
Download Simple HTML parser from here:
http://simplehtmldom.sourceforge.net/
*/
<?php
function randomImage(){
$best_images = Array(
"http://apod.nasa.gov/apod/image/1210/geyseraurora_howell_2163.jpg",
"http://apod.nasa.gov/apod/image/1210/meteorviolet_salomonsen_1200.jpg",
"http://apod.nasa.gov/apod/image/1010/hartley2pacman_fernandez.jpg",
"http://apod.nasa.gov/apod/image/1007/ISS023-E-58455lrg.jpg"
);
return $best_images[rand(0, count($best_images)-1)];
}
function isNotFound($url){
$response = get_headers($url, 1);
$response = explode(" ", $response[0]);
$response = $response[1];
if ($response=="404") return true;
else return false;
}
include('simple_html_dom.php');
$url="http://apod.nasa.gov";
$html=file_get_html($url);
$img = $html->find('img', 0)->parent->href;
if ($img=='') $img = randomImage();
else{
$img="http://apod.nasa.gov/apod/".$img;
if (isNotFound($img)) $img = randomImage();
}
header("location: ".$img);
?>
@gialloporpora
Copy link
Author

Example

Put this code in your userContent.css or use Stylish estension

@-moz-document url("about:home") {
    body{
        background-image: url(http://www.gialloporpora.netsons.org/apod.png) !important;
        background-repeat:no-repeat;
        background-attachment:fixed;
        background-position:center;
    }
    }/* The following code change the color of buttons in launcher, the image is often dark, with light text color buttons are more readable
    * if you want you could also select a background for buttons
    */
    .launchButton{
        color: #eef !important;
    }

}

@gialloporpora
Copy link
Author

I have put the style on userstyles.org.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment