Announcement

Collapse
No announcement yet.

Making xkcd your opening page on your browser

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Making xkcd your opening page on your browser

    Save the following code as xkcd.html and point your browser to it as its home page.
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>xkcd via JSONP</title>
     
    <script type="text/javascript">
    var details = {};
    function dataloaded(o){details = o;}
    
    function pageloaded()
    { 
       with(document.getElementById("image"))
       {
          src = details.img;
          alt = details.title;
          title = details.alt;
       }
    
       document.getElementById("title").innerHTML = details.title;     
       document.getElementById("num").innerHTML += details.num;
       document.getElementById("date").innerHTML = details.day + "/" + details.month + "/" + details.year;
       document.getElementById("mouseover").innerHTML = details.alt;
       
            //Format Transcript
       var str = details.transcript;
            //Fix < and >
       str = str.replace(/</g, '&lt;')
       str = str.replace(/>/g, '&gt;')
            //Fix newlines
       str = str.replace(/\n/g, '<br>\n');
            //Add extra breaks before bracketed sections
       str = str.replace(/[[]{2}/g, '<br>\n[[');   
            //Remove alt text from transcript
       str = str.replace(/{.*}/g, '');
       document.getElementById("transcript").innerHTML = str;
       
       var url = "http://xkcd.com/" + num;
       
        with(document.getElementById("original"))
        {
           href = url;
           innerHTML = url;
        }   
    }
    
    var num = prompt("Comic number");
    
    var head= document.getElementsByTagName('head')[0];
    var script= document.createElement('script');
    script.type= 'text/javascript';
    script.src = "http://dynamic.xkcd.com/api-0/jsonp/comic/"+num+"?callback=dataloaded";
    head.appendChild(script);
    </script>
    </head>
    <body onload="pageloaded()">
    <h2 id="title"></h2>
    <h3 id="num">#</h3>
    
    <div id="date"></div><br>
    
    <img id="image" style="border: 1px solid #888; padding: 10px;">
    <!-- img id="image" style="border: 5px solid #000;"-->
    
    <h3>Mouseover</h3>
    <div id="mouseover"></div>
    <!-- hr style="border: 1px solid #00F;" -->
    <h3>Transcript</h3>
    <div id="transcript" style="width: 50%;" ></div>
    <br>
    <a id=original></a>
    <br><hr><br>
    </body>
    </html>
    When it activates it will ask for a comic number. If you want the most recent then just click OK.

    I got it from here while looking for a widget that did the same thing. Thinking about it, I decided that having xkcd as my opening home page was a better idea than having a cron task which may not run when I first turn on my laptop or a widget burning clock cycles in some loop, waiting to fire.
    Last edited by GreyGeek; Apr 15, 2018, 02:11 PM.
    "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
    – John F. Kennedy, February 26, 1962.

    #2
    Kubuntu 24.11 64bit under Kernel 6.11.0, Hp Pavilion, 6MB ram. Stay away from all things Google...

    Comment

    Working...
    X