Advertisement
decembre

GM - Flickr Commented On (HTTPS) - TWEAK

Aug 17th, 2016
1,284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Flickr Commented On (HTTPS) - HACKS
  3. // @description    Shows whether or not you have commented on a photo
  4. // @include        http://www.flickr.com/*
  5. // @match      http://www.flickr.com/*
  6.  
  7. // @include http*://*flickr.com/*
  8.  
  9. // @version        2.29
  10. // @author     Brenton Cleeland (http://www.flickr.com/people/sesh00/)
  11. // @date       Jul 3, 2007
  12. // @modified       Jul 18, 2013
  13. // @contributor    Alesa Dam (http://www.flickr.com/people/alesadam/)
  14. // @contributor    Martin Heimburger (http://www.flickr.com/people/vispillo/)
  15. // @contributor    Bennie Hebbelynck (http://www.flickr.com/people/hebbervus/)
  16. // @icon       http://s3.amazonaws.com/uso_ss/icon/82360/large.png?1326790459
  17. // @downloadURL    https://userscripts.org/scripts/source/82360.user.js
  18. // @updateURL      https://userscripts.org/scripts/source/82360.meta.js
  19. // @run-at     document-end
  20. // @grant      GM_log
  21. // @grant      GM_addStyle
  22. // @grant      GM_xmlhttpRequest
  23. // ==/UserScript==
  24. //
  25. // Icon based on a Webdesigner Depot (http://www.webdesignerdepot.com/) icon from the Primo set. Downloaded from http://www.iconfinder.com/icondetails/40747/128/chat_comments_references_talk_icon
  26. //
  27. //
  28.  
  29. (function () {
  30. // shows the number of comments you left on the photo
  31. SHOW_COMMENT_COUNT=true;
  32.  
  33. var retrievingButtonImg = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%06%00%00%00%E0w%3D%F8%00%00%00%01sRGB%00%AE%CE%1C%E9%00%00%00%04gAMA%00%00%B1%8F%0B%FCa%05%00%00%00%20cHRM%00%00z%26%00%00%80%84%00%00%FA%00%00%00%80%E8%00%00u0%00%00%EA%60%00%00%3A%98%00%00%17p%9C%BAQ%3C%00%00%00%18tEXtSoftware%00Paint.NET%20v3.08er%9C%E1%00%00%01%B8IDATHK%EDTK%ABAa%14u%7F%A2%01%C5%84%92%09e%A4%94%81W%5E)%8F%89%01I%14%26%1E%09%11%C9%CC%C8%1F0%95%BC%9F%13%A5%A4%E5%EE%5D%E4r%CEu%DC%9B%EE%BDuw%9D%3A%F5%ED%B3%D6%DAk%AF%EF%BC%E1%BDd%AF%2C%22xe%C9%5E%09%CE%EE%FC%13%3Cr%E0%E7%2C%DA%EDv%C8%E7%F3p8%1C%B0%D9l%A2O*%95%C2r%B9%14%1DDt%82l6%8Bv%BB%8D%C3%E1%F0%A9%0B%DDn%17%E1pX%B4O%90%60%BF%DF%C3n%B7%E3x%3C%82%26%D9n%B7%D8l6X%ADVX%2C%16%98%CDf%98L%26%FCP%C5b1%0C%87CA!%82%04%04%16%0C%06%F9%03z_%AF%D7w%E0%A3%D1%88A%03%81%00%9CN'%FA%FD%FE%D7%08%08%9C%3C%26%E5%D3%E9%14%E3%F1%18g%F0%C1%60%00%8F%C7%C3%13X%2C%16%E9%04%D7%16%91%3D%F3%F9%FC%02%EE%F7%FB%E1%F5z%E1v%BB%D9%C6h4%8AV%AB%85H%24%02%A3%D1xG%F2p%C9%B4%87%EB%22%C5%9DN%87%03%40%C0%CDf%13%B9%5C%0E%B5Z%0D%3E%9F%0FZ%AD%F6C%BF(%C19%A6%A4%F2%1C%D3j%B5%CA%B1%25%F0L%26%83t%3A%8Dd2%89x%3C%8ED%22%81R%A9%C4%E7%0A%85%E2B%F2%D4E%A38Z%ADVV%5D%AF%D7Yu%A5Ra%92b%B1%C8%13%A8%D5ji%13%DC%9A%D9h4P.%97a6%9Ba2%99%600%18%A0%D7%EBYq%A1P%E0%9D(%95J%E9%3B%B8%EE%A4%FC%87B!%F4z%BD%3B%00%8DF%03%97%CB%05%9DN'x%17%9E%B2H(%87*%95%0Ar%B9%FCr%E9n%7B%BEM%F0%7B%FF%A6%8F%94I%3D%FF%FB%16%9D%00%89%06%23%97%2Bi%AE%7F%00%00%00%00IEND%AEB%60%82";
  34. var retrievingButtonTransparentImg = "data:image/png;base64," +
  35.     "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A" +
  36.     "/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wGBgg2JLgP+JQAAAHPSURBVEjH" +
  37.     "7ZU/i+pAFMVPhgdio6AggjaKWNlaKIrY29hpp73fJIgW9gEhhX4AsRBstLSJCUo6KwMGCyHG/L1b" +
  38.     "6Vv36a482Oa9PXCruZzf3LlzZzgiwneK4Zv1A/gPAL+eLZzPZ5pMJlAUBb7vPzVIp9Oo1WqIRqPc" +
  39.     "wwQiehiiKNJsNiPHcegzLZdL6vV617w/fB5WYFkWqaqKRqOBy+UCwzBARPB9/y4AoFgsQpZlaJqG" +
  40.     "ZDL52hGZpolQKATGGGzbvu3mI8D3ffA8D9M0YRjG3zX5vbHnefA87w7gOA7i8TgEQXi9ycFgEKfT" +
  41.     "Cb7vgzEG13VvhsPh8M48FoshlUrBNE10Oh0aDAbcl4BAIMBls1maz+eoVqtg7HehnuehUCjcIEQE" +
  42.     "XdeRyWRgmiba7TYJgnCDcM9e0+s1lWUZ15x8Po/VaoVSqQRN025H5rouGGOIRCKQJAmKomA8HnOf" +
  43.     "Ah6p3+/T4XBApVK564Wu6wiHw1BVFev1GqIofl3BR02nU7IsC4vFArZtw3VdOI6DRCKBXC6H7XYL" +
  44.     "SZIwGo24lyb5vY7HI202G5TLZfA8f2fQarWIMYbdbodut/v6JL8azWaT6vU67ff7h5PM/XyZ/z7g" +
  45.     "DW0ytGWUWU3+AAAAAElFTkSuQmCC";
  46. var commentedButtonImg = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%02%00%00%00o%15%AA%AF%00%00%00%04gAMA%00%00%B1%8F%0B%FCa%05%00%00%00%FFIDAT8Oc%FC%FF%FF%3F%03%05%E0%F7%FF%8F%0C%7F%18XY%D9%18%80%06Q%02%FE%FD%FF%F6%1F%84%FESj%10%DC%11%23%C8%A0%CF%DF~N%DAx1%BAsgD%FB%0EL%D4%BA%FC%F4%F3w_%B0F%0Ez%18%E5L%3D%F0%DFm%19.%04%94%CD%9F~%E8%F7%9F%BF%98f%A1%18%F4%FD%E7%EF%C8%8E%1D%FF%D3%B7%E11%ABz%C1%F1%DBO%DF%130%E8%F5%87o%F8%5D%04%B4%A0s%D5%D9%B3%B7_%D1%CB%20%A8%D7p%87%11%D0E%B5%8BN%DC%7CB%C8k%40%07w%AF%3E%0B%F4%DD%0D%86%02%CC%60%02%0AB%02%FB%E7%AF%3F%04%BC%06%94%86D%3F0%C8!q%3Fw%C7U%B8%89%40v%C9%EC%23%C4F%3F%9AUy%D3%0F%02%1D%024%22%B6k%D7%DA%23w%F0do%7Cy%0D%E8%91%99%DB%AE%C4%F7%EC%DEr%F2%3E%C1%12%02%A7A%2F%DE%7F%05%1A%B4%F7%FCc%82F%40%14%8C%A0%DCOd%88%10NG%C3%C8%20%00%86%F1%02%3D%CA%BE%AA%7D%00%00%00%00IEND%AEB%60%82";
  47. var commentedButtonTransparentImg = "data:image/png;base64," +
  48.     "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A" +
  49.     "/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wGBggwFb+LXygAAAFDSURBVEjH" +
  50.     "Y/z//z8DLQETA43BqAUDbwELNsEv33/9n7/7BsPJGy8Y/v7Dncp0FYQZktw1GSQEuRlxqWHElkxz" +
  51.     "px38P3njM4Kuy/WXYmBmYmLoSbVmYGFmYiQqiH78+vP/7ecfDAyKAgQtmLzxGQMPJyvDg5efiI+D" +
  52.     "L99/MwjzcjAw3P9AVBjzcbExfPr2exClIh5OVoa3n38QbcCXH78ZeDhZibeAg42F0UhZlCHXX4rh" +
  53.     "5q5TODXe3HWKIddfiuHT118MCmK8DCSlIlgyPX79OQNM2tVQliGp7yJczbwifYbrj98zFAcb4E2m" +
  54.     "DP///ycK500/+P8GQ8H/uTuu/o/t2vV/7ZE7/4nRx0hMcZ077eB/XUURhmPXnjOE2qoweJspMFKU" +
  55.     "k5HByw/f/jMwMDCoSPIzpHlqM5KaihhHK5xRCwa/BQCpjKvJw6UcSAAAAABJRU5ErkJggg==";
  56. var notCommentedButtonImg = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%06%00%00%00%E0w%3D%F8%00%00%00%01sRGB%00%AE%CE%1C%E9%00%00%00%04gAMA%00%00%B1%8F%0B%FCa%05%00%00%00%20cHRM%00%00z%26%00%00%80%84%00%00%FA%00%00%00%80%E8%00%00u0%00%00%EA%60%00%00%3A%98%00%00%17p%9C%BAQ%3C%00%00%00%18tEXtSoftware%00Paint.NET%20v3.08er%9C%E1%00%00%01FIDATHK%EDT%3D%8B%83%40%14%CC%FDq%0DZ%C746bc%91T6%01%0B%1B%C1%CA%CA%3F%60%E9G%8C%9A%C4%0F%84%80%22a%EE%9E%A0%C8%9D%9E%26%10%8E%83%0C%2C%AC%B0%3B%F3f%DEs%3F%F0%85%D5%2BA%02%AF%C4%EA%95%E4m%3Ao%81%B9%04%FE.%A2%DB%ED%06UU%B1%5E%AF%C10%CC%E4R%14%05%D7%EBu%D2%C8%A4%83%FD~%0F%C30%D04%CD%AF)X%96%85%EDv%3BynT%A0%AA*%B0%2C%8B%FB%FD%0ErR%14%05%F2%3CG%9A%A6%B8%5C.H%92%04Q%14%B5%8B%20I%12%82%20%18-dT%80%C86%9BM%7B%81%F6Y%96%FD%20%0F%C3%B0'%DD%EDvp%1C%E79%01%22%A7%8C%A9%F28%8Eq%3A%9D%D0%91%7B%9E%D7%92%3E%2C0%8C%88%E29%9F%CF%3D%F9%F1x%84%EF%FBp%5D%17%9D%80%2C%CB%FD%FE%BB%8D%D9%26S%1F%86%207DN%C2%84%AE%C9u%5D%2F%8F%88NvcJ%CD%EE%C6T%D3%B4%9E%A4%2CK%D0%B7(%8A%CF%8D%E9X94%8E%E4%80%889%8E%83i%9As%3F%F2%F2%C7N%D7u%1C%0E%07%F0%3C%DF%C6%B2%14%8B%9E%0A%9A%7FA%10%60%DB%F6R%DE%FE%DC%22%81%87Y%07%17%DE%02%B3%E9%FD%FF%88%3E%01Y%AF%5CU%DDg(%08%00%00%00%00IEND%AEB%60%82";
  57. var notCommentedButtonTransparentImg = "data:image/png;base64," +
  58.     "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A" +
  59.     "/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wGBggUJWi6jiIAAAFtSURBVEjH" +
  60.     "7VUxisJQEH3/syBBUMHGwsrCG9gELLQO2OY8XiCn8ASCWAjBQi9gRLCzs1ALTdQombdVXN2Nuwax" +
  61.     "Wh8MDPz582bmz59RJPFKaLwYb4J/QPBx72C/37PX62E6nUJE7jqoVCqwLAvFYlElGpBMlE6nw8Fg" +
  62.     "wPP5zN8wGo3oOE5s98NPYgZhGHI+n8O2bRyPRwRBAJIQkRsBANM04XkelsslyuXyYyU6HA7I5XLQ" +
  63.     "WuN0Ol2i+U4Qk2SzWQRBkO4NrksoIiCJKIou+jVB6i4yDAPb7RYiAq01ROTiPNajKLrJ2DCMxzPI" +
  64.     "ZDKqWq3SdV00Gg1o/RXHer2G7/soFArI5/MYj8fwfR+lUimRQN2bpnGbep6H2KZWq8GyLADAbrfD" +
  65.     "cDjEYrGAbdvp2zRJHMfharVit9tlu92m67r86456dB/0+32GYYjJZIJmswnTNNVTP/kam82Gs9kM" +
  66.     "9XodrVZLpRkV6r3R3gRP4xMAelzWTzapqAAAAABJRU5ErkJggg==";
  67. var errorCommentedButtonImg = 'data:image/png;base64,' +
  68.     'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sCDgYMGJVmyfcAAAF7SURBVEjH7VWxSwJRHP5MQQ4ChyCMhhrCgmw6dXBsadKknE2aT1wraClwFzcJQ4lAUChxc/F/sEFyCKegjFIOXkfpr+kOT++Od4W0+G3vfe993+/3+H48BxERZogFzBhzg78Z5EURb6XSr3kAcJilKC+KiCWT2no5lZrid8Nhbb2Ry/EbTIoDAPt4R+F7CABYrdd14p/dLgDAX6vxPdFhOj0lDgDHLueU+DjOdrb4OlAUBXK5jGG/rzMAgK+XV91Ztfrbp0dkWm2+DhhjKPZ6cHo8OvFJjIsfVe7tp2gpkcDi2rpp9ar49sm5vZgKgoDBYIDRaIRqNmv5NJlWG4wxCILAb+B2u+Hz+XAVDGIvtm+Z84doFLIsw+v12p8DVdys+nEYRdS0A7viaifcBpNzoKLQbOAuFMJKPM49By6z9MiXF7rqC80GDq5vEAgEtL3nSkWXJqM5AFmgI0nUkSQ69W8a8r1ikVqRiClPRGRpQESWl3l4x/xP/neDH8cgWRmnYjhfAAAAAElFTkSuQmCC';
  69. var errorCommentedButtonTransparentImg = "data:image/png;base64," +
  70.     "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A" +
  71.     "/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wGBgg7C6Zwu4AAAAGKSURBVEjH" +
  72.     "7VWxSwJxGH2XghwEDkEYDTWEBdl0p4NjS5Mm5WzS0nLiWkFLgbu4SRhKBIFBiZuLf0BNNkgO4RSU" +
  73.     "UcrBJaVfSyd3p3f8rpAWH9zw493vve/7eB8/jogwTkxhzJgY/M0gKwj0WijQb3kA4MxSlBUEisTj" +
  74.     "g/NsIsEZ+fVgcHBeymQ4ZgOjOAAo72/IffUAAPPlMrTiH80mAMBXKnFMI9pOJofEAWDX6RgS1+Jw" +
  75.     "bYWYOuh2u7fy5aXQa7d1BgDw+fyi+1et/uLxAalana0DRVGEfKsFh9utEzdCK75TvLGfoplYDNML" +
  76.     "i6bVq+Kr+0f2Ysrz/F2n00G/38dVOm05mlStDkVRwPM8u4HL5RK9Xi9O/X5sRDYtF+k+HIYsy/B4" +
  77.     "PHu290AVN6tei1ERNe3ArvhPJ8RsYNwDFblqBdeBAOaiUeY9cJqkh5NPjklbfa5awdbZOURRVEdB" +
  78.     "T8WiLk2j9gBEZPo1JIkakkQHvmUaxbfyeaqFQqY8EVkbEBGsLrPw3ORN/neDb7T6O9tyiYNeAAAA" +
  79.     "AElFTkSuQmCC";
  80.  
  81. if (typeof(GM_log) == "undefined") {
  82.     var GM_log = function(message) {
  83.         console.info('FCO: ' + message);
  84.     }
  85. }
  86.  
  87. // TWEAK TEST : document.getElementsByTagName('script')
  88. // OR:
  89. // document.getElementsByClassName("mystyle")[0].className;
  90. function addButtonToMenu(photo_id)
  91. {
  92.     var stats = document.getElementsByTagName('stats_ul');
  93.     if(stats) {
  94.     var libut = document.createElement('li');
  95.     libut.setAttribute('style','border-color:transparent;');
  96.     libut.setAttribute('class', 'stat-item');
  97.     var first = stats.getElementsByTagName('li')[0];
  98.     stats.insertBefore(libut, first);
  99.     var divbut = libut.appendChild(document.createElement('a'));
  100.     divbut.setAttribute('style','height:24px;');
  101.     var commentedButton = divbut.appendChild(document.createElement('img'));
  102.     commentedButton.setAttribute('style','position:relative; top:0px;');
  103.     commentedButton.id = 'FCO-image-' + photo_id;
  104.     commentedButton.alt = 'retrieving';
  105.     commentedButton.title = commentedButton.alt;
  106.     commentedButton.src = retrievingButtonImg;
  107.     }
  108.     return libut;
  109. }
  110.  
  111. function addButtonToImageCard(imgLinks,photo_id)
  112. {
  113.     if(imgLinks) {
  114.     var libut = document.createElement('li');
  115.     libut.setAttribute('style','border-color:transparent;');
  116.     libut.setAttribute('class', 'counter0');
  117.     var first = imgLinks.getElementsByTagName('li')[0];
  118.     imgLinks.insertBefore(libut, first);
  119.     var divbut = libut.appendChild(document.createElement('a'));
  120.     divbut.setAttribute('style','height:24px;');
  121.     var commentedButton = divbut.appendChild(document.createElement('img'));
  122.     commentedButton.setAttribute('style','position:relative; top:0px;');
  123.     commentedButton.id = 'FCO-image-' + photo_id;
  124.     commentedButton.alt = 'retrieving';
  125.     commentedButton.title = commentedButton.alt;
  126.     commentedButton.src = retrievingButtonImg;
  127.     }
  128.     return libut;
  129. }
  130.  
  131. function addButtonToThumbnail(thumbnail, photo_id, before) {
  132.     if ( document.getElementById('FCO-image-' + photo_id) ) { // there already is one (set page, apps page, ..)
  133.         return document.getElementById('FCO-image-' + photo_id);
  134.     }
  135.     if (!photo_id) {
  136.     photo_id = document.evaluate('./a/img', thumbnail, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).
  137.                 singleNodeValue.src.match(/.*flickr.com\/\d+\/(\d+)_.*/)[1];
  138.     }
  139.     var libut = document.createElement('div');
  140.         libut.setAttribute('style','display: inline-block; max-height: 16px; position: static;');
  141.     libut.setAttribute('id', 'FCO-photo-' + photo_id);
  142.     if (before) {
  143.         thumbnail.insertBefore(libut, before);
  144.     } else {
  145.         thumbnail.appendChild(libut);
  146.     }
  147.     var divbut = libut.appendChild(document.createElement('a'));
  148.     divbut.setAttribute('style', 'height:24px');
  149.     divbut.href = "#";
  150.     var commentedButton = divbut.appendChild(document.createElement('img'));
  151.     commentedButton.setAttribute('style', 'height:24px;');
  152.     commentedButton.id = 'FCO-image-' + photo_id;
  153.     commentedButton.title = 'retrieving';
  154.     commentedButton.src = retrievingButtonImg;
  155.        
  156.      var photoUrl = document.evaluate('.//a', thumbnail, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).
  157.             singleNodeValue.href;
  158.     getPhotoComments(photo_id, photoUrl);
  159.  
  160.     return libut;
  161. }
  162.  
  163. function addButtonToPoolItem(thumbnail) {
  164.     var photo_id = thumbnail.getAttribute('data-photo-id');
  165.     var hover = document.evaluate('.//div[contains(@class,"hover-target")]', thumbnail, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  166.     var meta = document.evaluate('.//div[contains(@class,"meta")]', thumbnail, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  167.     meta.setAttribute('style', 'display: inline-block; vertical-align: top;');
  168.     addButtonToThumbnail(hover, photo_id, meta);
  169. }
  170.  
  171. GM_addStyle(".FCO-gradient { " +
  172.     "background: -webkit-gradient(radial, center center, 0, center center, 24, from(#bbbbbb), to(#ffffff)); " +
  173.     "background: -webkit-radial-gradient(#bbbbbb, #ffffff); " +
  174.     "background: -moz-radial-gradient(circle, #bbbbbb, #ffffff); " +
  175.     "}; ");
  176.  
  177. function addButtonToJustifiedPoolItem(thumbnail, photo_id) { // photo_id passed for stream items
  178.     if (!photo_id) {
  179.         photo_id = thumbnail.getAttribute('data-photo-id');
  180.     }
  181.     if ( document.getElementById('FCO-image-' + photo_id) ) { // there already is one (set page, apps page, ..)
  182.         return;
  183.     }
  184.     var libut = thumbnail.appendChild(document.createElement('div'));
  185.         libut.setAttribute('style','display: inline-block; height: 24px; position: absolute; left: 10px; top: 10px;');
  186.     libut.setAttribute('id', 'FCO-photo-' + photo_id);
  187.     var divbut = libut.appendChild(document.createElement('a'));
  188.         divbut.setAttribute('style', 'height:24px;');
  189.         divbut.href = "#";
  190.     var commentedButton = divbut.appendChild(document.createElement('img'));
  191.         commentedButton.setAttribute('style', 'height:24px;');
  192.     commentedButton.setAttribute('class', 'FCO-gradient');
  193.         commentedButton.id = 'FCO-image-' + photo_id;
  194.         commentedButton.title = 'retrieving';
  195.         commentedButton.src = retrievingButtonTransparentImg;
  196.  
  197.         var photoUrl = document.evaluate('.//span[contains(@class,"photo_container")]/a', thumbnail, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.href;
  198.     getPhotoComments(photo_id, photoUrl);
  199.  
  200.     return libut;
  201. }
  202.  
  203. function setCommented(commented, photo_id, href, comment_count)
  204. {
  205.     var commentedButton = document.getElementById('FCO-image-' + photo_id);
  206.     if (!commentedButton) {
  207.     return;
  208.     }
  209.     switch (commented) {
  210.         case 'yes':
  211.             commentedButton.src = commentedButton.className.match('FCO-gradient') ? commentedButtonTransparentImg : commentedButtonImg;
  212.             commentedButton.alt = "Yay! You've commented on this photo!"
  213.         if (SHOW_COMMENT_COUNT) {
  214.             var countId = 'FCO-image-count-' + photo_id;
  215.             if (!document.getElementById(countId)) {
  216.                         var count = document.createElement('span');
  217.                 count.id = countId;
  218.                         count.setAttribute('style', "display:inline;z-index: 2; position: relative; left: -15px; top: -12px; font-size: 10px; color: white;padding: 0px;border-right:0;");
  219.                         count.innerHTML = comment_count;
  220.                         count.title = commentedButton.alt;
  221.                 commentedButton.parentNode.appendChild(count);
  222.             }
  223.                 }
  224.             break;
  225.         case 'no':
  226.             commentedButton.src = commentedButton.className.match('FCO-gradient') ? notCommentedButtonTransparentImg : notCommentedButtonImg;
  227.             commentedButton.alt = "Go ahead! Make my day! (by commenting)";
  228.         break;
  229.         case 'error':
  230.                 commentedButton.src = commentedButton.className.match('FCO-gradient') ? errorCommentedButtonTransparentImg : errorCommentedButtonImg;
  231.                 commentedButton.alt = "Error: " + comment_count;
  232.             break;
  233.         default:
  234.             commentedButton.src = commentedButton.className.match('FCO-gradient') ? errorCommentedButtonTransparentImg : errorCommentedButtonImg;
  235.             commentedButton.alt = "Error: " + commented;
  236.             break;
  237.     }
  238.     commentedButton.title = commentedButton.alt;
  239.     if (href == "#reply-box") { // when clicked, go to the reply-box, and set focus
  240.         commentedButton.style.cursor = 'pointer';
  241.         commentedButton.addEventListener('click', function (e) {
  242.             var textarea = document.getElementById('message');
  243.             textarea.focus();
  244.             textarea.setSelectionRange(0,0);
  245.         }, false);
  246.     } else {
  247.         commentedButton.parentNode.href = href;
  248.     }
  249. }
  250.  
  251. // DECEMBRE CORRECTION 2014 : https://www.flickr.com/groups/flickrhacks/discuss/72157645811287588/#comment72157648370481010
  252. function getUsername() {
  253. //  var buddyIcon = document.evaluate('.//a[contains(@class,"account")]/img[contains(@class,"gn-buddyicon")]', document, null,
  254. //          XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  255.            
  256.             var buddyIcon = document.evaluate('.//span[contains(@class,"account")]/img[contains(@class,"gn-buddyicon")]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  257.        
  258.     if (!buddyIcon) return null;
  259.     return buddyIcon.src.match(/flickr.com\/\d+\/buddyicons\/(\d+@\w\d{2})/)[1];
  260. }
  261.  
  262. // thanks to Vispillo (http://www.flickr.com/photos/31747528@N05/):
  263. var getJSVariable = function(regex) {
  264.                 // Thanks to Vispillo for this compact code
  265.                 var scripts = document.getElementsByTagName('script');
  266.         for (var i = 0; i < scripts.length; ++i) {
  267.                         var html = scripts[i].innerHTML;
  268.             try {
  269.                 return html.match(regex)[1];
  270.             } catch(e) {
  271.             }
  272.                 }
  273.                 return undefined;
  274.         }
  275. var api_key = getJSVariable(/[\"\']api_key[\"\'][ :]+[\"\']([^\"\']+)[\"\']/);
  276. var auth_hash = getJSVariable(/[\"\']auth_hash[\"\'][ :]+[\"\']([^\"\']+)[\"\']/);
  277.  
  278. function getPhotoComments(photo_id, commentHref)
  279. {
  280.  
  281. // HTTPS
  282.     GM_xmlhttpRequest({
  283.             method:"GET",
  284.             // use www.flickr.com to call the api (same servers :) ), to make it work in Chrome
  285.             url: "https://www.flickr.com/services/rest/?method=flickr.photos.comments.getList&api_key="+api_key+"&photo_id=" + photo_id + "&format=json&nojsoncallback=1&auth_hash="+auth_hash,
  286.             onload:function(details) {
  287.                 try{
  288.                     try {
  289.                         var data = JSON.parse(details.responseText);
  290.                     } catch (e) { // older versions of FF don't have JSON
  291.             try {
  292.                             data = eval( '(' + details.responseText + ')');
  293.             } catch (f) {
  294.                 GM_log("error parsing JSON data: " + e);
  295.                 GM_log("received from server for photo_id(" + photo_id + "): '" + details.responseText + "'");
  296.                 setCommented('error', photo_id, commentHref, e);
  297.                 return;
  298.             }
  299.                     }
  300.                     if (data.stat == 'ok') {
  301.                         var comments = data.comments.comment;
  302.                         var commented = false;
  303.             var comment_count = 0;
  304.             var permalink = undefined;
  305.                         if (comments) {
  306.                             comments.forEach(function(comment, idx) {
  307.                                 if (commented && !SHOW_COMMENT_COUNT) return;
  308.                                 if (comment.authorname == user_name || comment.author == user_name) {
  309.                                     commented = true;
  310.                     ++comment_count;
  311.                                     if (permalink == undefined) permalink = comment.permalink;
  312.                                 }
  313.                             });
  314.                         if (commented) {
  315.                         setCommented('yes', photo_id, permalink.replace('#comment', 'comment'), comment_count);
  316.                 } else {
  317.                         setCommented('no', photo_id, commentHref, comment_count);
  318.                     }
  319.                         } else {
  320.                             setCommented('no', photo_id, commentHref, comment_count);
  321.                         }
  322.                     } else {
  323.                         setCommented(data.code + " - " + data.message, photo_id, commentHref, comment_count);
  324.                     }
  325.                 } catch(e) {
  326.                     GM_log("error parsing API result: " + e);
  327.             GM_log("response received: " + details.responseText);
  328.             setCommented('error', photo_id, commentHref, e + ' - ' + details.responseText);
  329.                 }
  330.             },
  331.             onerror: function(details) {
  332.                 GM_log("error: " + details.statusText);
  333.         setCommented('error', photo_id, commentHref, details.statusText);
  334.             }
  335.     });
  336.    
  337. }
  338.    
  339. var user_name = getUsername();
  340. if(!user_name) {
  341.     GM_log("no user name found");
  342.     return;
  343. } else {
  344.     GM_log("running for user " + user_name);
  345. }
  346.  
  347.  
  348. // TEST not Working : TWEAK DECEMBRE : .new-comment-text
  349. try {
  350. if (document.location.href.match(/.*flickr.com\/photos\/[^\/]+\/\d+/)) { // on photo page
  351.     // add a 'reply' name anchor to jump to on button click
  352.     var anchorInCommentForm = document.evaluate('//div[contains(@class,"add-comment-form")]//a', document, null,
  353. //      var anchorInCommentForm = document.evaluate('//div[contains(@class,"new-comment-text")]//a', document, null,
  354.         XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  355.     if (anchorInCommentForm) { // no comment form: no permission to comment
  356.         anchorInCommentForm.setAttribute('name', 'reply-box');
  357.     }
  358.     var photo_id = document.location.href.match(/.*flickr.com\/photos\/[^\/]+\/(\d+)/)[1];
  359.  
  360.     addButtonToMenu(photo_id);
  361.     getPhotoComments(photo_id, "#reply-box");
  362. } else if (document.location.href.match(/.*flickr.com\/groups\/[^\/]+\/?$/) ||             // group start pages
  363.        document.location.href.match(/.*flickr.com\/groups\/[^\/]+\/pool/) ||           // group pools
  364.        document.location.href.match(/.*flickr.com\/photos\/[^\/]+\/favorites/) ||      // favorites pages
  365.        document.location.href.match(/.*flickr.com\/photos\/[^\/]+\/archives/) ||       // archive pages
  366.        document.location.href.match(/.*flickr.com\/photos\/friends/)) {                // friends
  367.  
  368.     var poolPhotos = document.evaluate('//div[contains(@class,"pool-photo") or contains(@class,"fave") or contains(@class,"photo-display-item")]',
  369.         document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  370.     if (poolPhotos.snapshotLength <= 0) {
  371.         GM_log("no photos found, aborting");
  372.     return;
  373.     }
  374.     var poolItemDecorator = addButtonToJustifiedPoolItem; // assume justified view
  375.     var squarePhotos = document.evaluate('count(//span[contains(@class,"pc_s")])', document, null,
  376.             XPathResult.ANY_TYPE, null);
  377.     if (squarePhotos.numberValue == poolPhotos.snapshotLength) {
  378.         // square thumbnails view
  379.     poolItemDecorator = null; // not on squares!
  380.     // except on set pages:
  381.     //if (document.location.href.match(/.*flickr.com\/photos\/[^\/]+\/sets/)) {
  382.         poolPhotos = document.evaluate('//span[contains(@class,"photo_container")]', document, null,
  383.                 XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  384.         poolItemDecorator = addButtonToThumbnail;
  385.     //}
  386.     } else {
  387.         var smallPhotos = document.evaluate('count(//span[contains(@class,"pc_t")])', document, null,
  388.         XPathResult.ANY_TYPE, null);
  389.     if (smallPhotos.numberValue == poolPhotos.snapshotLength) {
  390.         // small thumbnails view
  391.         poolItemDecorator = addButtonToPoolItem;
  392.     } else {
  393.         var mediumPhotos = document.evaluate('count(//span[contains(@class,"pc_m")])', document, null,
  394.             XPathResult.ANY_TYPE, null);
  395.         if (mediumPhotos.numberValue == poolPhotos.snapshotLength) {
  396.             // medium view
  397.             poolItemDecorator = addButtonToPoolItem;
  398.         } else {
  399.             var largePhotos = document.evaluate('count(//span[contains(@class,"pc_z")])', document, null,
  400.                 XPathResult.ANY_TYPE, null);
  401.             if (largePhotos.numberValue == poolPhotos.snapshotLength) {
  402.                 // large view
  403.                 poolItemDecorator = addButtonToPoolItem;
  404.             } else {
  405.                 //alert("justified view (" + poolPhotos.snapshotLength + ")");
  406.             }
  407.         }
  408.     }
  409.     }
  410.  
  411.     if (!poolItemDecorator) {
  412.     return;
  413.     }
  414.  
  415.     for (var i = 0, len = poolPhotos.snapshotLength; i < len; ++i) {
  416.         var thumbnail = poolPhotos.snapshotItem(i);
  417.     poolItemDecorator(thumbnail);
  418.     }
  419.     document.getElementById('main').addEventListener('DOMNodeInserted', function(event) {
  420.         setTimeout(function() { // workaround: addEventListener callback gets called in unsafeWindow!
  421.             try {
  422.                     var target = event.target;
  423.                     if (target.nodeName == 'DIV' && (target.className.match('pool-photo') || target.className.match('fave') || target.className.match('photo-display-item'))) {
  424.                 poolItemDecorator(target);
  425.                     }
  426.             } catch (e) {
  427.                     GM_log("error on insert: " + e);
  428.             }
  429.     }, 0);
  430.     }, true);
  431. } else if (document.location.href.match(/.*flickr.com\/photosof\/contacts/) ||     // contacts
  432.            document.location.href.match(/.*flickr.com\/activity/)) {               // recent activity
  433.     var poolThumbnails = document.evaluate('//span[contains(@class,"photo_container")]', document, null,
  434.         XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  435.     for (var i = 0, len = poolThumbnails.snapshotLength; i < len; ++i) {
  436.         var thumbnail = poolThumbnails.snapshotItem(i);
  437.         try {
  438.             var photo_id = document.evaluate('./a/img', thumbnail, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).
  439.                 singleNodeValue.src.match(/.*flickr.com\/\d+\/(\d+)_.*/)[1];
  440.         } catch (e) {
  441.             continue;
  442.         }
  443.         var commentedOnButton = addButtonToThumbnail(thumbnail, photo_id);
  444.         try {
  445.             // move the balloon
  446.             thumbnail.parentNode.insertBefore(commentedOnButton, thumbnail.nextSibling.nextSibling.nextSibling); // span - br
  447.         } catch (e) {
  448.             try {
  449.                 thumbnail.parentNode.insertBefore(commentedOnButton, thumbnail.nextSibling);
  450.             } catch (e) {
  451.                 GM_log("error inserting: " + e);
  452.             }
  453.             GM_log("error moving: " + e);
  454.             // ignore: let it be
  455.         }
  456.     }
  457. } else if (document.location.href.match(/.*flickr.com\/photos\/[^\/]+(\/page\d+|\/with\/\d+.*)?\/?$/) || // stream pages
  458.        document.location.href.match(/.*flickr.com\/photos\/[^\/]+\/sets/)) {                         // set pages
  459.     document.getElementById('main').addEventListener('DOMNodeInsertedIntoDocument', function(evt) {
  460.         setTimeout(function() { // workaround: addEventListener callback gets called in unsafeWindow!
  461.             try {
  462.                     var target = evt.target;
  463.                     if (target.nodeName == 'SPAN' && target.className.match("attribution")) {
  464.                 //unsafeWindow.console.log("add attribution");
  465.                 var thumbnailDiv = document.evaluate('.//ancestor::div[contains(@class,"photo-display-item")]', target, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  466.                 var photo_id = thumbnailDiv.getAttribute('data-photo-id');
  467.                 var thumbnail = document.evaluate('.//div[contains(@class,"thumb")]', thumbnailDiv, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  468.                 addButtonToJustifiedPoolItem(thumbnail, photo_id);
  469.                     } else if (target.nodeName == 'DIV' && target.className.match("cover-photo-position")) { // page has been reloaded: re-run
  470.                 //unsafeWindow.console.log("add buttons");
  471.                     var streamItems = document.evaluate('//div[contains(@class,"photo-display-item")]', document, null,
  472.                     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  473.                     for (var i = 0, len = streamItems.snapshotLength; i < len; ++i) {
  474.                     var streamItem = streamItems.snapshotItem(i);
  475.                     var photo_id = streamItem.getAttribute('data-photo-id');
  476.                     var thumbnail = document.evaluate('.//div[contains(@class,"thumb")]', streamItem, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  477.                     addButtonToJustifiedPoolItem(thumbnail, photo_id);
  478.                     }
  479.             } else {
  480.                 //unsafeWindow.console.log("adding " + target.nodeName + "(class:" + target.className + ")");
  481.             }
  482.             } catch (e) {
  483.                     GM_log("error on insert: " + e);
  484.             }
  485.     }, 0);
  486.     }, true);
  487.         var streamItems = document.evaluate('//div[contains(@class,"photo-display-item")]', document, null,
  488.         XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  489.         for (var i = 0, len = streamItems.snapshotLength; i < len; ++i) {
  490.         var streamItem = streamItems.snapshotItem(i);
  491.         var photo_id = streamItem.getAttribute('data-photo-id');
  492.         var thumbnail = document.evaluate('.//div[contains(@class,"thumb")]', streamItem, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  493.         addButtonToJustifiedPoolItem(thumbnail, photo_id);
  494.         }
  495. } else if (document.location.href.match(/.*flickr.com\/?$/)) {                        // flickr home page
  496.     var imageItems = document.evaluate('//div[contains(@class,"imgWrapper")]', document, null,
  497.         XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  498.     for (var i = 0, len = imageItems.snapshotLength; i < len; ++i) {
  499.     var imageItem = imageItems.snapshotItem(i);
  500.     var photo_id = imageItem.getAttribute('data-photo-id');
  501.     var imgLinks = document.evaluate('.//ul[contains(@class,"imgLinks")]', imageItem, null,
  502.         XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  503.     addButtonToImageCard(imgLinks, photo_id);
  504.     var photoUrl = document.evaluate('.//a', imageItem, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).
  505.             singleNodeValue.href;
  506.     getPhotoComments(photo_id, photoUrl);
  507.     }
  508. }
  509.  
  510. } catch (e) {
  511.     alert("exception: " + e);
  512. }
  513.  
  514. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement