Procore Development helper (Mturk)

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

当前为 2014-07-16 提交的版本,查看 最新版本

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