[Next entry: "Interview"]
Home » Archives » February 2009 » Removing the Cruft from the Nokia N810 - 4
[Previous entry: "Removing the Cruft from the Nokia N810 - 3"]
Home » Archives » February 2009 » Removing the Cruft from the Nokia N810 - 4
[Previous entry: "Removing the Cruft from the Nokia N810 - 3"]
Removing the Cruft from the Nokia N810 - 4
12 February 2009 @ 04:19 PM MST
12 February 2009 @ 04:19 PM MST
Current Music: None
Current Mood: Getting tired
Current Mood: Getting tired
6. AD-BLOCKING
Ads suck. We all know it already. Even more so for our mobile devices: 1. We have limited screen space and don't want it wasted on ads. 2. If connected via a cell-phone we have limited bandwidth and don't want it wasted on ads. Luckily there are ways to solve the problem of ads.
In Firefox we have the lovely addition of the Ad-Block Plus extension which works beautifully. Incredibly, this plug-in is also available for the MicroB browser built-in to the n810. Unfortunately, it is (apparently, from various accounts on the internet), rather processor intensive and chews up the battery. Since our goal with this nice little mobile device is convenience, sucking down the battery to perform ad-blocking is not ideal. Therefore, we'd like to look for alternative options for blocking ads.
There is a nice little page on the Maemo Wiki describing the 3 main options for blocking ads: Maemo Wiki: Ad-Blocking. I'm going to try out the "preferred" method from the Wiki: Hosts and CSS.
This technique keeps a list of webservers known to serve up ads, and automatically blocks your browser from connecting to them. It then uses a custom CSS file to rebuild your webpages as you view them so that you don't see where the ads would have been.
Unfortunately, at the time of this writing the website that provides the new hosts information is down. I grabbed a Google Cache of the file from the beginning of February. I recommend (and the author requests) you go directly to the site: http://everythingisnt.com/hosts.html, however if it's still not working, here's my local copy: Local copy of hosts.txt.
Also go and grab the new CSS file from floppymoose.com. Here's my local copy in case the site is down: Local copy of userContent.css.
Got the files? Good, let's do this. I copied the files to the /root directory as the root user.
First we'll append the hosts file to our existing hosts file:
Next we'll setup the userContent.css file, this one we can just be the regular user:
Restart your browser (or just open it, if it's not open) and you should be all set to browse with fewer ads than before. And go ahead and (as root) delete the two files from the /root directory, they don't need to be there anymore:
6.1 THE DRAWBACKS
So, there are some issues. This method is not as thorough as Adblock and it has the possibility of interferring with other applications if they try to point at one of the servers being blocked for ads. Also listed as a "Con" on the Wiki is that it is time consuming to temporarily disable. Well... that part could be easily fixed with a little script to toggle the changes on and off. "But there is no such script," you say? BEHOLD!
6.2 HOSTS/CSS TOGGLE SCRIPT
My own personal invention here. I would normally write things like this in Python, but Python is not installed by default on the n810, however Perl is. So I muddled through enough Perl to make this work. Anyone that actually writes Perl will probably laugh at my script, and feel free to do so, the main point is that it works.
Here's the script: hosts_css_toggler.txt. It's a .txt file because otherwise the webserver won't allow you to access it. So you'll want to rename it once you've downloaded it.
Once downloaded rename it and make it executable:
How it works: It's really quite simple. First, it assumes you've appended the hosts file with the new entry (as described above) and that you've placed the userContent.css file in the correct location (also described above). The first time you run it it will place a comment at the top of the hosts file to describe if it is currently toggled on or off.
When you run the script it looks for the comments indicating the start of the blocked hosts, it then just processes each line thereafter and if it starts with 127.0.0.1 (meaning it's blocking a site) it places a comment "#hct#" in front of it. When toggling it back on it just finds the lines starting with #hct# and removes the #hct#. So it won't interfere with any other changes you've made to the hosts file, so long as they occur above the comment indicating the start of the blocked sites.
As for the userContent.css, it just moves the file to userContent.css.bkp when disabling the blocking and back to userContent.css when enabling the blocking.
Each time you toggle you'll need to restart the web browser for the changes to take effect.
On first run you'll see something like this:
And if you run it again:
And now you're all set for quick and fast ad-blocking!
[This Entry]
Ads suck. We all know it already. Even more so for our mobile devices: 1. We have limited screen space and don't want it wasted on ads. 2. If connected via a cell-phone we have limited bandwidth and don't want it wasted on ads. Luckily there are ways to solve the problem of ads.
In Firefox we have the lovely addition of the Ad-Block Plus extension which works beautifully. Incredibly, this plug-in is also available for the MicroB browser built-in to the n810. Unfortunately, it is (apparently, from various accounts on the internet), rather processor intensive and chews up the battery. Since our goal with this nice little mobile device is convenience, sucking down the battery to perform ad-blocking is not ideal. Therefore, we'd like to look for alternative options for blocking ads.
There is a nice little page on the Maemo Wiki describing the 3 main options for blocking ads: Maemo Wiki: Ad-Blocking. I'm going to try out the "preferred" method from the Wiki: Hosts and CSS.
This technique keeps a list of webservers known to serve up ads, and automatically blocks your browser from connecting to them. It then uses a custom CSS file to rebuild your webpages as you view them so that you don't see where the ads would have been.
Unfortunately, at the time of this writing the website that provides the new hosts information is down. I grabbed a Google Cache of the file from the beginning of February. I recommend (and the author requests) you go directly to the site: http://everythingisnt.com/hosts.html, however if it's still not working, here's my local copy: Local copy of hosts.txt.
Also go and grab the new CSS file from floppymoose.com. Here's my local copy in case the site is down: Local copy of userContent.css.
Got the files? Good, let's do this. I copied the files to the /root directory as the root user.
First we'll append the hosts file to our existing hosts file:
~ $ root
BusyBox v1.6.1 (2008-09-18 09:43:17 EEST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
Nokia-N810-43-7:~# cat hosts.txt >> /etc/hostsNext we'll setup the userContent.css file, this one we can just be the regular user:
Nokia-N810-43-7:~# exit
~ $ mkdir /home/user/.mozilla/microb/chrome
~ $ cp /root/userContent.css /home/user/.mozilla/microb/chrome/userContent.cssRestart your browser (or just open it, if it's not open) and you should be all set to browse with fewer ads than before. And go ahead and (as root) delete the two files from the /root directory, they don't need to be there anymore:
~ $ root
BusyBox v1.6.1 (2008-09-18 09:43:17 EEST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
Nokia-N810-43-7:~# rm hosts.txt userContent.css6.1 THE DRAWBACKS
So, there are some issues. This method is not as thorough as Adblock and it has the possibility of interferring with other applications if they try to point at one of the servers being blocked for ads. Also listed as a "Con" on the Wiki is that it is time consuming to temporarily disable. Well... that part could be easily fixed with a little script to toggle the changes on and off. "But there is no such script," you say? BEHOLD!
6.2 HOSTS/CSS TOGGLE SCRIPT
My own personal invention here. I would normally write things like this in Python, but Python is not installed by default on the n810, however Perl is. So I muddled through enough Perl to make this work. Anyone that actually writes Perl will probably laugh at my script, and feel free to do so, the main point is that it works.
Here's the script: hosts_css_toggler.txt. It's a .txt file because otherwise the webserver won't allow you to access it. So you'll want to rename it once you've downloaded it.
Once downloaded rename it and make it executable:
~ $ mv hosts_css_toggler.txt hosts_css_toggler.pl
~ $ chmod +x hosts_css_toggler.plHow it works: It's really quite simple. First, it assumes you've appended the hosts file with the new entry (as described above) and that you've placed the userContent.css file in the correct location (also described above). The first time you run it it will place a comment at the top of the hosts file to describe if it is currently toggled on or off.
When you run the script it looks for the comments indicating the start of the blocked hosts, it then just processes each line thereafter and if it starts with 127.0.0.1 (meaning it's blocking a site) it places a comment "#hct#" in front of it. When toggling it back on it just finds the lines starting with #hct# and removes the #hct#. So it won't interfere with any other changes you've made to the hosts file, so long as they occur above the comment indicating the start of the blocked sites.
As for the userContent.css, it just moves the file to userContent.css.bkp when disabling the blocking and back to userContent.css when enabling the blocking.
Each time you toggle you'll need to restart the web browser for the changes to take effect.
On first run you'll see something like this:
~ $ rootsh ./hosts_css_toggler.pl
Toggling Hosts/CSS Based Ad-blocking...
Installing Toggler
Toggling OFF: /etc/hosts... DONE!
Toggling OFF: /home/user/.mozilla/microb/chrome/userContent.css... DONE!
And if you run it again:
~ $ rootsh ./hosts_css_toggler.pl
Toggling Hosts/CSS based Ad-blocking...
Toggling ON: /etc/hosts... DONE!
Toggling ON: /home/user/.mozilla/microb/chrome/userContent.css... DONE!
And now you're all set for quick and fast ad-blocking!
[This Entry]
Replies: 1 Comment
On Monday, February 16th @ 09:18, RavMan said:
Awesome and straightforward, thanks for sharing!