Posts Tagged ‘css’

Fullscreen, blank homepage

Saturday, September 3rd, 2011

I usually use a blank or empty page as my homepage. This makes for quick browser start up and minimal waiting when making new tabs/windows.

I find myself often opening a new browser window resizing it to fill the whole screen and then browsing. This goes against how apple wants me to use my mac. The little green plus sign button on the top left corner of the screen is supposed to be smart enough to always maximize the current window only as much as it needs to/should. But what is the correct maximization of a blank page? Apparently its a full height window with some arbitrary width. Why not make it a full height and full width window. To do this for my browsers (Safari, Firefox, Chrom(e|ium)) I made a little html file that displays a blank, fullscreen-able page. Save the following in a file on your computer called fullscreen-homepage.html:


<html>
  <head>
    <title>Fullscreen Homepage</title>
  </head>
  <body style="min-width:10000px;overflow:hidden">
  </body>
</html>

Open the file with your browser and copy the address at the top (starting with file:// to your browser’s preferences as your homepage for new tabs and windows. Here’s what to change in the Safari preferences:
safari preferences local fullscreen homepage

Ignore the onion paywall

Saturday, August 13th, 2011

Was watching the onion video channel today and to my surprise they have a paywall like nytimes. To be honest at first I thought it was a joke. But in the end it’s just as easy to get around as the nytimes one.

Just a little client side javascript gets ride of the paywall screen:


document.getElementById('gregbox-overlay').style.display = "none";
document.getElementById('gregbox-wrap').style.display = "none";

And here’s an applescript which calls that javascript on the frontmost safari window.


tell application "Safari"
	try
		set doc to front document
		do JavaScript "document.getElementById('gregbox-overlay').style.display = 'none';" in doc
		do JavaScript "document.getElementById('gregbox-wrap').style.display = 'none';" in doc
	on error errText number errNum
	end try
end tell

Horizontal and vertical centering using html, css without knowing container size

Friday, June 17th, 2011

This is an especially elusive problem when designing a simple webpage in html. There are many non solutions on the web that require knowing the size of the container element. The solution I found was straight forward and did not require knowing anything about the container. It does not require javascript (though the original code uses javascript to show off the fact that it stays centered).

A page with horizontal and vertical centering

Original source

Ignore nytimes paywall with simple client-side javascript, or applescript

Thursday, April 21st, 2011

Today was my first experience with the New York Times paywall. It manifested as an html overlay on top of the article I wanted to read. The article seemed to have fully loaded which made me think that if I could just get rid of the overlay I’d be able to read it.

This turned out to be the exactly case. I just zapped the div containing the overly (properly labeled id='overlay' and restored the overflow of the main page (to get scrolling back).

ignore nytimes paywall

This is easily accomplished with three lines of client side javascript:


document.getElementById('overlay').parentNode.innerHTML = '';
document.body.style['overflow-x'] = 'auto';
document.body.style['overflow-y'] = 'auto';

There are many ways of issuing your own javascript on pages opened in your browser, whatever that might be.

For me on a mac with safari, wrapping the above into a little applescript is easiest. I save this in a file called Ignore-nytimes-paywall.scpt:


tell application "Safari"
	try
		set doc to front document
		do JavaScript "document.getElementById('overlay').parentNode.innerHTML = '';" in doc
		do JavaScript "document.body.style['overflow-x'] = 'auto';" in doc
		do JavaScript "document.body.style['overflow-y'] = 'auto';" in doc
	on error errText number errNum
	end try
end tell

It seems that coming up with your own hack for knocking down the nytimes paywall is the trend these days. We’re all blowing our technological Joshua trumpets ;-) .

Update: I’m now more convinced that nytimes is just using this paywall as an experiment. Ignoring the paywall is even easier than I thought:

Readers need only remove “?gwh=numbers” from the URL. They can also clear their browser caches, or switch browsers as soon as they see the subscription prompt. All three of these simple fixes will let them continue reading.

Source

Update:
Seems the paywall organization has changed a little bit and now the client side javascript should be:


document.getElementById('regiwallBackground').style.display = 'none';
document.getElementById('regiwallOverlay').style.display = 'none';
document.body.parentElement.style.overflow = 'scroll';

Adding html doctype ruins fullscreen canvas

Friday, March 11th, 2011

Recently I experienced a very minor but annoying problem. I made a fullscreen canvas like this one:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    <style type="text/css">
    html,body
    {
      height: 100%;
      width: 100%;
      margin: 0;
      background-color: #F54;
    }
    canvas#full
    {
      height: 100%;
      width: 100%;
      margin: 0;
      background-color: #4F5;
    }
    </style>
    <title>Properly fullscreen canvas, but no doctype</title>
  </head>
  <body>
    <canvas id="full">
    </canvas>
  </body>
</html>

which you can see for yourself.

Then all I did was add to the top:

<!DOCTYPE HTML>

and you can see on the right a scroll bar now appears and there are 3 pixels below my canvas showing the background. This is a minor but very annoying problem.

I fixed this by adjusting the CSS style of the fullscreen canvas to:

    canvas#full
    {
      display: block;
      height: 100%;
      width: 100%;
      margin: 0;
      background-color: #4F5;
    } 

The result validates and looks right.

Short survey of email obfuscation techniques

Tuesday, October 26th, 2010

Although, spam detection is better each day, many people (and in the computer science computer it seems like most or all) people are paranoid about displaying their email addresses in plain text on the web.

The HTML standard has gone out of its way to make displaying email addresses easy to both the programmer and the user.


<a href="mailto:joeschmo@cs.abc.edu">
joeschmo@cs.abc.edu
</a>

Displays as
joeschmo@cs.abc.edu
which allows the user to click on the address and the browser will open the user’s default mail client.

But paranoia has driven many to obfuscate their addresses against would be spammers by first removing the “mailto” link and then manipulating the text in some way:


joeschmo [AT] cs [DOT] abc [DOT] edu
firstnamelastname@cs.abc.edu
email obfuscation image technique
joeschmo[strudel]cs.abc.edu

The last one is my favorite (courtesy Yotam Gingold, who told my strudel is how Israelis refer to the @ sign).

I remember a student asking one of my professors who used one of these techniques, “Isn’t it pretty easy for a spam bot to parse these common replacements?” And he replied, not without wisdom, “A person would obfuscates their email address is probably also a person who doesn’t respond to spam, so why would the spammers bother.”

This certainly holds some reason, but then the burden is placed on the user who wants to email you. Typically we’ve put our email addresses on the web because we want other people to email us. So it should be as easy as possible to do so: as the language provides.

Recently a friend and I experimented with a few different techniques for achieving user-end ease of use, but also satiating our paranoia about spam attacks. Admittedly posting these techniques could be seen as escalating the cold war with spammers. But they’re certainly not unknown and probably not worth spammers while (see the logic above).

Just in time replacement with javascript


<a href="mailto:joeschmocs.abc.edu" onmouseover="this.href=this.href.replace('ocs','o@cs');return true;" >
joeschmo@cs.abc.edu
</a>

Displays as

joeschmo@cs.abc.edu

The email address is still display in plain text in the source so we’re not done yet, but the href mailto link is only correct after the user has moused over the link. Thus, when the user clicks on the link the correct email address shows up in the mail client. Doing this onmouseover is expecially nice so that correct email address shows up in the browser’s status bar and that the user gets the correct email address if he right-clicks and chooses “Copy email address” or the like.

The one place where this fails is if the user is navigating via keyboard (alt-tabbing) through the forms and links. Then focusing on the email link and “clicking” it with space-bar will not present the user with the correct link. You can fix this by adding the same functionality to the onfocus action.


<a href="mailto:joeschmocs.abc.edu" onfocus="this.href=this.href.replace('ocs','o@cs');return true;" onmouseover="this.href=this.href.replace('ocs','o@cs');return true;">
joeschmo@cs.abc.edu
</a>

Displays as

joeschmo@cs.abc.edu

Note: You should be careful that the replacement you use only works the first time so that if the link is hovered over or focused more than once the correct email address remains.

Address completion via CSS

My friend, Tino Weinkauf, thought of a very clever way to be able to display his proper email address in a browser and be sure that spammers would not see it. The idea hinges on the assumption that spam bots won’t waste time evaluating CSS code because usually CSS doesn’t change the content of the page.

In your HTML head tag:


<style type="text/css">
.eobf:after {content:"o\0040cs";}
</style>

then in your link:


<a href="mailto:joeschmocs.abc.edu" 
onfocus="this.href=this.href.replace('ocs','o@cs');return true;" onmouseover="this.href=this.href.replace('ocs','o@cs');return true;" 
>
<span class="eobf">joeschm</span>.abc.edu
</a>

Displays as

joeschm.abc.edu

The only thing I don’t like about this technique is that (at least on Safari) selecting the displayed address and copying it doesn’t seem to grab the part placed by the css. So if the user is copying the text, he’ll have to replace the characters on his own anyway.

Note: Michael Overton has an amusing way of preventing spam from reaching his inbox. HIs method certainly seems to be the most extreme burden on himself and the user, it hard to imagine that he’s not missing many non-spam emails.

Update:
In the end I’m skipping the CSS trick and sticking to javascript and simple character replacement:


<a  href="mailto:jacobsoncs.nyu.edu" 
  onmouseover="this.href=this.href.replace('ncs','n@cs');return true;"
  onfocus="this.href=this.href.replace('ncs','n@cs');return true;"
  >
  jacobson<span style="font-size:1.25em">&#x263A;</span>cs.nyu.edu
</a>

Which displays as:
jacobsoncs.nyu.edu

Admittedly the user has to replace the ☺ with an at sign, but it’s a pleasant, easily-noticed substitution.

Note: Another site on the issue has an in-browser spam parser you can use to check out your obfuscation technique.

Update:A friend pointed out that rather than waiting for the user to hover over the link you could just have the switch occur when the div is loaded. The logic being that most spam bots that don’t evaluate onmouseover probably don’t evaluate onload either. The only problem I see is that the <a> object doesn’t allow the onload event, so you’d have to give your email link an id and do it on your html’s or body’s onload event.

LaTeX in browser

Friday, February 5th, 2010

I did a search for “Latex in browser” without any immediate finds for what I thought would come up. Namely, an in-bowser app that has a text area, where I can type in a full latex document program, and a rendering window/frame where I can on the fly see my typeset pdf.
I’ve quickly coded up a simple demo of the idea. Here’s a screen shot of the app running on Safari:
latex in browser screenshot
The code is rather simple it just calls pdflatex on a server using AJAX. Then it dumps the pdf into an <OBJECT> tag. I spent more (too much) tinkering with the layout than actually making the latex and in-browser part come together. Here’s the simple php code that the LaTeX program gets POSTed to asynchronously:


<?php
  $myFile = str_replace("\.","-",tempnam(".","latex-in-browser-"));
  $fh = fopen($myFile, 'w') or die("can't open file");
  fwrite($fh, $_POST['latex']);
  fclose($fh);
  #$error=`if pdflatex -interaction nonstopmode $myFile &> /dev/null ; echo "0";else echo "1";fi`;
  $output=`pdflatex -interaction nonstopmode -halt-on-error $myFile `;
  if(strstr($output,"Fatal error"))
    $error = "1";
  else
    $error = "0";
  $log=`cat $myFile.log`;
  `rm $myFile`;
  `rm $myFile.log`;
  `rm $myFile.aux`;
  print trim($myFile).".pdf ".trim($error)." ".$log;
?>

Try LaTeX in browser now!

Convert image file to html page using div blocks

Monday, October 12th, 2009

This is the revival of an old program I was requested to make. Given any .png, .jpg, .jpeg, .bmp, image file, DivMachine converts that image into a collection of colored divs. So given this image (8 KB):

div machine input image

DivMachine produces (164 KB):


<style type="text/css">
div.dm {
  position:absolute;
}
</style>
<div style="position: relative;padding:20px;background-color:#c3e0f0;width:100px;height:126px;">
<div class='dm' style="top:0px; left:58px; background-color:#2F2F31; width:1px; height:1px"></div>
<div class='dm' style="top:0px; left:56px; background-color:#2D2720; width:2px; height:2px"></div>
<div class='dm' style="top:1px; left:58px; background-color:#251C13; width:1px; height:1px"></div>
<div class='dm' style="top:0px; left:59px; background-color:#26292D; width:1px; height:2px"></div>
<div class='dm' style="top:2px; left:57px; background-color:#513E21; width:3px; height:1px"></div>
<div class='dm' style="top:0px; left:60px; background-color:#25292C; width:1px; height:3px"></div>
...

which displayed as html looks like this:

The source is included in the zip file.

New (version of) close-up font comparer: versus

Friday, July 31st, 2009

versus font comparerToday, I coded up Versus, a close-up font comparer. The original version (somewhat inspired by the documentary Helvetica) was written in straight html and css (with a little php to generate new phrases). The were a lot of problems with that version… Most importantly it only seemed to run on my browsers on my machine (some of the renderings — especially on IE browsers — were quite comical). The new version is all java and runs beautifully in a browser applet on any machine and any browser with java enabled. It also lets you choose fonts to compare from a list of fonts you have access to on your machine. I also included a “full screen page”.

Tell me what you think and leave ideas for improvements.

Note: For anyone interested here’s the source code.

Help google images find your images

Tuesday, July 21st, 2009

I’ve been using a javascript turned perl turned ruby gallery script to make hosting images as easy and sleek as possible. But I’ve found that google (and of course if there are other search engines then those, too) has not indexed the images shown in my gallery. All other images on my site that are included on a static html page eventually show up. I don’t want to give up my gallery script (hopefully I’ll post that code soon). So, I drew up some quick bash code to find all the images on my site and throw them into a static page, which I then hide links to all over my site.
Here’s the bash code that can be run periodically (it’s not necessary to do it all the time since search engines aren’t caching the site all the time…but obviously more often is better). Here’s my script, named make_all.sh:


#!/bin/bash
# Generate an html page with links to all images in this dir
# Author: Alec Jacobson (alecjacobson[strudel]gmail.com)
#
# To write links to all images in dir/ to index.html run:
# $ ./make_all.sh dir/ index.html 
#
echo "<html><body>" > $2
links=`find $1 -iregex ".*.jpe?g$" \
  | sed "s/\(^.*$\)/<a href=\"\1\" ><img alt=\'\[ideal query]\' src=\"\1\"\/><\/a>/"`
echo $links >> $2
echo "</body></html>" >> $2

Change ".*.jpe?g$" as you see fit (I’m only worrying about jpegs). Since I want my images to come when my name is searched I put my name in the alt field for [ideal query]. I also add a little text to the page to be sure it isn’t ignored for lack of content.

Next, since I don’t intend for human users to see this page but I still want the crawlers to find it I hide links all over my site using:


<a href="[path to your static index of images.html]" style="text-decoration:none;">&nbsp;</a>

You could even get really carried away hiding it and move it off the visible pages using position:absolute; top:-1;.

Here’s my static page of all my images, and between these parenthesis is an example of a hidden link ( ).

I will report back with whether this has worked successfully for me.