Additional buttons for Lists, Posts and PMs

adds buttons

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

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