Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
diff -rbc Downloads/TV Forecast orig.wdgt/TV/Functions.js Library/Widgets/TV Forecast.wdgt/TV/Functions.js *** Downloads/TV Forecast orig.wdgt/TV/Functions.js 2009-03-02 08:28:39.000000000 -0500 --- Library/Widgets/TV Forecast.wdgt/TV/Functions.js 2009-03-04 23:35:57.000000000 -0500 *************** *** 1,35 **** // Returns the search URL for the specified search text function tvShowSearchUrl(text) { ! return "http://www.tv.com/search.php?type=Search&stype=ajax_search&qs=" + ! escape(text) + ! "&search_type=program&pg_results=0&sort="; } // Parses TV show search results ! function parseTvShowSearchResults(html) { var results = new Array(); ! // global flag allows for multiple matches to occur ! var result_re = /Show: <a href=\"(.*?)\">(.*?)<\/a>/g; ! do ! { ! var result = result_re.exec(html); ! ! if (result !== null) ! { ! var url = result[1]; ! var title = result[2]; results.push({ ! url: url.replace(/\?.*/, ""), title: title }); } - } - while (result) var too_many_results = false; --- 1,27 ---- // Returns the search URL for the specified search text function tvShowSearchUrl(text) { ! return "http://www.thetvdb.com/api/GetSeries.php?seriesname=" + ! escape(text); } // Parses TV show search results ! function parseTvShowSearchResults(xml) { var results = new Array(); ! var series = xml.getElementsByTagName("Series"); ! for (var i=0; i<series.length; i++) { ! var serie = series[i]; ! var title = findChild(serie, "SeriesName").childNodes[0].nodeValue; ! var url = "http://dataproxy.pommepause.com/tvforecast/?what=next&source=thetvdb&show_id=" + findChild(serie, "seriesid").childNodes[0].nodeValue; results.push({ ! url: url, title: title }); } var too_many_results = false; Only in Library/Widgets/TV Forecast.wdgt/TV: TvShowParser2.js diff -rbc Downloads/TV Forecast orig.wdgt/TvShow.js Library/Widgets/TV Forecast.wdgt/TvShow.js *** Downloads/TV Forecast orig.wdgt/TvShow.js 2009-03-02 08:28:29.000000000 -0500 --- Library/Widgets/TV Forecast.wdgt/TvShow.js 2009-03-05 23:52:42.000000000 -0500 *************** *** 177,189 **** toXml: function() { return '<subscription>' + ! '<title>' + escape(this.title) + '</title>' + ! '<url>' + this.url + '</url>' + '<continent>' + this.continent + '</continent>' + '<city>' + this.city + '</city>' + '</subscription>'; }, eventTzClicked: function() { var tz_id = this.back_id + '-timezone'; --- 177,198 ---- toXml: function() { return '<subscription>' + ! '<title>' + this.xmlize(this.title) + '</title>' + ! '<url>' + this.xmlize(this.url) + '</url>' + '<continent>' + this.continent + '</continent>' + '<city>' + this.city + '</city>' + '</subscription>'; }, + xmlize: function(text) + { + text = text.replace(/&/g, '&'); + text = text.replace(/</g, '<'); + text = text.replace(/>/g, '>'); + text = text.replace(/"/g, '"'); + return text; + }, + eventTzClicked: function() { var tz_id = this.back_id + '-timezone'; *************** *** 269,275 **** remove_button.setEnabled(true); }, ! processSummary: function(text) { this.ajax_request = null; --- 278,284 ---- remove_button.setEnabled(true); }, ! processSummary: function(text, xml) { this.ajax_request = null; *************** *** 286,292 **** return; } ! var tv_show_summary = new TvShowParser(text); if (tv_show_summary.showAirsNext() == null) { --- 295,301 ---- return; } ! var tv_show_summary = new TvShowParser2(xml); if (tv_show_summary.showAirsNext() == null) { diff -rbc Downloads/TV Forecast orig.wdgt/tv.html Library/Widgets/TV Forecast.wdgt/tv.html *** Downloads/TV Forecast orig.wdgt/tv.html 2009-01-31 23:31:33.000000000 -0500 --- Library/Widgets/TV Forecast.wdgt/tv.html 2009-03-04 23:30:43.000000000 -0500 *************** *** 16,21 **** --- 16,22 ---- <script type="text/javascript" src="TV/Functions.js" charset="utf-8"></script> <script type="text/javascript" src="TV/ITunes.js" charset="utf-8"></script> <script type="text/javascript" src="TV/TvShowParser.js" charset="utf-8"></script> + <script type="text/javascript" src="TV/TvShowParser2.js" charset="utf-8"></script> <script type="text/javascript" src="TvShow.js" charset="utf-8"></script> <script type="text/javascript" src="tv.js" charset="utf-8"></script> diff -rbc Downloads/TV Forecast orig.wdgt/tv.js Library/Widgets/TV Forecast.wdgt/tv.js *** Downloads/TV Forecast orig.wdgt/tv.js 2009-03-02 08:28:31.000000000 -0500 --- Library/Widgets/TV Forecast.wdgt/tv.js 2009-03-05 23:51:48.000000000 -0500 *************** *** 21,27 **** this.ajaxCallback(e, callback); }.bind(this), onFailure: function(e) { ! callback(""); } }); }, --- 21,27 ---- this.ajaxCallback(e, callback); }.bind(this), onFailure: function(e) { ! callback("", ""); } }); }, *************** *** 29,45 **** ajaxCallback: function(xml_http_request, callback) { var text = xml_http_request.responseText; if (text == null) { ! callback(''); } else { text = text.replace(/\n/g, ""); text = text.replace(/\r/g, ""); ! callback(text); } }, --- 29,46 ---- ajaxCallback: function(xml_http_request, callback) { var text = xml_http_request.responseText; + var xml = xml_http_request.responseXML; if (text == null) { ! callback('', ''); } else { text = text.replace(/\n/g, ""); text = text.replace(/\r/g, ""); ! callback(text, xml); } }, *************** *** 657,665 **** search_request = new AjaxRequest(tvShowSearchUrl(text), searchCallback); } ! function searchCallback(text) { ! var results = parseTvShowSearchResults(text); var menu = widget.createMenu(); if (results == null) --- 658,666 ---- search_request = new AjaxRequest(tvShowSearchUrl(text), searchCallback); } ! function searchCallback(text, xml) { ! var results = parseTvShowSearchResults(xml); var menu = widget.createMenu(); if (results == null)
This paste will be private.
From the Design Piracy series on my blog: