Last active
April 9, 2017 19:33
-
-
Save brandonhellman/65b51be30f631e99e01a537d469c4c6d to your computer and use it in GitHub Desktop.
This file contains 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 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