Created
April 30, 2018 19:47
-
-
Save cuylerstuwe/7167e85e0c00ea1099c48bd6695b85cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Tax Engine Custom Personal Fork Hack | |
| // @namespace salembeats | |
| // @version 1.3 | |
| // @description New: / to return HIT. | |
| // @author Cuyler Stuwe (salembeats) | |
| // @include *mturkcontent.com* | |
| // @grant GM_info | |
| // @grant GM_xmlhttpRequest | |
| // @connect * | |
| // @require https://greasyfork.org/scripts/33041-mturk-frame-ggparent-interface-library/code/mTurk%20Frame-%3EParent%20Interface%20Library.js?version=239183 | |
| // ==/UserScript== | |
| const NUMBER_OF_LABELS_ON_TAX_ENGINE_HIT = 4; | |
| const TAX_ENGINE_SANITY_STRING = "choose a category:"; | |
| const DEBUG_ALWAYS_PASS_SANITY_CHECK = false; | |
| const DEBUG_RUN_IN_TOP_FRAME = false; | |
| if(!passSanityCheck()) {return;} | |
| const KEYCODE_ENTER = 13; | |
| var npeDiv; | |
| var npeIframe; | |
| document.querySelectorAll(".well").forEach((well, index) => { | |
| if( false /* || index === 1 */) { | |
| well.insertAdjacentHTML("afterend", ` | |
| <div><h1>Title: <span id="amzProductTitle"></span></h1></div> | |
| `); | |
| } | |
| well.style.display = "none"; | |
| }); | |
| document.querySelector("#CategoryInputs").parentElement.style = "position: fixed; right: 0px;"; | |
| function isInMturkIframe() { | |
| if(DEBUG_RUN_IN_TOP_FRAME) {console.log("DEBUG_RUN_IN_TOP_FRAME"); return true;} | |
| return (window !== window.top) && (document.referrer.includes("mturk")); | |
| //return ( window !== window.top && (document.referrer.includes("mturk.com/mturk/preview") || document.referrer.includes("mturk.com/mturk/accept") || document.referrer.includes("mturk.com/mturk/continue") || document.referrer.includes("mturk.com/mturk/return") || document.referrer.includes("mturk.com/mturk/previewandaccept") || document.referrer.includes("worker.mturk.com/projects/"))); | |
| } | |
| if (!isInMturkIframe()) {console.log("isInMturkIframe() === false"); return;} | |
| function passSanityCheck() { | |
| if(DEBUG_ALWAYS_PASS_SANITY_CHECK) {console.log("DEBUG_ALWAYS_PASS_SANITY_CHECK"); return true;} | |
| return ((document.querySelector("label.group-label") || {innerText: ""}).innerText.trim().toLowerCase().includes(TAX_ENGINE_SANITY_STRING)); | |
| } | |
| function runOnStart() { | |
| document.body.addEventListener("keydown", function(e) { | |
| if(e.key === "/") { | |
| mTurkParentWindow.returnHIT(); | |
| } | |
| if(e.keyCode === KEYCODE_ENTER) { | |
| document.querySelector("#submitButton").click(); | |
| } | |
| if(Number.isInteger(Number(e.key))) { | |
| let allRadios = document.querySelectorAll("input[type='radio']"); | |
| let radioIndexToClick = Number(e.key) - 1; | |
| if(radioIndexToClick < allRadios.length) { | |
| allRadios[radioIndexToClick].click(); | |
| document.querySelectorAll("#submitButton")[0].click(); | |
| } | |
| } | |
| }); | |
| window.addEventListener("message", function(event) { | |
| if(event.data.keypress) { | |
| // alert('keypress code is ' + event.data.keypress.keyCode); | |
| var newKeydownMessage = new KeyboardEvent("keydown", {key: event.data.keypress.key, | |
| keyCode: event.data.keypress.keyCode, | |
| which: event.data.keypress.which, | |
| code: event.data.keypress.code | |
| }); | |
| document.body.dispatchEvent(newKeydownMessage); | |
| } | |
| }); | |
| console.log("ENTERING RUNONSTART FUNCTION"); | |
| let allLinks = document.querySelectorAll("a"); | |
| console.log("THERE ARE " + allLinks.length + " links"); | |
| let productLink; | |
| for(let curLink of allLinks) { | |
| if(curLink.href.includes("amazon")) { | |
| productLink = curLink; | |
| break; | |
| } | |
| } | |
| let productLinkHref = productLink.getAttribute("href"); | |
| console.log("WE PICKED THE LINK WITH HREF " + productLinkHref); | |
| npeIframe = document.createElement("IFRAME"); | |
| npeIframe.setAttribute("src", productLinkHref.replace("http://", "https://")); | |
| npeIframe.setAttribute("width","100%"); | |
| npeIframe.setAttribute("height","800px"); | |
| document.body.insertAdjacentElement("beforeend", npeIframe); | |
| /* | |
| GM_xmlhttpRequest({ | |
| method: "GET", | |
| url: productLinkHref.toLowerCase(), | |
| onload: function(response) { | |
| console.log("ENTERING XML ONLOAD"); | |
| // npeDiv = document.createElement('DIV'); | |
| // npeDiv.innerHTML = response.responseText; | |
| // document.body.insertAdjacentElement('beforeend', npeDiv); | |
| } | |
| }); | |
| */ | |
| productLink.addEventListener("click", function prodLinkClick(event) { | |
| if(npeDiv) { | |
| if(npeIframe) { | |
| } | |
| else { | |
| event.preventDefault(); | |
| npeDiv.style.display = "none"; | |
| // npeIframe = document.createElement("IFRAME"); | |
| // npeIframe.setAttribute("src", productLinkHref.replace("http://", "https://")); | |
| // npeIframe.setAttribute("width","100%"); | |
| // npeIframe.setAttribute("height","800px"); | |
| // document.body.insertAdjacentElement("beforeend", npeIframe); | |
| } | |
| } | |
| else { | |
| if(!npeIframe) { | |
| event.preventDefault(); | |
| } | |
| } | |
| }); | |
| } | |
| (function main() { | |
| console.log("ENTERING MAIN FUNCTION"); | |
| if(!passSanityCheck()) { | |
| console.log(`FAILED SANITY CHECK: ${GM_info.script.name}`); | |
| return; | |
| } | |
| else { | |
| console.log(`PASSED SANITY CHECK: ${GM_info.script.name}`); | |
| } | |
| runOnStart(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment