Advertisement
clikengle

FFN Floaty Review Box Script

Feb 18th, 2017
7,581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.59 KB | None | 0 0
  1. // ==UserScript==
  2. // @name FFN Review
  3. // @namespace saxamaphone
  4. // @version 0.1
  5. // @description Adds a floaty review box
  6. // @author You
  7. // @match https://www.fanfiction.net/s/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // From http://stackoverflow.com/a/1909997/584004
  12. (function (jQuery, undefined) {
  13. jQuery.fn.getCursorPosition = function() {
  14. var el = jQuery(this).get(0);
  15. var pos = 0;
  16. if('selectionStart' in el) {
  17. pos = el.selectionStart;
  18. } else if('selection' in document) {
  19. el.focus();
  20. var Sel = document.selection.createRange();
  21. var SelLength = document.selection.createRange().text.length;
  22. Sel.moveStart('character', -el.value.length);
  23. pos = Sel.text.length - SelLength;
  24. }
  25. return pos;
  26. };
  27. })(jQuery);
  28.  
  29. // From http://stackoverflow.com/a/841121/584004
  30. (function (jQuery, undefined) {
  31. jQuery.fn.selectRange = function(start, end) {
  32. if(end === undefined) {
  33. end = start;
  34. }
  35. return this.each(function() {
  36. if('selectionStart' in this) {
  37. this.selectionStart = start;
  38. this.selectionEnd = end;
  39. } else if(this.setSelectionRange) {
  40. this.setSelectionRange(start, end);
  41. } else if(this.createTextRange) {
  42. var range = this.createTextRange();
  43. range.collapse(true);
  44. range.moveEnd('character', end);
  45. range.moveStart('character', start);
  46. range.select();
  47. }
  48. });
  49. };
  50. })(jQuery);
  51.  
  52. jQuery(window).ready(function() {
  53. // HTML to define layout of popup box
  54. // Include x button to close box
  55. var sHtml = '<button class="btn" style="float: right; margin-top: 10px;" id="close_floaty">×</button>';
  56. // Button to insert highlighted text and for a help list
  57. sHtml += '<button class="btn" style="float: left; margin-top: 10px; margin-left: 5px;" id="insert_floaty_text">Insert</button><button style="float: left; margin-top: 10px;" class="btn" id="pop_up_review_tips">Review Tips</button>';
  58. // Textarea
  59. sHtml += '<textarea style="margin: 5px; width: 97%; height: 80%;" id="floaty_textarea"></textarea>';
  60.  
  61. // Create popup box
  62. jQuery("<div/>", {
  63. id: "reviewTextArea",
  64. width:600, // Change for dimensions
  65. height:300, // Change for dimensions
  66. css: {
  67. backgroundColor:"#ffffff",
  68. opacity: 0.85,
  69. border: "thin solid black",
  70. display: "inline-block",
  71. "padding-right": 10,
  72. position: "fixed",
  73. top: 150,
  74. right: 5,
  75. "z-index": 999
  76. },
  77. html: sHtml
  78. }).appendTo("body");
  79.  
  80. // Hide the popup box by default (comment out line below if you want it to always appear by adding // before it)
  81. jQuery('#reviewTextArea').hide();
  82.  
  83. // To close the box
  84. jQuery('#close_floaty').click(function() {
  85. jQuery('#reviewTextArea').hide();
  86. });
  87.  
  88. // Anything you type in the box gets inserted into the real comment box below
  89. jQuery('#floaty_textarea').on('input', function() {
  90. jQuery('#review_review').val(jQuery('#floaty_textarea').val());
  91. });
  92.  
  93. // Add Float review box button to the top
  94. jQuery('#profile_top .icon-heart').after('<button class=\'btn pull-right\' type=button id=\'floaty_review_box\'> Floaty Review Box</button>');
  95.  
  96. // If the above button is clicked, display the review box
  97. jQuery('#floaty_review_box').click(function() {
  98. jQuery('#reviewTextArea').show();
  99. });
  100.  
  101. // Insert highlighted/selected text into textarea when Insert button is clicked
  102. jQuery('#insert_floaty_text').click(function() {
  103. var sInitialText = jQuery('#floaty_textarea').val();
  104. var iPosition = jQuery('#floaty_textarea').getCursorPosition();
  105.  
  106. var sHighlightedText = window.getSelection().toString();
  107.  
  108. var sNewText = sInitialText.substr(0, iPosition) + '<i>"' + sHighlightedText + '"</i>\n' + sInitialText.substr(iPosition);
  109. jQuery('#floaty_textarea').val(sNewText);
  110. jQuery('#floaty_textarea').focus();
  111. jQuery('#floaty_textarea').selectRange(iPosition+sHighlightedText.length+10);
  112.  
  113. // Copy into real comment box
  114. jQuery('#review_review').val(jQuery('#floaty_textarea').val());
  115. });
  116.  
  117. // Create the review tips box
  118. sReviewTipsHtml = '<button class="btn" aria-label="cancel" style="float: right;" id="close_review_tips">×</button>' +
  119. 'Writers will love any love you give them. If you&#39;re looking for things to help jumpstart a review, there are lots of different things you could focus on.<br />' +
  120. '<ul><li style="margin-left: 2em; text-indent: -2em;">Quotes you liked</li>'+
  121. '<li style="margin-left: 2em; text-indent: -2em;">Scenes you liked</li>' +
  122. '<li style="margin-left: 2em; text-indent: -2em;">What&#39;s your feeling at the end of the chapter (did it move you?)</li>' +
  123. '<li style="margin-left: 2em; text-indent: -2em;">What are you most looking forward to next?</li>' +
  124. '<li style="margin-left: 2em; text-indent: -2em;">Do you have any predictions for the next chapters you want to share?</li>' +
  125. '<li style="margin-left: 2em; text-indent: -2em;">Did this chapter give you any questions you can&#39;t wait to find out the answers for?</li>' +
  126. '<li style="margin-left: 2em; text-indent: -2em;">How would you describe the fic to a friend if you were recommending it?</li>' +
  127. '<li style="margin-left: 2em; text-indent: -2em;">Is there something unique about the story that you like?</li>' +
  128. '<li style="margin-left: 2em; text-indent: -2em;">Does the author have a style that really works for you?</li>' +
  129. '<li style="margin-left: 2em; text-indent: -2em;">Did the author leave any comments in the notes that said what they wanted feedback on?</li>' +
  130. '<li style="margin-left: 2em; text-indent: -2em;">Even if all you have are &quot;incoherent screams of delight&quot;, and can&#39;t come up with a real comment at the moment, authors love to hear that as well</li></ul>';
  131. jQuery("<div/>", {
  132. id: "reviewTips",
  133. width:600, // Change for dimensions
  134. height:300, // Change for dimensions
  135. css: {
  136. backgroundColor:"#ffffff",
  137. border: "thin solid black",
  138. padding: '10px 10px 0 10px',
  139. position: "fixed",
  140. top: 150,
  141. right: 620,
  142. "z-index": 999
  143. },
  144. html: sReviewTipsHtml
  145. }).appendTo("body");
  146. jQuery('#reviewTips li').css('list-style', 'circle inside none');
  147. jQuery('#reviewTips').hide();
  148.  
  149. // Pop up list of review tips
  150. jQuery('#pop_up_review_tips').click(function() {
  151. jQuery('#reviewTips').show();
  152. });
  153.  
  154. jQuery('#close_review_tips').click(function() {
  155. jQuery('#reviewTips').hide();
  156. });
  157.  
  158. // Enable text selection
  159. var sStyles='*,p,div{user-select:text !important;-moz-user-select:text !important;-webkit-user-select:text !important;}';
  160. jQuery('head').append(jQuery('<style />').html(sStyles));
  161. var allowNormal=function(){
  162. return true;
  163. };
  164. jQuery('*[onselectstart], *[ondragstart], *[oncontextmenu], #songLyricsDiv').unbind('contextmenu').unbind('selectstart').unbind('dragstart').unbind('mousedown').unbind('mouseup').unbind('click').attr('onselectstart',allowNormal).attr('oncontextmenu',allowNormal).attr('ondragstart',allowNormal);
  165.  
  166. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement