JavaScripted e-mail Links in WordPress Pages

You may want to include an e-mail link in your WordPress Blog’s “About” page or elsewhere, but no doubt you don’t want this harvested and you’ve found you can’t simply add the JavaScript to the post or page as it gets nuked.

So how about a workaround?

Firstly, you need to create an external Javascript file with this code (amended for your own needs, obviously):


function obfuscate() {
var ppclink = "Click here to e-mail us";
var ppcname = "nospamthanks";
var ppchost = "yourdomainnamegoeshere";
document.write("<a href=" + "mail" + "to:" + ppcname + "@" + ppchost + ">" + ppclink + "")
}

NB: the “@” sign is represented in the code as “& # 64 ;” with no spaces.

Save it as something like emailobfuscator.js and upload it to your server.

Then in the post or the page you want to include it in, add the following code:

<script type="text/javascript"
src="/scripts/emailobfuscator.js" mce_src="/scripts/emailobfuscator.js">
</script>
<script type="text/javascript">
<!--
obfuscate();
//-->
</script>

You will almost certainly want to uncheck the “Use visual editor when writing” checkbox in your User options before this will work.

And the finished result should look like this:

The Trouble with Firefox

I tend to have a number of web browsers installed on my systems to make sure I can test web pages in a number of up to date browsers, and this includes Firefox (
)

But one issue I have with Firefox is how after a few hours’ use – especially as my use these days tends to include a number of AJAX-based sites, Gmail, etc. – the amount of memory being consumed sky-rockets despite, or possibly because of, the amount of physical memory on my main work machine.

This evening, I’ve implemented a number of hacks that may or may not help things out with this supposed memory leak (apparently it’s working as designed…), so here we are. This is Firefox version 2.0.0.6, by the way.

Firstly, we want to reduce the amount of RAM being used for Firefox’s cache. We do this like this:

1. Type “about:config” (no quotes) in the browser
2. Find browser.sessionhistory.max_total_viewer
3. Set its value to “0″
4. Restart Firefox

Secondly, as minimising the browser window seems to accomplish little, we’ll try to reduce memory use when it is:

1. Type about:config again and then press Enter.
2. Right-click in the page and select New -> Boolean.
3. In the box that pops up enter config.trim_on_minimize. Press Enter.
4. Now select True and then press Enter.
5. Restart Firefox.

Still with me? Now we’ll move on to page rendering speeds and more memory leak hacks, this time from “Have Laptop Will Travel”:

“Type in the address bar about:config.
Type pipelining in the filter bar.
Double-click on network.http.pipelining to set its value to TRUE.
Double-click on network.http.pipelining.maxrequests and change its value to 12 or more if you have broadband.

Play a little with the setting to find a configuration which is best for your connection.

Firefox is most hated for its memory usage. After having browsed some hours, Firefox will easily have taken 250MB or more of memory and slow down your PC. This is because FF has never been programmed to overwrite the memory it doesn’t use anymore and give free to other programs. Sometimes even closing Firefox won’t speed up your PC anymore. But the leakage can be prevented.

To do so, open a new tab and type about:config in your address bar again.
This time we want to limit the size of the memory cache.
Therefore we need to create a new preference, named browser.cache.memory.capacity.
Right click on any free area in the preferences window and choose New —> String.
Type now the name browser.cache.memory.capacity and in the next window set the value to 20000.
This will limit the size of the cache in the RAM to 20000KB and should prevent the annoying memory leak.
Restart your browser now.”

And after I’d found and implemented these hacks, I discovered them and more at the element14 Blog.

Stopping the Leechers

I was looking at the traffic for some of my sites the other day and spotted a lot of bandwidth (relatively) being used by one particular site. Now that site only really serves up a script to convert RSS feeds to JavaScript files so that I can them embed news items from selected sources into some client sites.

So I looked at the web stats. for that site and discovered that nearly all the traffic was coming from a site in China. I followed a couple of the referring links and found that the pages were basically just generating page after page of potential search terms with embedded news feeds presumably to serve ads. on those pages.

That does beg the question that if they are intelligent to code those pages or that system, why aren’t they intelligent enough to simply add the scripts to their own site and serve them from there?

Now my site is hosted on a regular Linux box running Apache Web Server, so it was a fairly straightforward task to simply block all traffic from that domain name using an .htaccess file with this code:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?baddomain\.com [NC]
RewriteRule .* - [F]

So the next day when I checked the stats., there were many thousands of Failed Referrer entries where the code was no longer being leeched by them. Job done!

But it did then appear that my site had some particular attraction to them because they then started running the scripts on a different domain! Now, my first thought was to simply amend the .htaccess file to read as follows:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?baddomain\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?anotherbadone\.com [NC]
RewriteRule .* - [F]

But I realised I could end up playing cat and mouse with them for life, so instead I have now set the .htaccess file to only allow specific referring domains access to the scripts by using this code:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?gooddomain\.co\.uk [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?anothergoodone\.com [NC]
RewriteRule .* - [F]

By adding the “!”, the expression now says “if the referrer is not gooddomain, then…”. The only difficulty for me then is making sure there are matching entries for all the legitimate referrers (trickier as one of the sites has multiple domain names).

We’ll see how we get on with this.

[edited to add]

And lo and behold! The blocking is working well, especially as the Leecher in question, hosted by NetEase.com, Inc., has now started doing it with a third domain name.