Additional buttons for Lists, Posts and PMs

adds buttons

当前为 2014-06-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Additional buttons for Lists, Posts and PMs
  3. // @description adds buttons
  4. // @version 1.9
  5. // @include https://rateyourmusic.com/lists/new_item*
  6. // @include https://rateyourmusic.com/board_new_message?*
  7. // @include https://rateyourmusic.com/messages/compose?*
  8. // @include https://rateyourmusic.com/collection/*
  9. // @include http://rateyourmusic.com/collection/*
  10. // @include https://rateyourmusic.com/~*
  11. // @include https://rateyourmusic.com/list/*
  12. // @exclude https://rateyourmusic.com/collection/*/stag/*
  13. // @exclude http://rateyourmusic.com/collection/*/stag/*
  14. // @grant metadata
  15. // @namespace https://greasyfork.org/users/2625
  16. // ==/UserScript==
  17.  
  18.  
  19. var textArea;
  20. if (document.URL.indexOf("/list/") > 0) {
  21. flag = document.getElementsByClassName('fav0')[0];
  22. if (flag != undefined) {
  23. listId = flag.getAttribute('id').split('_')[1]
  24. }
  25. textArea = 'comments_list_comments_s_c_'+listId;
  26. $('.commentbutton:eq(0)').parent().attr('style','height:75px;')
  27. $('#list_comments_dummybutton').attr('style','height:75px;width:100%;')
  28. } else if (document.URL.indexOf("~") > 0) {
  29. userId = $('#shoutbox_assoc_id').val();
  30. textArea = 'comments_shoutbox_u_c_' + userId;
  31. $('.commentbutton:eq(0)').parent().attr('style','height:75px;')
  32. $('#list_comments_dummybutton').attr('style','height:75px;width:100%;')
  33. } else {
  34. var boxTypes = ['msg_body', 'item_description','body'];
  35. i = -1;
  36. while (textBox == undefined && i < boxTypes.length) {
  37. i++;
  38. var textBox = document.getElementById(boxTypes[i]);
  39. textArea = boxTypes[i];
  40. }
  41. }
  42. if (textArea != undefined){addButtons(textArea)}
  43.  
  44. function spoil(){
  45. editTextareaTwo('asdf', 'asfd')
  46. }
  47.  
  48. function editTextareaTwo(addBefore, addAfter) {
  49. var c = document.getElementById(textArea);
  50. if (document.selection) {
  51. var g = document.selection.createRange().text;
  52. c.focus();
  53. var e = document.selection.createRange();
  54. e.text = addBefore + g + addAfter
  55. } else {
  56. if (c.selectionStart | c.selectionStart == 0) {
  57. if (c.selectionEnd > c.value.length) {
  58. c.selectionEnd = c.value.length
  59. }
  60. var h = c.selectionStart;
  61. var b = c.selectionEnd + addBefore.length;
  62. c.value = c.value.slice(0, h) + addBefore + c.value.slice(h);
  63. c.value = c.value.slice(0, b) + addAfter + c.value.slice(b);
  64. c.selectionStart = h + addBefore.length;
  65. c.selectionEnd = b;
  66. c.focus()
  67. }
  68. }
  69. }
  70. function addButtons(prev) {
  71. msg_body = document.getElementById(prev);
  72. if ($('#'+prev)) {
  73. var btnContents = [['bold','strong','<b>B</b>'],['italic','emphasis','<i>I</i>'],['link','a_href','link']];
  74. var btnTemplate = '<a id="ID_HERE" href="javascript:void(0);" class="ratingbutton" title="ID_HERE"';
  75. btnTemplate += '>TEXT_HERE</a>';
  76. if (document.URL.indexOf("/board_new_message?") < 0){
  77. $.each(btnContents, function() {
  78. $('#'+prev).before(btnTemplate.replace(/ID_HERE/g,this[0]).replace('TEXT_HERE',this[2]))
  79. $('#'+this[0]).attr('onClick','return pnhEditTextarea(\''+prev+'\',\''+this[1]+'\')')
  80. });
  81. }
  82. if (document.URL.indexOf("~") < 0 && document.URL.indexOf("/list/") < 0) {
  83. $('#'+prev).before(btnTemplate.replace(/ID_HERE/g,'note').replace(/TEXT_HERE/g,'note'))
  84. document.getElementById('note').addEventListener('click', function(){editTextareaTwo('[note]','[/note]')}, false)
  85. }
  86. $('#'+prev).prev().before(btnTemplate.replace(/ID_HERE/g, 'spoiler').replace(/TEXT_HERE/g, 'spoiler'))
  87. document.getElementById('spoiler').addEventListener('click', function(){editTextareaTwo('[spoiler]','[/spoiler]')}, false)
  88. $('#'+prev).before(btnTemplate.replace(/ID_HERE/g, 'strikethrough').replace(/TEXT_HERE/g, '<s>S</s>'))
  89. document.getElementById('strikethrough').addEventListener('click', function(){editTextareaTwo('[s]','[/s]')}, false)
  90. if (document.URL.indexOf("~") < 0 && document.URL.indexOf("/list/") < 0) {
  91. $('#'+prev).before('<select name="colour" id="colour_box">')
  92. $('#'+prev).before(btnTemplate.replace(/ID_HERE/g, 'colours').replace(/TEXT_HERE/g, 'colours'))
  93. document.getElementById('colours').addEventListener('click', function(){editTextareaTwo('[color '+$('#colour_box').val()+']', '[/color]')}, false)
  94. var colours = ['red', 'green', 'blue', 'purple', 'pink', 'skyblue'];
  95. $.each(colours, function(){$('#colour_box').append('<option value="'+this+'">'+this+'</option>')})
  96. $('#'+prev).before(btnTemplate.replace(/ID_HERE/g, 'rand_wi').replace(/TEXT_HERE/g, 'random wi: code')+'<br>')
  97. document.getElementById('rand_wi').addEventListener('click', function(){editTextareaTwo('', '[wi:' + Math.random().toString(36).replace(/[^a-z]+/g, '') + ']')}, false)
  98. }
  99. }
  100. }
  101. // FOR LISTS
  102. if (document.URL.indexOf("/new_item") >= 0) {
  103. var previewButton = '<a href="javascript:void(0);" class="ratingbutton"';
  104. previewButton += ' onclick="previewO(\'item_description\')";>preview</a>';
  105. $("#item_description").prev().before(previewButton)
  106. var previewArea = '<br><br><span style="font-size: large; font-weight: bold;">Preview</span>';
  107. previewArea += '<div style="padding:20px;border:#aaa 1px solid;"id="item_description_preview"></div>';
  108. $('#list_new_item_btn').after(previewArea)
  109. }
  110. // PM'S
  111. if (document.URL.indexOf("rateyourmusic.com/messages/compose?") >= 0) {
  112. body = document.getElementById("body");
  113. body.parentNode.insertBefore(document.createElement('br'), body.previousSibling);
  114. }
  115. // COLLECTION BUTTONS
  116. else if (document.URL.indexOf("rateyourmusic.com/collection/") >= 0) {
  117. banner = document.getElementById('breadcrumb');
  118. if (banner) {
  119. var relTypes = [['bootlegs','typb'],['videos','typd'],['compilations','typc'],['eps','type'],['singles','typi'],['albums','typs']];
  120. var btnTemplate = '<a id="TYPEBtn" href="javascript:void(0);" class="printbutton" title="limit to TYPE only">TYPE</a>';
  121. //var btnTemplate = '<a id="TYPEBtn" href="javascript:void(0);" class="printbutton" title="limit to TYPE only">TYPE</a>';
  122. $.each(relTypes, function() {
  123. var rlsTypes = ["typi", "type", "typs", "typd", "typb", "typc"];
  124. var x = window.location.toString().split('/');
  125. for (var i = 0, j = rlsTypes.length; i < j; i++) {
  126. if (x[5].indexOf(rlsTypes[i]) >= 0) {
  127. x[5] = x[5].replace(rlsTypes[i], this[1]);
  128. break;
  129. }
  130. }
  131. if (x[5].indexOf(this[1]) < 0) {x[5] = x[5] + ',' + this[1]}
  132. if (!isNaN(x[6])) {if (parseInt(x[6]).length == x[6].length) {x[6] = ''}}
  133. if (!isNaN(x[7])) {if (parseInt(x[7]).length == x[7].length) {x[7] = '1'}}
  134. x = x.join("/");
  135. $('#breadcrumb').after(btnTemplate.replace(/TYPE/g, this[0], 3));
  136. $("#"+this[0]+'Btn').attr('href',x)
  137. //$("#"+this[0]+'Btn').bind('click', (function(n) {return function (e) {changeCollectionView(n)}})(this[1]), false);
  138. });
  139. }
  140. }