Sidenotes

Allows to add a sidenote to each thread

  1. // ==UserScript==
  2. // @name Sidenotes
  3. // @version 1.0.0
  4. // @description Allows to add a sidenote to each thread
  5. // @author DaCurse0
  6. // @copyright 2017+, DaCurse0
  7. // @match https://www.fxp.co.il/forumdisplay*
  8. // @require https://code.jquery.com/jquery-latest.min.js
  9. // @namespace https://greasyfork.org/users/62051
  10. // ==/UserScript==
  11.  
  12. var uri = 'http://simpleicon.com/wp-content/uploads/note-4.svg';
  13. var notes;
  14.  
  15.  
  16. $(function() {
  17.  
  18. try {
  19. notes = JSON.parse(localStorage.sidenotes_data);
  20. } catch(ex) {
  21. localStorage.sidenotes_data = '{}';
  22. notes = {};
  23. }
  24.  
  25. $(window).unload(function() {
  26. localStorage.sidenotes_data = JSON.stringify(notes);
  27. });
  28.  
  29. var icon = '<img style="position:relative;bottom:3px;right:30px;cursor:pointer;" width="14" height="14" src="'+uri+'" title="View Sidenote" class="sidenote">';
  30. var shade = '<div style="position:fixed;background-color:rgba(0,0,0,0.5);width:100%;height:100%;z-index:999999998;" id="shade"></div>';
  31. var ui = '<textarea style="position:fixed;z-index:999999999;background-color:white;border:1px solid black;width:640px;height:360px;top:50%;left:50%;transform:translate(-50%, -50%);" id="note"></textarea>';
  32.  
  33. $('dl[class="threadlastpost td"]').each(function(i, v) {
  34. v.children[2].innerHTML += icon;
  35. v.children[2].children[2].id = v.parentElement.parentElement.id.substr(7);
  36. v.children[2].children[2].onclick = function() {
  37. id = this.id;
  38. $('body').prepend(shade);
  39. $('#shade').after(ui);
  40. $("#note").val(notes[id]);
  41. $('#shade').click(function() {
  42. notes[id] = $("#note").val();
  43. $('#shade').remove();
  44. $('#note').remove();
  45. console.dir(notes);
  46. });
  47. };
  48. });
  49.  
  50. });