// ==UserScript== // @name Craigslist Quick Page Viewer // @namespace derekdahmer.com // @description Clicking a link in a CraigsList list will toggle open and closed the linked page's content in a div directly below the link. Designed by Derek Dahmer. Released under the MIT license. // @include *.craigslist.org* // ==/UserScript== // Add jQuery var greasemonkey_jquery = document.createElement('script'); greasemonkey_jquery.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'; greasemonkey_jquery.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(greasemonkey_jquery); // Check if jQuery loaded function wait_until_jquery_loaded() { if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(wait_until_jquery_loaded,10); } else { $ = unsafeWindow.jQuery; letsJQuery(); } } wait_until_jquery_loaded(); // All your GM code must be inside this function function letsJQuery() { $(function() { // Initial data $(window).data("current_row_index",0); $(window).data("rows",$("blockquote > p")); if ($(window).data("rows").length == 0) { console.log('Could not find any listings'); } // Helper function for loading data in a div var load_html = function(div,url) { $contents_div = $(div).find("div.pagecontents"); if (!$contents_div.data("loaded")) { // Load just the inner content $contents_div.load(url + " #userbody"); $contents_div.data("loaded",true); } } // For each row listing... $("blockquote > p").each(function() { var $p = $(this); // Each row var $a = $($(this).find("a:first")); // The main link if ($a.length == 0) { console.log("Couldn't find blockquote > p > a:first"); } // Exclude "next 100 postings" if (!$p.children().is("a")) { return; } // ADD PERMALINK // Get info from link var url = $a.attr("href"); // Create new permanent link straight to page var newlink = $("Permalink").attr("href",url).css('margin-left','15px'); // Add to row if ($p.find("br.c").length > 0) { // furniture section has this $p.find("br.c").before(newlink); } else { $p.append(newlink); } // CREATE DIV // Make the first link on the line float left so the div floating works right $a.css("float","left"); // Add an invisible div under each list item to hold linked pages' html var $div = $("