Tech Note: LGF Pages Bookmarklet Supports Scribd and SoundCloud

Making blogging easier
LGF • Views: 26,131

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()})();

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