Tech Note: A New Improved Auto-Updating LGF Pages Bookmarklet

Automatic is good
LGF • Views: 20,836

That magnified image of the code means there’s a new version of the LGF Pages “Create A Page” bookmarklet tonight, Pages authors.

I’m stoked about this one, because I finally worked out a way to make the part you install in your browser nothing more than a loader for the rest of the code. I was halfway there with the previous version, but the new one separates the loader from the function library completely.

One of the big drawbacks of bookmarklets in general is that when they’re updated, you have to go through the not-difficult but yes-tedious process of manually deleting the old one and installing the new one.

But the cool thing about implementing the bookmarklet as a loader is that it lets me update and modify the actual guts of the code at will — and it will automagically be updated for every Pages author, with no need to reinstall the bookmarklet. Every time you click, you’ll be using the latest version of the code. With any luck, this will be the last version of the LGF Pages bookmarklet you’ll have to re-install for a while.

(And it still gets around the popup blockers of most popular browsers too.)

Anyway, install the new version of the “Create A Page” bookmarklet and enter the new era, where everything is sparkly and magical.

Here’s the latest code for the bookmarklet and function library, for those with a hankering to know how it works.

First, the loader module that you install as a bookmarklet; if you’ve seen our previous posts you’ll notice how much simpler this code is now. It first loads the function library (which creates a global variable named $LGF_Page), then loads the latest version of jQuery, checking to make sure both of these scripts aren’t already loaded:

(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=' + ((screen.width / 2) - (w / 2)) + ',top=' + ((screen.height / 2) - (h / 2)));
	if (typeof(window.$LGF_Page) === 'undefined') {
		var done = false,
			s = document.createElement('script');
		s.src = 'http://littlegreenfootballs.com/lgfjs/lgf-postpage-functions.min.js?' + (new Date()).getTime().toString();
		s.onload = s.onreadystatechange = function() {
			if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
				done = true;
				loadjQuery();
			}
		};
		document.getElementsByTagName('head')[0].appendChild(s);
	} else {
		loadjQuery();
	}
	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;
					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();
	}
})();

And here’s the auto-updating function library that’s loaded by dynamically injecting a script tag into the page’s head section (in the code above):

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

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
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
3 weeks ago
Views: 441 • Comments: 0 • Rating: 1