JR zing receipt helper for mturk.com

A script for zings with buttons to make it easier to submit and allows keyboard shortcuts.

当前为 2016-06-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name JR zing receipt helper for mturk.com
  3. // @version 0.8
  4. // @namespace https://greasyfork.org/users/6406
  5. // @description A script for zings with buttons to make it easier to submit and allows keyboard shortcuts.
  6. // @author John Ramirez (JohnnyRS)
  7. // @include http*://*ibotta.com/duplicate_receipt_moderation/*
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // ==/UserScript==
  11.  
  12. // 0.6 - Added a warning when submit after option is checked. It will only warn once.
  13. // This script will hide the instructions but you can click on the instruction text to show the full
  14. // instructions again. You will see 2 buttons at the top of the receipts for easy access. If the receipts
  15. // are different then click on the first button. If they are the same then click on the second button.
  16. // Once you push a button it will fill in the bottom radio buttons and submit the hit if you checked the
  17. // checkbox called submit after. By default it will not submit after so you have to press the submit button
  18. // or press enter after the submit button gets focused. You can also use keyboard shortcuts to make it easier.
  19. // Keyboard shortcuts follow the submit after setting so be careful. Pressing n or 1 will select
  20. // the no option. Pressing y or 2 will select the yes option. Then you can press enter to submit the hit or
  21. // click the submit button if the submit after option is off.
  22. //
  23. // 0.5 - Added a setting checkbox to submit after button pressed. It is turned off by default and saved.
  24. // 0.4 - Added buttons at top. Allows keypad numbers to work. Hides the instructions at top.
  25.  
  26. var gSubmitAfter = false, gWarned = false;
  27. var gLogging = false, gDebugging = true;
  28. if (typeof console.log == 'function') gLogging = gDebugging; // Fix for browsers without console.log
  29. else gDebugging=false;
  30.  
  31. function loadSettings() {
  32. gSubmitAfter = JSON.parse(GM_getValue("JR_submitafter",gSubmitAfter));
  33. gWarned = JSON.parse(GM_getValue("JR_theWarning",gWarned));
  34. }
  35. function saveSettings() {
  36. GM_setValue("JR_submitafter",JSON.stringify(gSubmitAfter));
  37. GM_setValue("JR_theWarning",JSON.stringify(gWarned));
  38. }
  39. function createButton(theId,theValue,theName,theStyle) {
  40. var theButton = document.createElement("input");
  41. theButton.id = theId;
  42. theButton.value = theValue;
  43. theButton.type = "button";
  44. if (theName) theButton.name = theName;
  45. if (theStyle) theButton.setAttribute("style",theStyle);
  46. return theButton;
  47. }
  48. function createCheckbox(theId,theValue,theName,theStyle) {
  49. var theCheckbox = document.createElement("input");
  50. theCheckbox.id = theId;
  51. theCheckbox.value = theValue;
  52. theCheckbox.type = "checkbox";
  53. if (theName) theCheckbox.name = theName;
  54. if (theStyle) theCheckbox.setAttribute("style",theStyle);
  55. return theCheckbox;
  56. }
  57. function createMyElement(elementName,theClass,theId,theStyle) {
  58. var theElement = document.createElement(elementName);
  59. if (theId) theElement.id = theId;
  60. if (theClass) theElement.className = theClass;
  61. if (theStyle) theElement.setAttribute("style",theStyle);
  62. return theElement;
  63. }
  64. function searchInnerText(node,theText) {
  65. return node.innerHTML.indexOf(theText);
  66. }
  67. function searchInClass(theClass,theIndex,theText) {
  68. var classNode = document.getElementsByClassName(theClass)[theIndex];
  69. if (typeof classNode !== 'undefined') {
  70. var retVal = searchInnerText(classNode,theText);
  71. return (retVal!=-1) ? classNode.innerHTML.substr(retVal) : retVal;
  72. }
  73. }
  74. function toggleInstructions(theDiv) {
  75. arguments.callee.hiddenToggle = arguments.callee.hiddenToggle || false;
  76. arguments.callee.hiddenToggle = !arguments.callee.hiddenToggle;
  77. theDiv.style.overflow="hidden";
  78. if (arguments.callee.hiddenToggle) {
  79. theDiv.style.height="25px";
  80. } else {
  81. theDiv.style.height="auto";
  82. }
  83. }
  84. function moveInDiv(theNode,nodeNumbers) {
  85. var removedNode = null;
  86. var myDiv = createMyElement("div","theInstructions");
  87. var myH1 = createMyElement("h1","toggleMe");
  88. myH1.appendChild(document.createTextNode("Click here to show/hide instructions!"));
  89. myH1.setAttribute("style","color:blue;");
  90. myDiv.appendChild(myH1);
  91. for (var i=0; i<nodeNumbers+1; i++) {
  92. removedNode = theNode.removeChild(theNode.children[0]);
  93. myDiv.appendChild(removedNode);
  94. }
  95. return myDiv;
  96. }
  97. function answerRadio(theRadio,submitButton,submitMe) {
  98. window.scrollTo(0,document.body.scrollHeight +20);
  99. theRadio.checked=true;
  100. if (submitMe) submitButton.click(); // Only when one of my buttons are pressed.
  101. else submitButton.focus(); // Only gives focus to the submit button and will not auto submit it for pressing keys.
  102. }
  103.  
  104. $(function() {
  105. if (searchInClass("warning",0,"ATTENTION: We are actively monitoring quality. Workers who repeatedly ignore the instructions")) {
  106. if (gDebugging && gLogging) console.log(".found a zing I can work with");
  107.  
  108. var container = document.getElementsByClassName("container")[1];
  109. var instructions = moveInDiv(container,5);
  110. container.insertBefore(instructions,container.firstChild);
  111.  
  112. var noDuplicates = document.getElementById("duplicatefalse");
  113. var yesDuplicates = document.getElementById("duplicatetrue");
  114. var submitButton = document.getElementsByClassName("submitctrl")[0].getElementsByClassName("btn")[0];
  115.  
  116. var receipts = document.getElementsByClassName("row")[1];
  117. var liNodes = document.getElementsByTagName("li");
  118. var noBtn = createButton("noButton","No - DIFFERENT receipts (n) (1)","","margin-left: 25px; padding: 2px 40px;");
  119. var yesBtn = createButton("yesButton","Yes - Same receipts (y) (2)","","margin-left: 25px; padding: 2px 40px;");
  120. noBtn.onclick = function() { answerRadio(noDuplicates,submitButton,gSubmitAfter); };
  121. yesBtn.onclick = function() { answerRadio(yesDuplicates,submitButton,gSubmitAfter); };
  122.  
  123. var myDiv = createMyElement("div","row","","padding:10px 0 20px 0; text-align:center;");
  124. var myCheckbox = createCheckbox("mySubmitAfter","Submit After","mySubmitAfter","margin:0 5px 0 20px;");
  125. myDiv.appendChild(noBtn);
  126. myDiv.appendChild(yesBtn);
  127. myDiv.appendChild(myCheckbox);
  128. myDiv.appendChild(document.createTextNode('Submit after'));
  129. receipts.parentNode.insertBefore(myDiv, receipts);
  130.  
  131. var theDivInstructions = document.getElementsByClassName("theInstructions")[0];
  132. toggleInstructions(theDivInstructions);
  133. theDivInstructions.onclick = function() { toggleInstructions(theDivInstructions); };
  134.  
  135. loadSettings();
  136. myCheckbox.checked = gSubmitAfter;
  137. myCheckbox.onchange = function() {
  138. if (myCheckbox.checked) {
  139. var gConfirmed = true;
  140. if (!gWarned) gConfirmed = confirm("Warning: This option will submit the hit after pressing a button or using a keyboard shortcut. Be careful.\nYou can turn this option off at any time to verify your answer is correct. This is your only warning.");
  141. if (gConfirmed) { gSubmitAfter = true; gWarned = true; }
  142. else myCheckbox.checked = false;
  143. } else gSubmitAfter = false;
  144. saveSettings();
  145. };
  146. $("#noButton").focus();
  147. $(document).keydown(function (e) {
  148. if (e.which == 78 || e.which == 49 || e.which == 97) { // n=(78) or 1=(49)(97) pressed
  149. answerRadio(noDuplicates,submitButton,gSubmitAfter);
  150. } else if (e.which == 89 || e.which == 50 || e.which == 98) { // y=(89) or 2=(50)(98) pressed
  151. answerRadio(yesDuplicates,submitButton,gSubmitAfter);
  152. }
  153. });
  154. }
  155. });