Skip to content

Instantly share code, notes, and snippets.

@cuylerstuwe
Last active July 19, 2018 16:49
Show Gist options
  • Select an option

  • Save cuylerstuwe/cb6abf3991e5750a266ef727458dfdd3 to your computer and use it in GitHub Desktop.

Select an option

Save cuylerstuwe/cb6abf3991e5750a266ef727458dfdd3 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name 01a - New Unnamed HIT Script
// @namespace salembeats
// @version 1.32
// @description .
// @author Cuyler Stuwe (salembeats)
// @include *
// @require https://gist.github.com/salembeats/3dd0c6c765a553c1184bc1d6d075bb9a/raw/5335a3ca833e5ccb7574c3c1d7b8af2e0e96a859/mselect.library.user.js
// @require https://gist.github.com/salembeats/6f50c37f7309fe1c7632376c4e2f3a1c/raw/bce38260696278c5cb42d0d8ee5f65125511577b/maction.library.user.js
// @require https://gist.github.com/salembeats/2661fe710d1520a50cb0f8fa8b23d052/raw/d8174bc63c1c3fea038dbed542308d64375bfecb/mutil.library.user.js
// @require https://gist.github.com/salembeats/911fa615ea87bb077649adacf9436db9/raw/84d3adcf77b22766f946029fae8b0317d5ea38a4/mturk-frame-parent-interface.library.user.js
// @require https://gist.github.com/salembeats/3b5c664709dd46f41ac2d4ad740bf02b/raw/e9e666adc3cb9a5e273c4681dbbbedf115e8fc83/panda-crazy-helper-emulation.library.user.js
// @require https://gist.github.com/salembeats/31f44fcda5869fd3040b80a0d3034e04/raw/12a775370cc3b5de7c1b919f71c7ae39427335f6/salem-midi.library.user.js
// @require https://gist.github.com/salembeats/fbac8b91ae02433ad1c6af3eebe358ea/raw/03ddb55538a834825468b2175625cdaa650a1a5d/subwindow.library.user.js
// @require https://gist.github.com/salembeats/0fabf74493df13a3200cc604ae4e31c3/raw/4e0b9f5d36a010b1a8f43010cc013c1201c54760/salem-crosshair-library.user.js
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_deleteValue
// @grant GM_openInTab
// @grant GM_addValueChangeListener
// @grant GM_removeValueChangeListener
// @grant GM_getTab
// @grant GM_saveTab
// @grant GM_getTabs
// @grant GM_download
// @grant GM_addStyle
// @grant GM_getResourceText
// @grant GM_getResourceURL
// @grant unsafeWindow
// @grant GM_notification
// @grant GM_setClipboard
// @connect worker.mturk.com
// @connect mturk.com
// ==/UserScript==
const globals = {
SCRIPT_SETTINGS: {
GID: "", // TODO: If you want this script to target only one GID, place that 30-character GID inside the quotes.
SHOULD_USE_VERBOSE_LOGGING: true, // TODO: If you want this script to log debug messages, set this to true and use MU.debug(messageContents) to log.
DEFAULT_SCRIPT_NAME: "01a - New Unnamed HIT Script"
},
SCRIPT_INFO: {
NAME: GM_info.script.name,
URL: window.location.href
},
};
//================================================================================================================================================
MU.setDebugLevel(globals.SCRIPT_SETTINGS.SHOULD_USE_VERBOSE_LOGGING);
const trimmedGid = globals.SCRIPT_SETTINGS.GID.trim();
if(!MU.isMturkHit(trimmedGid)) {
if(window === window.top) {
}
else {
MU.failure(`Script [ ${globals.SCRIPT_INFO.NAME} ] failed sanity check on URL [ ${globals.SCRIPT_INFO.URL} ] and will not start.`);
if(trimmedGid && trimmedGid.length !== 30) {
MU.failure(`Possible failure reason: Provided GID [ ${globals.SCRIPT_SETTINGS.GID} ] is incorrectly formatted ( ${trimmedGid.length} characters instead of 30 ). Check to make sure you pasted the entire 30-character GID, starting with a 3, and ensure there are no non-alphanumeric characters or other characters added.`);
}
}
return;
}
MU.success( `Script [ ${globals.SCRIPT_INFO.NAME} ] is active on URL [ ${globals.SCRIPT_INFO.URL} ] with verbose logging enabled.` );
if(globals.SCRIPT_INFO.NAME === globals.SCRIPT_SETTINGS.DEFAULT_SCRIPT_NAME) {
MU.warning(`An mTurk script is running using the default template name ( ${globals.SCRIPT_SETTINGS.DEFAULT_SCRIPT_NAME} ). Rename it to stay organized.`);
}
//================================================================================================================================================
async function main() {
// TODO: Start writing your code in this entry point.
// Code that reaches this point is guaranteed to be:
// - In an mTurk iFrame,
// - Running only on iFrames of the specified GID (if set).
// - Either accepted or not accepted.
// EXAMPLE:
// This will notify the Turker that the HIT has been opened, and inform him/her of its total value.
// mTurkParentWindow.runOnParentParametersKnown(() => {
// GM_notification(`Starting a new HIT worth $${ mTurkParentWindow.getHitValueAsDollars().toFixed(2) }`);
// });
}
async function acceptedMain() {
// TODO: Start writing any code that applies only to accepted HITs in this entry point.
// Code that reaches this point is guaranteed to be:
// - In an mTurk iFrame,
// - Running only on iFrames of the specified GID (if set).
// - Accepted.
// EXAMPLE:
// This will return an accepted HIT and accept another from the same GID.
// mTurkParentWindow.runOnParentParametersKnown(() => {
// mTurkParentWindow.rotateDifferentHitFromSameGid();
// });
}
async function notAcceptedMain() {
// TODO: Start writing any code that applies only to not-yet-accepted HITs in this entry point.
// Code that reaches this point is guaranteed to be:
// - In an mTurk iFrame,
// - Running only on iFrames of the specified GID (if set).
// - Not accepted.
// EXAMPLE:
// This will accept a HIT if it is being previewed (in a "non-accepted" state).
// mTurkParentWindow.runOnParentParametersKnown(() => {
// mTurkParentWindow.acceptHit();
// });
}
//================================================================================================================================================
main();
if(MU.isHitAccepted()) {
acceptedMain();
}
else {
notAcceptedMain();
}
//================================================================================================================================================
/*
==================================================================================================================================================
Template Quickstart
==================================================================================================================================================
NOTE: The question mark (?) before a parameters means that parameter is optional.
M$ ("MTurk $electors")
.$(selector)
Selects the first element that matches the CSS selector. Alias for document.querySelector(selector).
.$$(selector)
Selects all elements that match the CSS selector. Alias for document.querySelectorAll(selector).
.$$$(selector)
Selects all elements on the page. Alias for document.querySelectorAll("*").
.$text(selector, text, ?options)
Selects the first element that matches a given CSS selector and contains the given text.
.$$aText(selector, text, ?options)
Returns an array which contains all elements matching a given CSS selector and given text.
.$rads()
Selects all radio buttons. Alias for document.querySelectorAll("input[type='radio']").
.$sub()
Selects the submit button - first by input type, and then by ID as a fallback.
.$0()
Selects the last-clicked element.
MA ("MTurk Actions")
.click(element)
If the element exists, it will be clicked.
.hide(element)
If the element exists, it will be hidden.
.show(element)
If the element exists, it will be shown.
.remove(element)
If the element exists, it will be removed.
.text(element, ?options)
If the element exists, this method will either: A) Set the text and return the element, or B) Return the text inside the element.
options: string | object
If options is a string, the selected element will have its text changed to that string.
Otherwise, the options have the following effect:
{
lowercase|lower|l: If set to true, the text is set or returned as lowercase.
text: If set, this will be used as the string to set the element's text to.
}
MU ("MTurk Utilities")
.$wait(selector, ?pollRate)
Returns a Promise that polls the page for a selector and ultimately returns the first element selected by that selector as soon as it is found.
Example Usage:
MU.$wait(".alert-this-text-on-insert").then( insertedElement => alert( insertedElement.innerText ) );
==================================================================================================================================================
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment