Tech Note: Yet Another New Improved LGF Pages Bookmarklet

Script injection module enabled
LGF • Views: 15,917

If you post LGF Pages, you may notice that your LGF Pages posting window is nagging you to install yet another update for the bookmarklet. This isn’t a bug fix or anything urgent, just some internal code improvements that will further refine the “separate loader and function library” design of the bookmarklet.

One small visible change: instead of opening in the center of the screen, the Create a Page window now opens at the top, 100 pixels from the left edge.

So you don’t technically need to update right away, but the posting window is going to keep nagging away at you until you do, so you might as well get it over with.

(Right click your old bookmarklet, delete it, then drag that big ol’ “Create a Page” button to your browser’s bookmarks bar in its place.)

Since I’ve been posting the source for these monsters, here’s the Javascript source for the latest version of the bookmarklet loader, and the separate function library.

First, the bookmarklet you install in your browser bar. It does only three major tasks: opens the popup “Create a Page” window, loads the function library, and loads the latest version of jQuery (if it isn’t already present). When everything is properly loaded, it then calls the function library’s “getQuery” method to do all the magic stuff (searching for embeddable videos and sound files in the opening page). getQuery returns a query string that is used to set the “href” attribute of the popup window, containing the page’s URL and title, any selected text, and any embedded video or audio it found.

(function() {
	var w = 670,
		h = 824,
		popup = window.open(
			'http://littlegreenfootballs.com/weblog/lgf-postpage.php?loading',
			'_blank',
			'scrollbars=1,resizable=1,width=' + w + ',height=' + h + ',left=100'
		),
		done = false,
		s = document.createElement('script');
	s.src = 'http://littlegreenfootballs.com/lgfjs/lgf-postpage-functions.min.js?' + (new Date()).getTime();
	s.onload = s.onreadystatechange = function() {
		if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
			done = true;
			s.parentNode.removeChild(s);
			loadjQuery();
		}
	};
	document.getElementsByTagName('head')[0].appendChild(s);
	function loadjQuery() {
		var j = '1.10.2';
		if (typeof(window.jQuery) === 'undefined' || window.jQuery.fn.jquery < j) {
			var done = false,
				s = document.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;
					s.parentNode.removeChild(s);
					jQuery.noConflict();
					postPage();
				}
			};
			document.getElementsByTagName('head')[0].appendChild(s);
		} else {
			postPage();
		}
	}
	function postPage() {
		popup.location.href = 'http://littlegreenfootballs.com/weblog/lgf-postpage.php?' + $LGF_Page.getQuery() + '&v=1.2.1';
	}
})();

This is the function library “lgf-postpage-functions.min.js,” which the bookmarklet loads by injecting a script tag into the section of the opening page. This doesn’t hurt a bit.

var $LGF_Page = {
	version: '1.2.1',
	getQuery: function() {
		var esc = function(s) {
				return escape(s).replace(/\+/ig, '%252B');
			},
			ob,
			iframe = audio = '',
			url = location.href,
			d = document;
		if (url.match(/www\.npr\.org/i)) {
			ob = jQuery('a.download');
			if (ob.length) {
				audio = ob.eq(0).attr('href').split('?')[0];
			}
		} else if (url.match(/www\.rightwingwatch\.org/i)) {
			ob = jQuery('#content-area object embed');
			if (ob.length) {
				if (ob.eq(0).attr('src').match(/www\.youtube\.com\/v\//i)) {
					iframe = 'https://www.youtube.com/embed/' + ob.eq(0).attr('src').split('?')[0].split('/')[4];
				}
			} else {
				ob = jQuery('#content-area iframe');
				if (ob.length) {
					iframe = ob.eq(0).attr('src');
					if (iframe.substring(0, 2) == '//') {
						iframe = 'http:' + iframe;
					}
				}
			}
		}
		if (iframe == '') {
			ob = jQuery('iframe').filter(function() {
				return this.src.match(/https?:\/\/(www\.youtube|player\.vimeo\.|w\.soundcloud\.com\/player|www\.scribd\.com\/embeds\/|media\.mtvnservices\.com\/embed\/|mediamatters\.org\/embed\/static\/clips\/)/i);
			});
			if (ob.length && !url.match(/www\.youtube\.com\/|vimeo\.com\/|soundcloud\.com|www\.scribd\.com/i)) {
				iframe = ob.eq(0).attr('src');
			}
		}
		return (
			'u=' + esc(url) +
			'&t=' + esc(d.title) +
			'&f=' + esc(iframe) +
			'&a=' + esc(audio) +
			'&s=' + esc(d.selection ? d.selection.createRange().text : d.getSelection())
		);
	}
};

Jump to bottom

4 comments
1 Iwouldprefernotto  Sun, Nov 10, 2013 4:49:09pm

Thanks, but I would have a better chance of reading the Rosetta Stone.

2 Charles Johnson  Sun, Nov 10, 2013 4:49:22pm
3 Dancing along the light of day  Sun, Nov 10, 2013 5:08:01pm

re: #2 Charles Johnson

Here, kitty, kitty!

4 darthstar  Sun, Nov 10, 2013 5:16:10pm

This article has been archived.
Comments are closed.

Jump to top

Create a PageThis 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, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2023-04-04 11:11 am PDT
LGF User's Guide RSS Feeds

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Cash.app
Recent PagesClick to refresh
Uncommon US Flags #3: Storm Warning Flags Indianola, Texas after the Civil War became the principal port for the state, due to its location on Matagorda Bay. The town steadily grew as commerce, tourism, and agriculture expanded. In 1875, a powerful Category 3 hurricane struck Indianola, ...
Anymouse 🌹🏡😷
Yesterday
Views: 27 • Comments: 0 • Rating: 1
A Friday at the Tail End of SpringJust out and about for a bit. First a walk downtown where the two rivers meet, then a short drive just outside of town.
William Lewis
3 days ago
Views: 124 • Comments: 0 • Rating: 3
The Good Liars at Miami Trump Rally [VIDEO] Jason and Davram talk with Trump supporters about art, Mike Lindell, who is really president and more! SUPPORT US: herohero.co SEE THE GOOD LIARS LIVE!LOS ANGELES, CA squadup.com SUBSCRIBE TO OUR AUDIO PODCAST:Apple Podcasts: podcasts.apple.comSpotify: open.spotify.comJoin this channel to ...
teleskiguy
5 days ago
Views: 411 • Comments: 0 • Rating: 0
Ranked-Choice Voting Has Challenged the Status Quo. Its Popularity Will Be Tested in November. JUNEAU — Alaska’s new election system — with open primaries and ranked voting — has been a model for those in other states who are frustrated by political polarization and a sense that voters lack real choice at the ...
Cheechako
4 weeks ago
Views: 387 • Comments: 0 • Rating: 2