Created
August 28, 2009 20:18
-
-
Save dtjohnso/177199 to your computer and use it in GitHub Desktop.
Insert class links from remote location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Insert class links from remote location | |
// @namespace http://www.duncanandmeg.org/ | |
// @description Pulls down links from one of my instapaper.com folder RSS feeds and inserts them into a page. Let him who understandeth modify to his own satisfaction! | |
// @author Duncan Johnson | |
// @include http://home.bju.edu/ | |
// @include https://home.bju.edu/ | |
// ==/UserScript== | |
/* | |
* -------------------------------------------------------------- | |
* USER EDIT: paste your feed URL in the line below | |
* -------------------------------------------------------------- | |
*/ | |
var feedURL = "http://www.instapaper.com/folder/48337/rss/11185/QBV0RZfH4KBO7GwgrR3D8b7sv90"; | |
/* | |
* -------------------------------------------------------------- | |
* USER EDIT: Do not edit any code below this comment... | |
* -------------------------------------------------------------- | |
*/ | |
// Add jQuery | |
var GM_JQ = document.createElement('script'); | |
GM_JQ.type = 'text/javascript'; | |
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'; | |
document.getElementsByTagName('head')[0].appendChild(GM_JQ); | |
// All your GM code must be inside this function | |
function letsJQuery() { | |
GM_xmlhttpRequest({ | |
url: feedURL, | |
method: "GET", | |
onload: function (responseObject){ | |
var data = responseObject.responseText; | |
data = data.replace(/link>/g,"url>"); //necessary because jQuery arfs the </link> tag for some reason | |
var classString = ""; | |
$("item",data).each(function (i) { | |
var link = $("url",this).text(); | |
(link.match(/\.doc/)) ? img = "<img src='http://home.bju.edu/images/doc.gif'/>" : img = ""; | |
classString = classString + "<li><a href='" + link + "'>" + $("title",this).text() + "</a> " + img + "</li>"; | |
}); | |
GM_setValue ("classStringCached", classString); //cache string for offline use | |
var message = "<div id='classes'><h2>Class Links</h2><ul>" + classString + "</ul></div>"; | |
if ($("#sidelinks #classes").length === 0) { $("#sidelinks").prepend(message); } | |
}, | |
onerror: function () { | |
var classString; | |
if (typeof(GM_getValue("classStringCached")) === "undefined") { | |
classString = "<p>Sorry! There was an error accessing your class link information. We will try again the next time you view this page.</p>"; //polite total fail message | |
} else { | |
classString = "<ul>" + GM_getValue("classStringCached") + "</ul>"; //access cached classString value | |
} | |
if ($("#sidelinks #classes").length === 0) { $("#sidelinks").prepend("<div id='classes'><h2>Class Links</h2>" + classString + "</div>"); } | |
} | |
}); | |
} | |
// Check if jQuery's loaded | |
function GM_wait() { | |
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); } | |
else { $ = unsafeWindow.jQuery; letsJQuery(); } | |
} | |
GM_wait(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment