// ==UserScript== // @name General SPARQL tester // @author Troy Fleischauer // @date 11/05/09 // @namespace http://somewhere.com // @include http://projects.ischool.washington.edu/tabrooks/343INFOAutumn09/SPARQLhuskies/sparqlHuskies.htm // @exclude http://students.washington.edu/troyf2/INFO343/ // ==/UserScript== (function() { try { var endpoint; var query; var rawQuery; ////////////////////////////////////////////////////////////////////////////////////// goes to web site, assigns address to variable // Uncomment one of these SPARQL endpoints endpoint = "http://dbpedia.org/sparql"; //dbpedia //////////////////// Query variable ///////////////////////////////////////////////////////// Sparql query, changing query // rawQuery = "select distinct ?concept where { [] a ?concept } limit 50"; rawQuery = "SELECT ?color WHERE { ?color . } "; //////////////////////////////////////////////////////////////////////////////////////////////////// // HTTPRequest code with MIME type 'text/html' query = encodeURIComponent(rawQuery); GM_xmlhttpRequest({ method: 'GET', url: endpoint + '?query=' + query, headers: { 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey', 'Accept': 'text/html', }, onload: function(responseDetails) { //////////////////////////////////////////////////////////////////////////////// // Shows results in alert() //alert(responseDetails.responseText); var newDiv = document.createElement("div"); newDiv.innerHTML = responseDetails.responseText; var td = document.evaluate('//td', newDiv, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); //parses it away from the containers tags and captures it in variable var myPage = document.getElementById("colorDiv"); // from html page var tx = document.createTextNode(td.snapshotItem(0).firstChild.nodeValue); // makes a text node myPage.appendChild(tx); // adds paragraph to html div //alert (stringCollector); } }); } catch (eErr) { alert ("Greasemonkey error: " + eErr); } return; }) ();