8chan-MD5

Display image md5s

  1. // ==UserScript==
  2. // @name 8chan-MD5
  3. // @version 0.3.1
  4. // @description Display image md5s
  5. // @author Anonymous
  6. // @match *://8ch.net/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/18941
  9. // ==/UserScript==
  10.  
  11. String.prototype.hexEncode = function() {
  12. var result = "";
  13. for (var i = 0; i < this.length; i++) { result += this.charCodeAt(i).toString(16); }
  14. return result;
  15. };
  16.  
  17. (function(window, $) {
  18. var md5 = {
  19. init: function() {
  20. // apply md5 to all posts now.
  21. md5.append(document.body);
  22.  
  23. // add md5 to any posts that may be added.
  24. this.observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { var newNodes = mutation.addedNodes; if (newNodes !== null) { $(newNodes).each(function() { md5.append(this); }); } }); });
  25. this.observer.observe($('.thread')[0], {attributes: true, childList: true, characterData: true});
  26. },
  27.  
  28. append: function(root) {
  29. $(root).find('.files .file').each(function() {
  30. var md5 = window.atob($(this).find('.post-image').attr('data-md5')).hexEncode();
  31. $(this).find('.fileinfo .unimportant').append(" <a href='javascript:md5.toggle(\"" + md5 + "\");'>#</a><br/><span id='md5_" + md5 + "' class='hidden'>MD5: " + md5 + "</span>");
  32. });
  33. },
  34. toggle: function(md5) {
  35. $('#md5_' + md5).toggleClass('hidden');
  36. }
  37. };
  38.  
  39. md5.init();
  40. window.md5 = md5;
  41. })(window, jQuery);