Selective Quote - Idea by Vegas

Only quote the text selected by your cursor.

  1. // ==UserScript==
  2. // @name Selective Quote - Idea by Vegas
  3. // @author Hash G.
  4. // @description Only quote the text selected by your cursor.
  5. // @namespace HF
  6. // @include *hackforums.net/showthread.php?tid=*
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
  8. // @version 0.23
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // ==/UserScript==
  12.  
  13. window.onload = function() {
  14. settings = GM_getValue("settings", 0);
  15. $(".post_management_buttons.float_right").each(function(e) {
  16. $(this).prepend("<a class='bitButton' data-nb="+e+" title='Quote selected text' href='javascript:void(0);' rel='nofollow' id='selectiveQuote'>Quote selected text</a> ");
  17. });
  18. $("body").append("<div id='popup_SQSettings' style='background-color: #333333; bottom: auto; border: 1px solid rgb(0, 0, 0); height: 20%; left: 182px; margin: 0px; max-height: 95%; max-width: 95%; opacity: 1; padding: 0px; position: fixed; right: auto; top: 128px; width: 75%; display: none;'><h4>Selective Quote Settings</h4><br><input type='radio' data-input='0' name='settings'>Open in a new tab<br><input type='radio' data-input='1' name='settings'>Add to your message<br><input type='radio' data-input='2' name='settings'>Add to your message and scroll<br><br><button class='bitButton' id='SQClose'>Close</button> <button class='bitButton' id='SQSaveSettings'>Save</button></div>");
  19. $(".post_management_buttons.float_right a[title*='Quote selected']").on("click", function() {
  20. quote = parseText(getSelectionText());
  21. if (quote === "" || quote.length == 0 || !quote) {
  22. callSettings(settings);
  23. } else {
  24. name = $(this).parent().parent().parent().parent().find(".post_author strong span[class*='group']").html();
  25. pid = $(this).parent().find("a[href*='newreply.php?tid=']").attr("href").substr(33);
  26. if (settings == 0) {
  27. $("#message").html("[quote="+name+" pid="+pid+"]\n"+quote+"\n\n[/quote]");
  28. $("#quick_reply_form").attr("target", "_blank");
  29. $("input.button:nth-child(2)").click();
  30. } else if (settings == 1) {
  31. $("#message").html("[quote="+name+" pid="+pid+"]\n"+quote+"\n\n[/quote]");
  32. } else if (settings == 2) {
  33. $("#message").html("[quote="+name+" pid="+pid+"]\n"+quote+"\n\n[/quote]");
  34. window.scrollTo(0,document.body.scrollHeight);
  35. }
  36. }
  37. });
  38. $("#SQClose").on("click", function() {
  39. $("#popup_SQSettings").css("display", "none");
  40. });
  41. $("#SQSaveSettings").on("click", function() {
  42. GM_setValue("settings", $("#popup_SQSettings input:checked").attr("data-input"));
  43. settings = GM_getValue("settings", 0);
  44. $("#popup_SQSettings").css("display", "none");
  45. });
  46. function getSelectionText() {
  47. var sel = unsafeWindow.getSelection();
  48. if (sel.rangeCount) {
  49. var container = document.createElement("div");
  50. for (var i = 0, len = sel.rangeCount; i < len; ++i) {
  51. container.appendChild(sel.getRangeAt(i).cloneContents());
  52. }
  53. text = container.innerHTML;
  54. }
  55. return text;
  56. }
  57. function callSettings(settings) {
  58. $("#popup_SQSettings").css("display", "block");
  59. if (settings == 0) {
  60. $("#popup_SQSettings input[data-input=0]").attr("checked", "checked");
  61. } else if (settings == 1) {
  62. $("#popup_SQSettings input[data-input=1]").attr("checked", "checked");
  63. } else if (settings == 2) {
  64. $("#popup_SQSettings input[data-input=2]").attr("checked", "checked");
  65. }
  66. }
  67. function parseText(quote) {
  68. for (var i = 0; i < 5; i++) {
  69. quote = quote.replace(/<span style="text-decoration: underline;">(.*?[\S\s]*?)<\/span>/ig, '[u]$1[/u]');
  70. quote = quote.replace(/<span style="font-weight: bold;">(.*?[\S\s]*?)<\/span>/ig, '[b]$1[/b]');
  71. quote = quote.replace(/<span style="font-style: italic;">(.*?[\S\s]*?)<\/span>/ig, '[i]$1[/i]');
  72. quote = quote.replace(/<span style="color: (.*?);">(.*?[\S\s]*?)<\/span>/ig, '[color=$1]$2[/color]');
  73. quote = quote.replace(/<div style="text-align: (.*?);">(.*?[\S\s]*?)<\/div>/ig, '[align=$1]$2[/align]');
  74. quote = quote.replace(/<ol type="1">(.*?[\S\s]*?)<\/ol>/ig, '[list=1]$1[/list]');
  75. quote = quote.replace(/<ul>(.*?[\S\s]*?)<\/ul>/ig, '[list]$1[/list]');
  76. quote = quote.replace(/<li>(.*?[\S\s]*?)<\/li>/ig, '[*]$1');
  77. quote = quote.replace('<a href="javascript:void(0);" onclick="javascript:if(parentNode.parentNode.getElementsByTagName(\'div\')[1].style.display==\'block\'){parentNode.parentNode.getElementsByTagName(\'div\')[1].style.display=\'none\';this.innerHTML=\'(Click to View)\';}else {parentNode.parentNode.getElementsByTagName(\'div\')[1].style.display=\'block\';this.innerHTML=\'(Click to Hide)\';}">(Click to Hide)<\/a>', '');
  78. quote = quote.replace(/<div><div class="spoiler_header">(.*?[\S\s]*?)<\/div><div class="spoiler_body" style="display: block;">(.*?[\S\s]*?)<\/div><\/div>/ig, '[sp=$1]$2[/sp]');
  79. quote = quote.replace(/<a href="(.*?)" target="_blank">(.*?[\S\s]*?)<\/a>/ig, '[url=$1]$2[/url]');
  80. quote = quote.replace(/<img src="(.*?)" alt="(.*?)" border="0">/ig, '[img]$1[/img]');
  81. quote = quote.replace(/<span style="font-family: (.*?);">(.*?[\S\s]*?)<\/span>/ig, '[font=$1]$2[/font]');
  82. quote = quote.replace(/<span style="font-size: (.*?);">(.*?[\S\s]*?)<\/span>/ig, '[size=$1]$2[/size]');
  83. quote = quote.replace(/<br>/ig, '');
  84. quote = quote.replace(/<hr>/ig, '[hr]');
  85. quote = quote.replace(/<hr>/ig, '[hr]');
  86. }
  87. return quote;
  88. }
  89.  
  90. }