Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. // ==UserScript==
  2. // @name ocmp5 - jdzane special
  3. // @version 2.1
  4. // @description $$$!
  5. // @author slothbear
  6. // @icon http://i.imgur.com/yptTSAh.gif
  7. // @include https://wml1.crowdcomputingsystems.com/*
  8. // ==/UserScript==
  9.  
  10. //
  11. // LINK FOR TESTING PURPOSES:
  12. // https://wml1.crowdcomputingsystems.com/workfusion/public/HTMLRenderer?submissionUUID=f1e8d294-2fbc-4af7-a2bd-5c6f97c3fb77&assignmentId=ASSIGNMENT_ID_NOT_AVAILABLE&hitId=3DWNFENNE35BUNDJP2X01FNU0274JS#
  13. //
  14.  
  15.  
  16. //OPTIONS
  17. const MOST_PROBABLE_VALUE = 1; //this is which value gets autoselected
  18. const CLICK_MOST_PROBABLE = true;
  19. const HIGHLIGHT_MOST_PROBABLE = true;
  20. const HIDE_ANSWERED_OR_SKIPPED = true;
  21. const LARGE_ANSWER_TEXT = true;
  22. const AUTOSUBMIT_AFTER_FINAL_ANSWER = false; //if false, enter to submit
  23.  
  24. //ONLY SET ONE OR NEITHER OF THE SEARCHES TO TRUE
  25. //OR ELSE THEY WILL BOTH OPEN
  26. const SEARCH_IN_NEW_TAB = true;
  27. const SEARCH_IN_NEW_WINDOW = false;
  28.  
  29. //SELECTION IS SET TO 1-4
  30. //YOU CAN SET THESE SPECIAL KEYS THOUGH
  31. //PUT KEY IN QUOTES ('.' FOR dot, 'Enter' for enter, etc...)
  32. const PRODUCT_SEARCH_KEY = '+';
  33. const SKIP_QUESTION_KEY = 'Enter';
  34. const PREVIOUS_QUESTION_KEY = '8';
  35. //END OF OPTIONS
  36.  
  37.  
  38.  
  39. const IS_PRODUCT_TYPE_RELEVANCE = document.body.innerText.indexOf('Which Product Type is the most relevant?') > -1;
  40.  
  41. function productTypeRelevance() {
  42. if (LARGE_ANSWER_TEXT) boldAnswers();
  43. if (CLICK_MOST_PROBABLE) clickMostProbable();
  44. window.focus();
  45.  
  46. var counter = 0;
  47. var radios = document.querySelectorAll('[type="radio"]');
  48. var productSearchWindow;
  49. document.addEventListener("keydown", function(e) {
  50. if (e.key.match(/[1-4]/)) { //select option
  51. let choice = parseInt(e.key) - 1;
  52. radios[(counter * 4) + choice].click();
  53. hideAnswered(counter);
  54. counter++;
  55. closeSearchWindow(productSearchWindow);
  56. }
  57. if (e.key === SKIP_QUESTION_KEY) { //skip question
  58. hideAnswered(counter);
  59. counter++;
  60. closeSearchWindow(productSearchWindow);
  61. if (!AUTOSUBMIT_AFTER_FINAL_ANSWER) autosubmitCheck(counter - 1);
  62. }
  63. if (e.key === '8') {
  64. counter--;
  65. goBack(counter);
  66. }
  67. if (e.key === PRODUCT_SEARCH_KEY) productSearchWindow = productSearch(counter);
  68. if (AUTOSUBMIT_AFTER_FINAL_ANSWER) autosubmitCheck(counter); //submit if both question have been dealt with
  69. });
  70. }
  71.  
  72. function boldAnswers() {
  73. let answerText = document.querySelectorAll('.hotkey-text');
  74. for (var i = 0; i < answerText.length; i++) {
  75. let text = answerText[i];
  76. text.style.fontWeight = 'bold';
  77. text.style.fontSize = 'large';
  78. }
  79. }
  80.  
  81. function clickMostProbable() {
  82. let probableRadiosArr = document.querySelectorAll(`input[value="${MOST_PROBABLE_VALUE}"]`);
  83. for (var i = 0; i < probableRadiosArr.length; i++) {
  84. probableRadiosArr[i].click();
  85. if (HIGHLIGHT_MOST_PROBABLE) probableRadiosArr[i].parentNode.style.backgroundColor = 'yellow';
  86. }
  87. }
  88.  
  89. function hideAnswered(counter) {
  90. if (HIDE_ANSWERED_OR_SKIPPED) {//document.querySelectorAll('div.question')[counter].style.display = "none";
  91. let thisQuestion = document.querySelectorAll('div.question')[counter];
  92. if (thisQuestion) thisQuestion.style.display = "none";
  93. }
  94. }
  95.  
  96. function goBack(counter) {
  97. document.querySelectorAll('div.question')[counter].style.display = "block";
  98. }
  99.  
  100. function productSearch(counter) {
  101. let productText = document.querySelectorAll('div.bg-dark')[counter].innerText;
  102. productText = productText.split('Name: ')[1].trim();
  103. let searchLink = 'https://www.google.com/search?q=' + productText;
  104. if (SEARCH_IN_NEW_TAB) return window.open(searchLink);
  105. if (SEARCH_IN_NEW_WINDOW) return window.open(searchLink, '_blank','height=' + screen.height + ',width=' + screen.width);
  106. }
  107.  
  108. function closeSearchWindow(win) {
  109. if (win) win.close();
  110. }
  111.  
  112. function autosubmitCheck(counter) {
  113. if (counter < 2) return false;
  114. submitButton = document.querySelector('a.submit-btn');
  115. setTimeout(function(){submitButton.click();},100);
  116. }
  117.  
  118.  
  119. //THIS RUNS WHEN PAGE IS LOADED
  120. (function(main) {
  121. if (IS_PRODUCT_TYPE_RELEVANCE) productTypeRelevance();
  122. return false;
  123.  
  124. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement