Procore Development helper (Mturk)

Makes it easier to do Procore Development drawing number and title HITs on Mturk.

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

  1. // ==UserScript==
  2. // @name Procore Development helper (Mturk)
  3. // @namespace https://greasyfork.org/users/3408
  4. // @author DonovanM
  5. // @description Makes it easier to do Procore Development drawing number and title HITs on Mturk.
  6. // @include https://www.procoretech.com/mechanical_turk/show_drawing_revision*
  7. // @include http://www.procoretech.com/mechanical_turk/show_drawing_revision*
  8. // @include https://get.thecurrentset.com/*
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  10. // @version 0.9.2
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. // Automatically scrolls to the bottom right on load. Whatever you type into the floating
  15. // form will be entered into the real form. Pressing enter or clicking the Done button will
  16. // bring the window back to the top with the input fields filled in (so you can preview
  17. // before you submit). Hitting Enter again will submit the hit. Use Ctrl + arrow keys to
  18. // move around the window.
  19.  
  20. var clone,
  21. currentSet = false;
  22.  
  23. $(document).ready(function() {
  24. if (document.URL.indexOf("get.thecurrentset.com") !== -1)
  25. currentSet = true;
  26.  
  27. if (!currentSet){
  28. // Stretch out the input boxes to make sure everything was typed out correctly
  29. $("#drawing_number").css('width', "500px");
  30. $("#drawing_title").css('width', "500px");
  31. } else {
  32. $("div.drawing-image").css({
  33. 'max-width': "100%",
  34. 'position': "absolute",
  35. 'right': "0",
  36. 'left': "195px",
  37. 'width': "auto",
  38. 'top': "0",
  39. 'bottom': "30px",
  40. 'height': "auto"
  41. });
  42.  
  43. $("hr").remove();
  44. }
  45.  
  46. var form = $("<form>");
  47.  
  48. // Container
  49. var div = $("<div>")
  50. .css('position', "fixed")
  51. .css('right', "0px")
  52. .css('bottom', "0px")
  53. .css('padding', "3px")
  54. .css('background-color', "rgba(160,215,255,0.75)")
  55. .css('border', "1px solid rgba(130,200,220,0.75)")
  56. .css('border-width', "1px 0 0 1px")
  57. .css('border-radius', "2px 0 0 0")
  58. .css('font', "11pt sans-serif")
  59. .append(
  60. $("<p>")
  61. .html("Drawing/sheet number: ")
  62. .append(
  63. $("<input>") // First input (drawing number)
  64. .attr('id', "clone_number")
  65. .keydown(function() { clone.number() })
  66. )
  67. )
  68. .append(
  69. $("<p>")
  70. .html("Drawing/sheet title: ")
  71. .css('margin-left', "20px")
  72. .append(
  73. $("<input>") // Second input (drawing number)
  74. .attr('id', "clone_title")
  75. .css('width', "500px")
  76. .keydown(function() { clone.title() })
  77. )
  78. .append(
  79. $("<button>") // Done button (doesn't submit, just takes you to the real sumbit button)
  80. .html("Done")
  81. .prop('type', "button")
  82. .css('margin', "0 10px 0 20px")
  83. .click(function() {
  84. $(window).scrollTop(0).scrollLeft(0);
  85. $("button[name='commit']").focus();
  86. })
  87. )
  88. )
  89.  
  90. // Add some shared styles
  91. $("p", div).css('text-align', "right").css('display', "inline");
  92. $("input", div).css('background-color', "rgba(255,255,255,0.65)").css('border', "1px solid #ddd");
  93.  
  94.  
  95. form.append(div);
  96. $("body").append(form);
  97.  
  98. $("#clone_number")[0].focus();
  99. clone = new Clone();
  100. });
  101.  
  102. $(window).load(function(e) {
  103. // Timeout needed for Chrome or it will scroll to the bottom right and quickly back to it's original position
  104. // otherwise. Not sure if a longer timeout is needed for slower computers.
  105. setTimeout(function() { Scroll.bottom(); Scroll.farRight() }, 100);
  106. });
  107.  
  108. // Clone object. Copies text from the floating form to the HIT form. Created as an object to keep references to
  109. // jQuery objects instead of doing a search on each keypress. The timeout allows the text to go into the floating
  110. // form before copying it, otherwise it'll copy before the text is actually in the input box.
  111. function Clone() {
  112. var self = this;
  113. this.numberBox = $("#drawing_number");
  114. this.titleBox = $("#drawing_title");
  115. this.numberClone = $("#clone_number");
  116. this.titleClone = $("#clone_title");
  117.  
  118. this.number = function() {
  119. setTimeout(function() {
  120. self.numberBox.val(self.numberClone.val());
  121. }, 100);
  122. }
  123.  
  124. this.title = function() {
  125. setTimeout(function() {
  126. self.titleBox.val(self.titleClone.val());
  127. }, 100);
  128. }
  129. }
  130.  
  131. $(document).keydown(function(e) {
  132. if (e.keyCode == 13) {
  133. $(window).scrollTop(0).scrollLeft(0);
  134. $("*[name='commit']").focus();
  135. } else if (e.ctrlKey) {
  136. switch (e.keyCode) {
  137. case 38: // Up
  138. Scroll.top();
  139. break;
  140. case 40: // Down
  141. Scroll.bottom();
  142. break;
  143. case 37: // Left
  144. Scroll.farLeft();
  145. break;
  146. case 39: // Right
  147. Scroll.farRight();
  148. break;
  149. }
  150. }
  151. });
  152.  
  153. var Scroll = {
  154. top: function() {
  155. if (currentSet)
  156. $("div.drawing-image").scrollTop(0);
  157. else
  158. $(window).scrollTop(0);
  159. },
  160.  
  161. bottom: function() {
  162. if (currentSet)
  163. $("div.drawing-image").scrollTop($("div.drawing-image")[0].scrollHeight);
  164. else
  165. $(window).scrollTop($(this).height());
  166. },
  167.  
  168. farLeft: function() {
  169. if (currentSet)
  170. $("div.drawing-image").scrollLeft(0);
  171. else
  172. $(window).scrollLeft(0);
  173. },
  174.  
  175. farRight: function() {
  176. if (currentSet)
  177. $("div.drawing-image").scrollLeft($("div.drawing-image")[0].scrollWidth);
  178. else
  179. $(window).scrollLeft($(document).outerWidth() - $(window).width());
  180. }
  181. }