Tech Note: Yet Another New Improved LGF Pages Bookmarklet

Script injection module enabled
LGF • Views: 15,853

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 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
The Pandemic Cost 7 Million Lives, but Talks to Prevent a Repeat Stall In late 2021, as the world reeled from the arrival of the highly contagious omicron variant of the coronavirus, representatives of almost 200 countries met - some online, some in-person in Geneva - hoping to forestall a future worldwide ...
Cheechako
4 days ago
Views: 137 • Comments: 0 • Rating: 1
Texas County at Center of Border Fight Is Overwhelmed by Migrant Deaths EAGLE PASS, Tex. - The undertaker lighted a cigarette and held it between his latex-gloved fingers as he stood over the bloated body bag lying in the bed of his battered pickup truck. The woman had been fished out ...
Cheechako
2 weeks ago
Views: 303 • Comments: 0 • Rating: 1