content~20170625-184418.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var pageUrl = window.location.href;
  2. var username = $(".path__username > a").eq(0).text();
  3. var channelId = $(".channel > span").eq(0).attr("id").slice(16);
  4. var channelName = $(".channel > span").eq(0).text();
  5. // $.ajax({
  6. // //type: 'GET',
  7. // url: 'https://api.are.na/v2/channels/' + channelId + '/contents',
  8. // data: { get_param: 'value' },
  9. // dataType: 'json',
  10. // success: function (data) {
  11. // console.log(data.contents);
  12. // // $.each(data, function(index, element) {
  13. // // console.log(element.contents.title);
  14. // // });
  15. // }
  16. // });
  17. var blocks = [];
  18. var firstPage = $('<div>').addClass("page").append("<h1 id='channel'>Are.na <span class='slash'>/</span><br>" + username + " <span class='slash'>/</span><br><span id='channelName'>" + channelName + "</span></h1>\n<footer class='block__footer'><small><a href='" + pageUrl + "'>" + pageUrl + "</a></small></footer>");
  19. $.getJSON(chrome.extension.getURL('contents.json'), function(data) {
  20. //console.log(data);
  21. var channelContents = data.contents;
  22. $.each(channelContents, function( index, block ) {
  23. var datetime = new Date(block.created_at).toLocaleDateString();
  24. blocks[index] = "<div class='page'>\n"
  25. + "<article class='block'>\n"
  26. + "<header class='block__header'>\n"
  27. + ( block.title == null ? "<h3 class='block__title'>"+ block.generated_title + "</h3>\n" : "<h3 class='block__title'>" + block.title + "</h3>\n" )
  28. + "<p class='block__url'><span class='block__header__label'>URL</span><a href='https://www.are.na/block/"+ block.id + "'>https://www.are.na/block/"+ block.id + "</a><br>\n"
  29. + "<span class='block__header__label'>User</span> <span class='block__username'>" + block.user.full_name + "</span><br>\n"
  30. + "<span class='block__header__label'>Date</span> <time datetime='" + block.created_at + "' class='block__date'>" + datetime + "</time></p>\n"
  31. + "</header>\n"
  32. + ( block.content_html ? "<div class='block__content'>"+ block.content_html + "</div>\n" : "" )
  33. + ( block.image ? "<figure class='block__image'>\n<img src='"+ block.image.large.url + "'>\n" + ( block.description_html ? "<figcaption class='block__description'>" + block.description_html + ( block.source ? "<small class='block__source'>Source: <a href='"+ block.source.url + "'>"+ block.source.url + "</a></small>\n" : "" ) + ( block.attachment ? "<small class='block__attachment'>PDF: <a href='"+ block.attachment.url + "'>"+ block.attachment.url + "</a></small>\n" : "" ) + "</figcaption>\n" : "") + "</figure>\n" : "" )
  34. + "<footer class='block__footer'><small><a href='" + pageUrl + "'>" + pageUrl + "</a></small></footer>\n"
  35. + "</article>\n"
  36. + "</div>";
  37. });
  38. });
  39. //console.log(blocks);
  40. $.get(chrome.extension.getURL('head.html'), function( head ) {
  41. $( "head" ).html( head );
  42. });
  43. $.get(chrome.extension.getURL('body.html'), function( pages ) {
  44. $( "body" ).html( pages );
  45. $( "#pages" ).append(firstPage);
  46. $.each(blocks, function( index, block ) {
  47. $( "#pages" ).append(block);
  48. });
  49. });
  50. // Print
  51. //window.print();