Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ocmp5 - jdzane special
- // @version 2.1
- // @description $$$!
- // @author slothbear
- // @icon http://i.imgur.com/yptTSAh.gif
- // @include https://wml1.crowdcomputingsystems.com/*
- // ==/UserScript==
- //
- // LINK FOR TESTING PURPOSES:
- // https://wml1.crowdcomputingsystems.com/workfusion/public/HTMLRenderer?submissionUUID=f1e8d294-2fbc-4af7-a2bd-5c6f97c3fb77&assignmentId=ASSIGNMENT_ID_NOT_AVAILABLE&hitId=3DWNFENNE35BUNDJP2X01FNU0274JS#
- //
- //OPTIONS
- const MOST_PROBABLE_VALUE = 1; //this is which value gets autoselected
- const CLICK_MOST_PROBABLE = true;
- const HIGHLIGHT_MOST_PROBABLE = true;
- const HIDE_ANSWERED_OR_SKIPPED = true;
- const LARGE_ANSWER_TEXT = true;
- const AUTOSUBMIT_AFTER_FINAL_ANSWER = false; //if false, enter to submit
- //ONLY SET ONE OR NEITHER OF THE SEARCHES TO TRUE
- //OR ELSE THEY WILL BOTH OPEN
- const SEARCH_IN_NEW_TAB = true;
- const SEARCH_IN_NEW_WINDOW = false;
- //SELECTION IS SET TO 1-4
- //YOU CAN SET THESE SPECIAL KEYS THOUGH
- //PUT KEY IN QUOTES ('.' FOR dot, 'Enter' for enter, etc...)
- const PRODUCT_SEARCH_KEY = '+';
- const SKIP_QUESTION_KEY = 'Enter';
- const PREVIOUS_QUESTION_KEY = '8';
- //END OF OPTIONS
- const IS_PRODUCT_TYPE_RELEVANCE = document.body.innerText.indexOf('Which Product Type is the most relevant?') > -1;
- function productTypeRelevance() {
- if (LARGE_ANSWER_TEXT) boldAnswers();
- if (CLICK_MOST_PROBABLE) clickMostProbable();
- window.focus();
- var counter = 0;
- var radios = document.querySelectorAll('[type="radio"]');
- var productSearchWindow;
- document.addEventListener("keydown", function(e) {
- if (e.key.match(/[1-4]/)) { //select option
- let choice = parseInt(e.key) - 1;
- radios[(counter * 4) + choice].click();
- hideAnswered(counter);
- counter++;
- closeSearchWindow(productSearchWindow);
- }
- if (e.key === SKIP_QUESTION_KEY) { //skip question
- hideAnswered(counter);
- counter++;
- closeSearchWindow(productSearchWindow);
- if (!AUTOSUBMIT_AFTER_FINAL_ANSWER) autosubmitCheck(counter - 1);
- }
- if (e.key === '8') {
- counter--;
- goBack(counter);
- }
- if (e.key === PRODUCT_SEARCH_KEY) productSearchWindow = productSearch(counter);
- if (AUTOSUBMIT_AFTER_FINAL_ANSWER) autosubmitCheck(counter); //submit if both question have been dealt with
- });
- }
- function boldAnswers() {
- let answerText = document.querySelectorAll('.hotkey-text');
- for (var i = 0; i < answerText.length; i++) {
- let text = answerText[i];
- text.style.fontWeight = 'bold';
- text.style.fontSize = 'large';
- }
- }
- function clickMostProbable() {
- let probableRadiosArr = document.querySelectorAll(`input[value="${MOST_PROBABLE_VALUE}"]`);
- for (var i = 0; i < probableRadiosArr.length; i++) {
- probableRadiosArr[i].click();
- if (HIGHLIGHT_MOST_PROBABLE) probableRadiosArr[i].parentNode.style.backgroundColor = 'yellow';
- }
- }
- function hideAnswered(counter) {
- if (HIDE_ANSWERED_OR_SKIPPED) {//document.querySelectorAll('div.question')[counter].style.display = "none";
- let thisQuestion = document.querySelectorAll('div.question')[counter];
- if (thisQuestion) thisQuestion.style.display = "none";
- }
- }
- function goBack(counter) {
- document.querySelectorAll('div.question')[counter].style.display = "block";
- }
- function productSearch(counter) {
- let productText = document.querySelectorAll('div.bg-dark')[counter].innerText;
- productText = productText.split('Name: ')[1].trim();
- let searchLink = 'https://www.google.com/search?q=' + productText;
- if (SEARCH_IN_NEW_TAB) return window.open(searchLink);
- if (SEARCH_IN_NEW_WINDOW) return window.open(searchLink, '_blank','height=' + screen.height + ',width=' + screen.width);
- }
- function closeSearchWindow(win) {
- if (win) win.close();
- }
- function autosubmitCheck(counter) {
- if (counter < 2) return false;
- submitButton = document.querySelector('a.submit-btn');
- setTimeout(function(){submitButton.click();},100);
- }
- //THIS RUNS WHEN PAGE IS LOADED
- (function(main) {
- if (IS_PRODUCT_TYPE_RELEVANCE) productTypeRelevance();
- return false;
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement