OPML PopUp to ease Podcast Aggregation


/ Published in: JavaScript
Save to your folder(s)

This is a website specific script... pops up the source of an OPML file with 145+ podcasts.
http://www.productivity501.com/2006/11/free_academic_p.html

Note: The 'bookmarklet' format is included as a comment at the bottom... (write in a webpage an anchor element with the escaped javascript format in the href attribute).


Copy this code and paste it in your HTML
  1. /* 'Get Podcasts'
  2. * if isOPML is false, it pops up an escaped version in HTML.
  3. * if isOPML is true, it pops up an OPML version.
  4. * Either way, you need to copy and save the results as a file with an .opml extension
  5. * You can then add it to your Aggregator of choice:
  6. */
  7.  
  8. var isOPML=false;
  9. var entry=document.getElementById('entry-14040355');
  10. var ul=entry.getElementsByTagName('ul')[1];
  11. var links=ul.getElementsByTagName('a');
  12. var smalls=entry.getElementsByTagName('small');
  13. var names=[];var cond=false;var text=url=title="";
  14. for(var i=0;i<smalls.length;++i){
  15. cond=false;text=smalls[i].childNodes[0].nodeValue;
  16. for(var j=0;j<names.length;++j){
  17. if(text==names[j]){
  18. cond=true;
  19. }
  20. }
  21. if(!cond){
  22. names.push(text);
  23. }
  24. }
  25. //So far, names=["Purdue University","Southwest Tech","Berkeley","College of St. Scholastica","John Hopkins University","UCLA","Western Kentucky University","College of DuPage","NC State University","City University of New York","Ohio State University"];
  26. function filter(name){
  27. var t=output="";
  28. for(var k=0;k<links.length;++k){
  29. t=smalls[k].childNodes[0].nodeValue;
  30. if(t==name){
  31. url=links[k].href;
  32. title=links[k].childNodes[0].nodeValue;
  33. output=output+' <outline text="'+title+'" title="'+title+'" type="rss" xmlUrl="'+url+'" htmlUrl="'+url+'"/>'+"\n";
  34. }
  35. }
  36. return output;
  37. }
  38. var header='<opml version="1.0">'+"\n"+' <head>'+"\n"+' <title>Free Academic Podcasts</title>'+"\n"+' </head>'+"\n"+' <body>'+"\n";
  39. var body='';
  40. names.sort();
  41. var p='Choose from which university you would like to get the podcasts from:\n 0. All';
  42. for(var l=0;l<names.length;++l){
  43. p=p+'\n '+(l+1)+'. '+names[l];
  44. }
  45. var reply=prompt(p,"");
  46. var choice=parseInt(reply)-1;
  47. if(choice<0||choice>names.length-1||isNaN(choice)){
  48. for(var l=0;l<names.length;++l){
  49. body=body+' <outline title="'+names[l]+'" text="'+names[l]+'">'+"\n"+filter(names[l])+' </outline>'+"\n";
  50. }
  51. }else{
  52. body=' <outline title="'+names[choice]+'" text="'+names[choice]+'">'+"\n"+filter(names[choice])+' </outline>'+"\n";
  53. }
  54. body=body.replace(/="\s/g,'="');
  55. body=body.replace(/&/g,'&amp;');
  56. var footer=' </body>'+"\n"+'</opml>';
  57. var htmlHeader='<html><head><title>Free Academic Podcasts</title></head><body>';
  58. var htmlFooter='</body></html>';
  59. var opml=(isOPML)?header+body+footer:htmlHeader+(((((header+body+footer).replace(/&/g,'&amp;')).replace(/>/g,'&gt;')).replace(/</g,'&lt;')).replace(/\n/g,'<br>\n'))+htmlFooter;
  60. function popOPML(code){
  61. var gOPML=window.open('','Free Academic Podcasts','top=300,left=200,height=480,width=640');
  62. var tmp=gOPML.document;
  63. tmp.open();
  64. tmp.write(code);
  65. tmp.close();
  66. }
  67. popOPML(opml);
  68.  
  69. /*Resulting Bookmarklet:*/
  70. /*javascript:(function(){var%20isOPML=false;var%20entry=document.getElementById('entry-14040355');var%20ul=entry.getElementsByTagName('ul')[1];var%20links=ul.getElementsByTagName('a');var%20smalls=entry.getElementsByTagName('small');var%20names=[];var%20cond=false;var%20text=url=title='';for(var%20i=0;i&lt;smalls.length;++i){cond=false;text=smalls[i].childNodes[0].nodeValue;for(var%20j=0;j&lt;names.length;++j){if(text==names[j]){cond=true}}if(!cond){names.push(text)}}function%20filter(name){var%20t=output='';for(var%20k=0;k&lt;links.length;++k){t=smalls[k].childNodes[0].nodeValue;if(t==name){url=links[k].href;title=links[k].childNodes[0].nodeValue;output=output+' &lt;outline%20text=%22'+title+'%22%20title=%22'+title+'%22%20type=%22rss%22%20xmlUrl=%22'+url+'%22%20htmlUrl=%22'+url+'%22/&gt;'+%22\n%22}}return%20output}var%20header='&lt;opml%20version=%221.0%22&gt;'+%22\n%22+' &lt;head&gt;'+%22\n%22+' &lt;title&gt;Free%20Academic%20Podcasts&lt;/title&gt;'+%22\n%22+' &lt;/head&gt;'+%22\n%22+' &lt;body&gt;'+%22\n%22;var%20body='';names.sort();var%20p='Choose%20from%20which%20university%20you%20would%20like%20to%20get%20the%20podcasts%20from:\n%200.%20All';for(var%20l=0;l&lt;names.length;++l){p=p+'\n%20'+(l+1)+'.%20'+names[l];}var%20reply=prompt(p,%22%22);var%20choice=parseInt(reply)-1;if(choice&lt;0||choice&gt;names.length-1||isNaN(choice)){for(var%20l=0;l&lt;names.length;++l){body=body+' &lt;outline%20title=%22'+names[l]+'%22%20text=%22'+names[l]+'%22&gt;'+%22\n%22+filter(names[l])+' &lt;/outline&gt;'+%22\n%22;}}else{body=' &lt;outline%20title=%22'+names[choice]+'%22%20text=%22'+names[choice]+'%22&gt;'+%22\n%22+filter(names[choice])+' &lt;/outline&gt;'+%22\n%22;}var%20tx='='+'%22';body=body.replace(/=%22\s/g,tx);body=body.replace(/&amp;/g,'&amp;amp;');var%20footer=' &lt;/body&gt;'+%22\n%22+'&lt;/opml&gt;';var%20htmlHeader='&lt;html&gt;&lt;head&gt;&lt;title&gt;Free%20Academic%20Podcasts&lt;/title&gt;&lt;/head&gt;&lt;body&gt;';var%20htmlFooter='&lt;/body&gt;&lt;/html&gt;';var%20opml=(isOPML)?header+body+footer:htmlHeader+(((((header+body+footer).replace(/&amp;/g,'&amp;amp;')).replace(/&gt;/g,'&amp;gt;')).replace(/&lt;/g,'&amp;lt;')).replace(/\n/g,'&lt;br&gt;\n'))+htmlFooter;function%20popOPML(code){var%20gOPML=window.open('','Free%20Academic%20Podcasts','top=300,left=200,height=480,width=640');var%20tmp=gOPML.document;tmp.open();tmp.write(code);tmp.close()}popOPML(opml);})()*/

URL: http://www.productivity501.com/2006/11/free_academic_p.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.