RYM: Quick Edit List

inline editing of list items

  1. // ==UserScript==
  2. // @name RYM: Quick Edit List
  3. // @version 0.2
  4. // @description inline editing of list items
  5. // @match https://rateyourmusic.com/lists/edit*
  6. // @copyright 2014+, thought_house
  7. // @namespace https://greasyfork.org/users/2653
  8. // ==/UserScript==
  9.  
  10. var $ = unsafeWindow.jQuery;
  11.  
  12. $('#list_content .picturebutton').after('<br /><a class="smallbutton quick_edit" href="#">quick edit</a>');
  13.  
  14. $('.quick_edit').on('click', function(event) {
  15. event.preventDefault();
  16. if (!$(this).data('editing')) {
  17. $(this).data('editing', true);
  18. var $td = $(this).closest('tr').children('td:last');
  19. var html = $td.html().replace(/.*?<br><br>/, '');
  20. var title = $td.html().match(/.*?<br><br>/, '')[0];
  21. var item_type = '';
  22. var assoc_id = 0;
  23. var item_name = '';
  24. if (title.match(/class="album"/)) {
  25. item_type = 'l';
  26. } else if (title.match(/class="artist"/)) {
  27. item_type = 'a';
  28. } else if (title.match(/class="label"/)) {
  29. item_type = 'b';
  30. } else if (title.match(/class="film"/)) {
  31. item_type = 'F';
  32. } else if (title.match(/class="user."/)) {
  33. $(this).remove();
  34. return;
  35. } else {
  36. item_type = 'g';
  37. item_name = $td.find('b:first').text();
  38. }
  39. if (item_type == 'l') {
  40. assoc_id = parseInt($td.find('a.album:first').attr('title').match(/\d*]/)[0]);
  41. } else if (item_type == 'g') {
  42. assoc_id = 0;
  43. } else {
  44. assoc_id = parseInt($td.find('a:eq(0)').attr('title').match(/\d*]/)[0]);
  45. }
  46. $td.data('html', html);
  47. var text = html.replace(/<br>/g, "\n");
  48. text = text.replace(/<a class="normal_link".*?rel="nofollow".*?href="(.*?)" target="_blank">(.*?)<\/a>/g, '[$1,$2]');
  49. text = text.replace(/<strong class="rymfmt">/g, '[b]').replace(/<\/strong>/g, '[/b]');
  50. text = text.replace(/<em class="rymfmt">/g, '[i]').replace(/<\/em>/g, '[/i]');
  51. text = text.replace(/<s>/g, '[s]').replace(/<\/s>/g, '[/s]');
  52. text = text.replace(/<span style="color:(.*?);">(.*?)<\/span>/g, '[color $1]$2[/color]');
  53. text = text.replace(/<blockquote class="rymfmt">/g, '[blockquote]').replace(/<\/blockquote>/g, '[/blockquote]');
  54. text = text.replace(/<a href="\/wiki_deprecated\/.*?">(.*?)<\/a>/g, '[wp:$1]');
  55. text = text.replace(/<a class="wiki_link" href="\/wiki\/(.*?)">.*?<\/a>/g, '[wiki:$1]');
  56. text = text.replace(/<ul class="rymfmt">/g, '[ul]').replace(/<\/ul>/g, '[/ul]');
  57. text = text.replace(/<ol class="rymfmt">/g, '[ol]').replace(/<\/ol>/g, '[/ol]');
  58. text = text.replace(/<li class="rymfmt">/g, '[li]').replace(/<\/li>/g, '[/li]');
  59. text = text.replace(/<tt class="rymfmt">/g, '[tt]').replace(/<\/tt>/g, '[/tt]');
  60. text = text.replace(/<a title="\[(.*?)\]" href=".*?" class="(artist|album|label)"(?:(?!<\/a>).)+\[.*?<\/a>/g, '[$1]');
  61. text = text.replace(/<a title="\[(.*?)\]" .*?class="(artist|album|label)">(.*?)<\/a>/g, '[$1,$3]');
  62. text = text.replace(/<a title="\[(.*?)\]" .*?>.*?<\/a>/g, '[$1]');
  63. text = text.replace(/<span title="\[(.*?)\]">\.\.\.<\/span>/g, '[$1]');
  64. text = text.replace(/<a class="user.?" href="\/~.*?">(.*?)<\/a>/g, '[~$1]');
  65. text = text.replace(/<span class="userd">(.*?)<\/span>/g, '[~$1]');
  66. text = text.replace(/<div class="rsummaryframe" .*?<a href="\/collection\/.*?\/rating(\d*?)">[\s\S]*?<div class="clear"> <\/div>/g, '[Rating$1]');
  67. text = text.replace(/<a class="list" href="(.*?)">(.*?)<\/a>/g, '[http://rateyourmusic.com$1,$2]');
  68. text = text.replace(/<div class="youtube_container" id="youtube_container_.*?" data-youtube-id="(.*?)">[\s\S]*?<\/a>\s*?<\/div>/g, '[YouTube $1]');
  69. text = text.replace(/<a href="\/rymzilla\/view\?id=(\d*?)" style=".*?" class="bug_a">.*?<\/a>/g, '[Bug$1]');
  70. text = text.replace(/<span id="spoiler\d*?">[\s\S]*?<span id="spoilerinner\d*?" style="display:none;">([\s\S]*?)<\/span>/g, '[spoiler]$1[/spoiler]');
  71. text = text.replace(/<a href="\/board_message\?message_id=\d*&amp;find=(\d*)&amp;x=m#msg\d*">(.*?)<\/a>/g, '[Post$1,$2]');
  72. var lines = text.match(/\n/g);
  73. var height = Math.max(8, lines ? lines.length + 1 : 8);
  74. var $form = $('<form method="POST" action="/lists/new_item_2"></form>');
  75. $form.append('<textarea rows="' + height + '" style="width:100%" name="item_description">' + text + '</textarea><br>');
  76. var $save = $('<input type="submit" class="picturebutton quick_save" value="Save">');
  77. var $cancel = $('<a href="#" class="smallbutton quick_cancel">Cancel</a>');
  78. $form.append($save);
  79. $form.append($cancel);
  80. $form.append('<input type="hidden" name="item_name" value="' + item_name + '">');
  81. $form.append('<input type="hidden" name="page" value="' + unsafeWindow.currentPage + '">');
  82. $form.append('<input type="hidden" name="list_id" value="' + location.search.match(/list_id=\d*/)[0].replace('list_id=', '') + '">');
  83. $form.append('<input type="hidden" name="item_type" value="' + item_type + '">');
  84. $form.append('<input type="hidden" name="item_assoc_id" value="' + assoc_id + '">');
  85. $form.append('<input type="hidden" name="insert_before" value="-50">');
  86. $form.append('<input type="hidden" name="item_id" value="' + $(this).closest('tr').find('td:first').text() + '">');
  87. $td.html($td.html().replace(html, ''));
  88. $td.append($form);
  89. var $button = $(this);
  90. $cancel.on('click', function(event) {
  91. event.preventDefault();
  92. $form.replaceWith(html);
  93. $button.data('editing', false);
  94. });
  95. }
  96. });
  97.  
  98. GM_addStyle(".quick_save { \
  99. background-color: #d8d8ff; \
  100. padding: 5px; \
  101. margin: 3px; \
  102. font-family: Verdana,Arial,sans-serif; \
  103. font-size: x-small; \
  104. font-weight: 700; \
  105. border-top: 0px; \
  106. border-left: 0px; \
  107. border-right: 1px solid #999; \
  108. border-bottom: 1px solid #555; \
  109. cursor: pointer; \
  110. } \
  111. ");
  112. GM_addStyle(".quick_save:hover { \
  113. background-color: #ccf; \
  114. padding: 5px; \
  115. margin: 3px; \
  116. font-family: Verdana,Arial,sans-serif; \
  117. font-size: x-small; \
  118. font-weight: 700; \
  119. border-top: 0px; \
  120. border-left: 0px; \
  121. border-right: 1px solid #999; \
  122. border-bottom: 1px solid #555; \
  123. cursor: pointer; \
  124. } \
  125. ");