Skip to content

Instantly share code, notes, and snippets.

@brandonhellman
Last active April 9, 2017 19:33
Show Gist options
  • Save brandonhellman/65b51be30f631e99e01a537d469c4c6d to your computer and use it in GitHub Desktop.
Save brandonhellman/65b51be30f631e99e01a537d469c4c6d to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name HIT Export Mod for HIT Catcher
// @namespace https://gist.github.com/Kadauchi
// @version 1.0.1
// @description Adds panda and once links to HIT exports
// @author Kadauchi
// @icon http://i.imgur.com/oGRQwPN.png
// @include https://turkerhub.com/threads/*
// @include http://www.mturkcrowd.com/threads/*
// ==/UserScript==
const extId = `gknfnjfbnepfmhkkaoiknnjdhjnhlhbk`;
function addButtons (elem) {
const key = elem.querySelector(`a[href^="https://www.mturk.com/mturk/preview?groupId="]`).getAttribute(`href`).match(/roupId=(.*)/)[1];
elem.insertAdjacentHTML(
`afterbegin`,
`<div>
HC :
<button data-key="${key}" type="button" class="HIT-Catcher-Panda">Panda</button>
<button data-key="${key}" type="button" class="HIT-Catcher-Once">Once</button>
</div>`
);
}
function sendToHC (once, hitSetId) {
chrome.runtime.sendMessage(extId, {
type: `hitCatcherAddWatcher`,
message: {
nickname: null,
once: once,
sound: true,
requesterName: null,
requesterId: null,
title: null,
hitSetId: hitSetId,
reward: null,
assignmentDuration: null,
hitRequirements: null,
hitAutoAppDelay: null
}
});
}
function nom (elem) {
if (document.URL.match(`turkerhub`)) {
elem.closest(`li[id^="post-"]`).querySelector(`img[src="styles/dark/ratings/panda.png"]`).click();
}
}
for (let elem of document.getElementsByClassName(`ctaBbcodeTable`)) {
if (elem.querySelector(`a[href^="https://www.mturk.com/mturk/preview?groupId="]`)) addButtons(elem);
}
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
for (let i = 0; i < mutation.addedNodes.length; i++) {
const added = mutation.addedNodes[i];
for (let elem of added.getElementsByClassName(`ctaBbcodeTable`)) {
if (elem.querySelector(`a[href^="https://www.mturk.com/mturk/preview?groupId="]`)) addButtons(elem);
}
}
});
});
observer.observe(document.getElementById(`messageList`), {childList: true});
document.addEventListener(`click`, function (event) {
const elem = event.target;
if (elem.matches(`.HIT-Catcher-Panda`)) {
sendToHC(false, elem.dataset.key);
nom(elem);
}
if (elem.matches(`.HIT-Catcher-Once`)) {
sendToHC(true, elem.dataset.key);
nom(elem);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment