Skip to content

Instantly share code, notes, and snippets.

@cuylerstuwe
Last active June 23, 2019 20:35
Show Gist options
  • Save cuylerstuwe/6c8f4b5aef3a351bc52fb96a73059184 to your computer and use it in GitHub Desktop.
Save cuylerstuwe/6c8f4b5aef3a351bc52fb96a73059184 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Perch Kitchen - No Means No
// @namespace salembeats
// @version 1.61
// @description .
// @author Cuyler Stuwe (salembeats)
// @include https://www.mturkcontent.com/dynamic/hit?*
// ==/UserScript==
const GIDS = [
"305NBF6GLTENU5EKFS5DSMB0VVBDRL", // Kitchen
"3BG0QG8YP9VPQS8JULA7YQY5PSPCSG" // Backyards
];
const VALUE_FOR_LIKE_ITEMS = "no_photos";
const inputStates = {
newer: [...document.querySelectorAll("input")].map(inp => inp.checked),
older: []
};
function store() {
inputStates.older = [...inputStates.newer];
inputStates.newer = [...document.querySelectorAll("input")].map(inp => inp.checked);
}
function rewind() {
const allInputs = [...document.querySelectorAll("input")];
inputStates.older.forEach((state, idx) => {
allInputs[idx].checked = state;
});
}
(function main() {
const gidFromUrl = (document.referrer.match(/worker\.mturk\.com\/projects\/([^/]*)/) || ["", ""])[1];
if(!GIDS.includes(gidFromUrl)) { return; }
document.body.addEventListener("change", e => {
store();
});
document.body.addEventListener("click", e => {
const {target} = e;
if(target.value && target.value === VALUE_FOR_LIKE_ITEMS) {
[...document.querySelectorAll(`[value='${VALUE_FOR_LIKE_ITEMS}']`)].forEach(el => el.checked = true);
[...document.querySelectorAll(`input[type='checkbox']:not([value^='no_'])`)].forEach(el => el.checked = false);
}
});
document.body.addEventListener("keyup", e => {
if(e.key.toLowerCase() === "z") {
rewind();
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment