Sign InRegisterForgotten password?

RebelmouseTwitterFacebook

Tech Note: Yet Another LGF Pages Bookmarklet Update

But this version will make updating much easier
LGF • Views: 16,395

I know, right? Another one, just a day later? But this one actually will make it possible for me to update the types of auto-embed content the LGF Pages bookmarklet can identify — without making you re-install the bookmarklet to take advantage of the new features.

When you open this new version of the bookmarklet, it “phones home” to littlegreenfootballs.com no matter which site you’re on, and gets a file with the information it needs to find embedded video and audio in the current page. The cool thing about doing it this way is that it lets me add new embed types to the file on our server, and the bookmarklet automatically starts using them the next time you open it — no reinstallation necessary any more!

To get the new extensible version of the bookmarklet, reinstall it one more time by first deleting the old one (either by dragging it off the bookmark bar or by right-clicking and choosing “Delete”), then dragging the button labeled “Create a Page” (at the top of the right sidebar) to your bookmark bar in its place.

A trouble-shooting tip: if you click the bookmarklet and no window (or tab) opens, it’s probably because popups have been blocked by the browser. Most browsers have popup blocking on by default. The easiest way to handle this is to turn popup blocking off entirely; you can also allow popups on specific sites in the browser’s Preferences, but for posting purposes it’s a nuisance to do this for every site you might want to post something about.

The technical details

This new bookmarklet is actually calling our brand spanking new API (version 0.1, a one-day old baby), using the JSONP technique to get around the Javascript same-origin policy that would normally prevent this kind of cross-site access.

This happens in the jQuery.ajax() method beginning at line 27. It makes a call to the API at:

http://littlegreenfootballs.com/api/0.1/postRegex

jQuery handles all the details of the JSONP call (with its necessary callback function), parses the JSON response, and returns the data in the object lgf — in this case it consists of two regular expression definitions that are used on lines 34 and 36.

UPDATE at 5/18/13 5:08:19 pm

Stop the presses! Wouldn’t you know that as soon as I post this new version, I discover an even better way to get this done? Instead of JSONP, the bookmarklet now uses the new hotness, CORS, to do away with the callback function and the other JSONP kludges, and use pure unsullied JSON as Crockford intended.

I’ve updated the code below; the API now goes to version 0.2, so I can still support the JSONP method as well.

(function() {
	var j = '1.9.1', d = document;
	if (window.jQuery === undefined || window.jQuery.fn.jquery < j) {
		var done = false, s = d.createElement('script');
		s.src = '//ajax.googleapis.com/ajax/libs/jquery/' + j + '/jquery.min.js';
		s.onload = s.onreadystatechange = function(){
			if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
				done = true;
				jQuery.noConflict();
				lgfPost();
			}
		};
		d.getElementsByTagName('head')[0].appendChild(s);
	} else {
		lgfPost();
	}
	function esc(s) {
		return escape(s).replace(/\+/ig, '%252B');
	}
	function lgfPost() {
		(window.postPage = function() {
			jQuery.ajax('http://littlegreenfootballs.com/api/0.2/postRegex').done(function(lgf) {
				var f = q = w = '',
					u = esc(location.href),
					d = document,
					t = esc(d.title),
					s = esc((d.selection) ? d.selection.createRange().text : d.getSelection()),
					ob = jQuery('iframe').filter(function() {
						return this.src.match(RegExp(lgf.regex.embed, 'i'));
					});
				if (ob.length && !u.match(RegExp(lgf.regex.sites, 'i'))) {
					f = esc(ob.eq(0).attr('src'));
				}
				q = (
					'u=' + u +
					'&t=' + t +
					'&f=' + f +
					'&s=' + s
				);
				w = (
					'width=670,' +
					'height=820,' +
					'scrollbars=1,' +
					'status=1,' +
					'menubar=1,' +
					'location=1,' +
					'resizable=1'
				);
				window.open('http://littlegreenfootballs.com/weblog/lgf-postpage.php?' + q, '_blank', w);
			});
		})();
	}
})();
Advertisement

Tech Note: LGF Pages Bookmarklet Supports Scribd and SoundCloud

Making blogging easier
LGF • Views: 21,245

I’m about to sling some code at you here, so watch out. There’s a new improved version of the LGF Pages bookmarklet, and if you have an LGF account you can install it by deleting the old one (if you already installed it) from your browser’s bookmarks bar, then dragging the “Create a Page” button to the bookmarks bar in its place.

The new version extends our exclusive auto-embed feature to add Scribd.com and SoundCloud to the auto-detected embed types. If you open the bookmarklet on any page containing an embedded Scribd document or SoundCloud audio file, it will be automatically added to your Page. If you want to test it out, here’s a page at Right Wing Watch with an embedded SoundCloud file: Radio Host Frequented by Gun Activists Calls for Shooting of Bush Family & Obama, Sexual Violence Against Hillary Clinton | Right Wing Watch.

Here’s the source code for the bookmarklet, in the interest of full disclosure. (Also because I want to test the latest version of our source code formatter.)

There are a couple of interesting tricks in this one; notice the method of loading jQuery by injecting a script tag into the page. I’ll leave the rest as an exercise for the nerds amongst us.

The bookmarklet source code:

(function() {
	var j = '1.9.1', d = document;
	if (window.jQuery === undefined || window.jQuery.fn.jquery < j) {
		var done = false, s = d.createElement('script');
		s.src = '//ajax.googleapis.com/ajax/libs/jquery/' + j + '/jquery.min.js';
		s.onload = s.onreadystatechange = function(){
			if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
				done = true;
				jQuery.noConflict();
				init();
			}
		};
		d.getElementsByTagName('head')[0].appendChild(s);
	} else {
		init();
	}
	function esc(s) {
		return escape(s).replace(/\+/ig, '%252B');
	}
	function init() {
		(window.LGF_post = function() {
			var f = q = w = '',
				u = esc(location.href),
				d = document,
				t = esc(d.title),
				s = esc((d.selection) ? d.selection.createRange().text : d.getSelection()),
				ob = jQuery('iframe').filter(function() {
					return this.src.match(/https?:\/\/(www\.youtube|player\.vimeo\.|w\.soundcloud\.com\/player|www\.scribd\.com\/embeds\/)/i);
				});
			if (ob.length && !u.match(/www\.youtube\.com\/|vimeo\.com\/|soundcloud\.com|www\.scribd\.com/i)) {
				f = esc(ob.eq(0).attr('src'));
			}
			q = (
				'u=' + u +
				'&t=' + t +
				'&f=' + f +
				'&s=' + s
			);
			w = (
				'width=670,' +
				'height=820,' +
				'scrollbars=1,' +
				'status=1,' +
				'menubar=1,' +
				'location=1,' +
				'resizable=1'
			);
			window.open('http://littlegreenfootballs.com/weblog/lgf-postpage.php?' + q, '_blank', w);
		})();
	}
})();

And here’s the minified version created with Google Closure Compiler:

(function(){function b(b){return escape(b).replace(/\+/ig,"%252B")}function d(){(window.LGF_post=function(){var a=q=w="",d=b(location.href),c=document,f=b(c.title),c=b(c.selection?c.selection.createRange().text:c.getSelection()),e=jQuery("iframe").filter(function(){return this.src.match(/https?:\/\/(www\.youtube|player\.vimeo\.|w\.soundcloud\.com\/player|www\.scribd\.com\/embeds\/)/i)});e.length&&!d.match(/www\.youtube\.com\/|vimeo\.com\/|soundcloud\.com|www\.scribd\.com/i)&&(a=b(e.eq(0).attr("src"))); q="u="+d+"&t="+f+"&f="+a+"&s="+c;w="width=670,height=820,scrollbars=1,status=1,menubar=1,location=1,resizable=1";window.open("http://littlegreenfootballs.com/weblog/lgf-postpage.php?"+q,"_blank",w)})()}var f=document;if(void 0===window.jQuery||"1.9.1">window.jQuery.fn.jquery){var e=!1,a=f.createElement("script");a.src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";a.onload=a.onreadystatechange=function(){if(!e&&(!this.readyState||"loaded"==this.readyState||"complete"==this.readyState))e= !0,jQuery.noConflict(),d()};f.getElementsByTagName("head")[0].appendChild(a)}else d()})();

Tech Note: The LGF Pages Popup Window and Google Chrome

How to make it work
LGF • Views: 19,409

In last night’s thread about the new features in our LGF Pages posting bookmarklet, several people mentioned that the Chrome browser was blocking the window from opening.

Here’s how to fix that problem:

  • Go to Chrome Preferences.
  • At the bottom of the Settings page, click “Show advanced settings…”
  • Under Privacy, click “Content settings…”
  • In the dialog box that appears, scroll down until you see the section titled “Pop-ups.”
  • Click the button labeled “Manage exceptions…”
  • Enter “littlegreenfootballs.com” in the input field and make sure the Behavior is set to “Allow.”
  • Click “Done.”

And you’re done! Chrome will now allow the LGF Pages bookmarklet to open a new window (or tab), and all is right with the world.

Tech Note: Automatic YouTube/Vimeo Embedding for LGF Pages

Video made easy
LGF • Views: 24,920

We have a great new feature to announce tonight: when you click the LGF Pages bookmarklet on any web page that contains a YouTube or Vimeo video, the bookmarklet now automagically grabs that video’s information and embeds it in your post.

The LGF Pages bookmarklet could always do this if you opened it on the YouTube or Vimeo website, but now it can sense the presence of these video providers on any web page, and react with aplomb, dignity, and quiet reserve. Ahem.

To use this new feature you will have to reinstall your “Create a Page” bookmarklet. First delete the old one, either by dragging it off the bookmark bar or by right-clicking and choosing “Delete.” Then drag that button at the top of the right sidebar labeled “Create a Page” to your bookmark bar in its place, and you’re good to go.

Here’s a page you can test it on, at Right Wing Watch: Robertson Tells Woman Whose Husband Cheated to Remember ‘He’s a Man’ and Be Grateful She Lives in America | Right Wing Watch.

And here’s a screenshot, showing what it looks like when you open the LGF Pages bookmarklet on that page (notice that the video code is automatically generated, along with a link to the original page it came from):

UPDATE at 5/15/13 10:03:22 pm

The first release had a small bug, but it’s now fixed. Reinstall the bookmarklet one more time and everything will be groovy.

Tech Note: A BBEdit Text Filter to Minify Javascript With Google Closure Compiler

Maximum shrinkage
LGF • Views: 28,247

BBEdit is the pinnacle of text editors for Mac OS; it is the El Supremo in the room at the top of the stairs. I’ve been using it on an almost daily basis for more years than I like to think about, and it just keeps getting better.

One of BBEdit’s great features: “Text Filters” that let you write a script or short program in almost any language, and have it work on the contents of the current text document. Today I searched in vain for an already-written text filter that would call the Google Closure Compiler to “minify” Javascript code, and ended up just writing one myself, and I’m passing it on in case someone else out there might find it useful.

To use this, you have to first install the Closure Compiler Java app on your system, which isn’t difficult:

  • Download the ZIP file and expand it. (The decompression should happen automatically after downloading; if not, double click the ZIP file.)
  • In the Finder’s Go menu, click “Go to Folder…” and enter /usr/local/lib in the dialog box. This opens a desktop window showing that folder.
  • Copy the file compiler.jar from the folder compiler-latest to this new window. Because it’s in a system directory, you’ll probably be asked to enter your login password before the copy will proceed.

That’s it — the Closure Compiler is ready to go. Unless you’ve removed it, Java is already installed in Mac OS, so you shouldn’t need to do anything else.

Now for the Text Filter. In BBEdit, open a new window and and enter this short and simple Bash shell script:

#!/bin/bash

echo -n $(java -jar /usr/local/lib/compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS <&0)

This script needs to be placed in:

~/Library/Application Support/BBEdit/Text Filters

Easiest way to get it there is to first save it to the Desktop, as Closure Compiler.sh, then use the Finder’s Go->Go to Folder menu again to open the Text Filters folder, and move the file in. (This time, you shouldn’t need to enter a password because it’s your own Library folder.)

Now you’re ready to minify some Javascript. Open a BBEdit window with some code, then go to Text->Text Filters, and choose “Closure Compiler.” Wait a few seconds and BAM! All that code is suddenly compressed with the best minifier available. We’re talking maximum shrinkage here.

If you mark a selection before using the text filter, just that section will be minified. If you’re feeling adventurous, you can set the compilation_level option in the text filter to “ADVANCED_OPTIMIZATIONS,” but this won’t work with all code; there are some strict requirements. Check the Closure Compiler docs for more on that.

Tech Note: Hot Key Fever

They’re new, they’re keys, and they’re hot. They are hot keys.
LGF • Views: 29,849

Here’s one of those new feature announcements that serves double duty as an open thread: we now have some new “hot keys” available to all site visitors.

If you’re currently viewing a page that has a list of articles, you can now use the J and K keys to instantly jump to the top of the next or previous article.

J = next item
K = previous item

These keys also work with LGF comments.

The other new hot key: on any page with comments, you can now type N to activate the “New Comments” button.

N = New Comments

If you’re currently entering text into any kind of input field, these hot keys will be automatically disabled, to avoid confusion, mayhem, and/or recriminations.

Implemented via John Resig’s jQuery plugin.

Tech Note: New Feature: Refresh ‘Featured’ and ‘Recent’ Pages Lists

Keepin’ it fresh
LGF • Views: 28,280

This here’s a tricky way to do an open thread, and also announce a new feature: if you click the title of the ‘Featured Pages’ or ‘Recent Pages’ list, it will now refresh the list with the latest data for each Page, and any new Pages will show up at the top. With a nice animated fade to make it all pretty-like. No, I don’t know why I’m writing like a hillbilly.

Anyways y’all, that’s the new hotness for the day, and the open thread may now commence to git started.

Ten Million Comments and Counting

Breaking the eight-digit barrier
LGF • Views: 22,081

I’m proud to announce that today, Little Green Footballs stored our ten millionth comment in the database, posted by long-time LGF supporter Varek Raith: LGF Comment #10000000.

Bam!

Short, sweet, and to the point.

Varek Raith will be receiving a copy of “Drift: The Unmooring of American Military Power,” signed by Rachel Maddow herself. Thanks to Varek and Rachel Maddow, and to all the LGF readers who continue to make this one of the best sites for intelligent discussion on the Internet.

Our Ten Millionth Commenter Will Win a Signed Copy of Rachel Maddow’s Book “Drift”

Now, that’s a round number
LGF • Views: 17,289

Sometime in the next day or two, someone is going to post the ten millionth comment at LGF, and for this momentous round-number occasion we’re glad to announce that the lucky commenter will receive a copy of Rachel Maddow’s excellent work of historical analysis, Drift: The Unmooring of American Military Power, signed by Rachel herself, courtesy of her publisher.

The ten millionth comment will have a shiny golden header, so it will be impossible to miss. May the best lizard win!

Thursday Afternoon Open, With Music Video

Broccoli
LGF • Views: 19,914

The new one for RUFUS from their upcoming album, ATLAS.

Check them out here:
facebook.com

I’m finally biting the bullet and getting down to work on making the LGF codebase compatible with the upcoming jQuery 2.0. If all I had to worry about was my own Javascript code it wouldn’t be a big deal, but I use several plug-ins written by third parties and those are a lot more difficult to debug.

So in the meantime here’s an open thread with a flashy music video to make it more interesting…

^ back to top ^

Turn off ads by subscribing!
For about 33 cents a day, our subscription option turns off all advertisements at LGF!
Read more...

► LGF Headlines

  • Loading...

► Tweeted Articles

  • Loading...

► Tweeted Pages

  • Loading...

► Top 10 Comments

  • Loading...

► Bottom Comments

  • Loading...

► Recent Comments

  • Loading...

► Tools/Info

► Tag Cloud

► Contact

You must have Javascript enabled to use the contact form.
Your email:

Subject:

Message:


Messages may be published in our weblog, unless you request otherwise.
Tech Note:
Using the Contact Form
LGF Pages Create a Page

This is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title and text already filled in.

Last updated: 2013-05-19 10:14 am PDT

Recent Pages
Vicious Babushka
If Disney Cartoons Were Historically Accurate
, if embed doesn't play. If Disney Cartoons Were Historically Accurate -- powered by Cracked.com

1 hour, 12 minutes ago
Views: 98 • Comments: 0
Tweets: 1 • Rating: 1
Political Atheist
There Is No Such Thing Really as Professional Photographers
there's no such thing as Flickr Pro, because today, with cameras as pervasive as they are, there is no such thing really as professional photographers, when there's everything is professional photographers. Certainly there is varying levels of skills, but we didn't want to have a Flickr Pro anymore, we wanted everyone to have professional quality photos, space, and sharing." - Marissa Mayer, Yahoo ...

4 hours, 14 minutes ago
Views: 121 • Comments: 2
Tweets: 1 • Rating: 1
chadu
Sinkhole at 14th and F Closes Downtown D.C. Streets
Oh joy! Just a couple blocks from my office... A sinkhole at the intersection of 14th and F streets in Northwest Washington has closed streets around that intersection, and police warn that the closures could remain in place for two days. Crews are on the scene to repair the sinkhole. As a result, 14th Street is blocked between New York and Pennsylvania Avenues NW ...

5 hours, 28 minutes ago
Views: 162 • Comments: 0
Tweets: 5 • Rating: 0
thecommodore
WAPO’s Glenn Kessler Gives Three “Pinocchios” To Claim of Doctored Emails
It has long been part of the Washington game for officials to discredit a news story by playing up errors in a relatively small part of it. Pfeiffer gives the impression that GOP operatives deliberately tried to "smear the president" with false, doctored e-mails. But the reporters involved have indicated they were told by their sources that these were summaries, taken from notes ...

5 hours, 47 minutes ago
Views: 176 • Comments: 2
Tweets: 0 • Rating: 1
FemNaziBitch
Men Are Being Sexually Assaulted in the Military, but Nobody Is Talking About It — the Good Men Project
Our Soldiers are being raped...by our Soldiers. In the U.S. Military, annually, more men are being raped by men than women are being raped by men. I state this fact, articulating it in this manner, not to diminish what these women are enduring but to raise the level of awareness and discourse to fully include the men; they have been dropping through the ...

6 hours, 2 minutes ago
Views: 89 • Comments: 1
Tweets: 0 • Rating: 1
Haywood Jabloeme
CSOPE Classroom Curriculum System Dies Amid Criticism
AUSTIN, Texas (AP) - A classroom curriculum system used by hundreds of Texas school districts will stop offering lesson plans after some conservative groups claimed it was promoting anti-American values. State Sen. Dan Patrick said Monday that officials who created the system known as CSOPE will vote to scrap thousands of lesson plans this week, effectively killing the entire system. CSCOPE had helped ...

11 hours, 2 minutes ago
Views: 81 • Comments: 0
Tweets: 0 • Rating: 1
kristina37
We know how to reduce the incidence of common medical conditions but …
Obesity is on the rise-- as is the incidence of Heart Disease, Diabetes, Stroke and various forms of Cancer. And, shockingly, diseases that had in the past begun in old age are now appearing at much earlier ages. A groundbreaking scientific study showed how easily (and inexpensively) the rate of occurrence of these and other serious illness could be greatly reduced-- but this information ...

1 day, 6 hours ago
Views: 173 • Comments: 2
Tweets: 0 • Rating: 2
theye1
The Greatest (Movie) Speech Ever Made
73 years later is still relevant and powerful as ever. It's also because of this movie that Charlie Chaplin was labelled a "premature anti-fascist."

3 days, 21 hours ago
Views: 438 • Comments: 9
Tweets: 0 • Rating: 7
Romantic Heretic
The Singing Ringing Tree
Some people built this strange looking statue in England. And this is what it sounds like. Youtube Video

3 days, 22 hours ago
Views: 154 • Comments: 2
Tweets: 0 • Rating: 3
Skip Intro
Your Weekly Peggy Noonan Three Martini Column
We are in the midst of the worst Washington scandal since Watergate. The reputation of the Obama White House has, among conservatives, gone from sketchy to sinister, and, among liberals, from unsatisfying to dangerous. No one likes what they're seeing. The Justice Department assault on the Associated Press and the ugly politicization of the Internal Revenue Service have left the administration's credibility deeply, ...

4 days, 2 hours ago
Views: 338 • Comments: 5
Tweets: 0 • Rating: 2
 Frank says:

I'll do the stupid thing first and then you shy people follow...