HIT Export Mod for HIT Catcher

Adds panda and once links to HIT exports

  1. // ==UserScript==
  2. // @name HIT Export Mod for HIT Catcher
  3. // @namespace https://gist.github.com/Kadauchi
  4. // @version 1.0.4
  5. // @description Adds panda and once links to HIT exports
  6. // @author Kadauchi
  7. // @icon http://i.imgur.com/oGRQwPN.png
  8. // @include https://turkerhub.com/threads/*
  9. // @include http://www.mturkcrowd.com/threads/*
  10. // ==/UserScript==
  11.  
  12. const extId = `iglbakfobmoijpbigmlfklckogbefnlf`;
  13.  
  14. function addButtons (elem) {
  15. const key = elem.querySelector(`a[href^="https://www.mturk.com/mturk/preview?groupId="]`).getAttribute(`href`).match(/roupId=(.*)/)[1];
  16.  
  17. elem.insertAdjacentHTML(
  18. `afterbegin`,
  19. `<div>
  20. <button data-key="${key}" type="button" class="button primary HIT-Catcher-Panda">Panda</button>
  21. <button data-key="${key}" type="button" class="button primary HIT-Catcher-Once">Once</button>
  22. </div>`
  23. );
  24. }
  25.  
  26. function sendToHC (once, hitSetId) {
  27. chrome.runtime.sendMessage(extId, {
  28. type: `hitCatcherAddWatcher`,
  29. message: {
  30. nickname: null,
  31. once: once,
  32. sound: true,
  33. requesterName: null,
  34. requesterId: null,
  35. title: null,
  36. hitSetId: hitSetId,
  37. reward: null,
  38. assignmentDuration: null,
  39. hitRequirements: null,
  40. hitAutoAppDelay: null
  41. }
  42. });
  43. }
  44.  
  45. function nom (elem) {
  46. if (document.URL.match(`turkerhub`)) {
  47. const post = elem.closest(`li[id^="post-"]`);
  48. const postId = post.id.match(/[0-9]+/)[0];
  49. const quoted = elem.closest(`.quoteContainer`);
  50. const xfToken = document.querySelector(`input[name=_xfToken]`).value;
  51.  
  52. if (quoted) {
  53. const post = quoted.previousElementSibling.querySelector(`.AttributionLink`).getAttribute(`href`).match(/[0-9]+/)[0];
  54. $.post(`https://turkerhub.com/posts/${post}/rate`, {rating: `15`, _xfToken: xfToken});
  55. }
  56. else {
  57. $.post(`https://turkerhub.com/posts/${postId}/rate`, {rating: `15`, _xfToken: xfToken});
  58. }
  59. }
  60. }
  61.  
  62. for (let elem of document.getElementsByClassName(`ctaBbcodeTable`)) {
  63. if (elem.querySelector(`a[href^="https://www.mturk.com/mturk/preview?groupId="]`)) addButtons(elem);
  64. }
  65.  
  66. const observer = new MutationObserver(function (mutations) {
  67. mutations.forEach(function (mutation) {
  68. for (let i = 0; i < mutation.addedNodes.length; i++) {
  69. const added = mutation.addedNodes[i];
  70.  
  71. for (let elem of added.getElementsByClassName(`ctaBbcodeTable`)) {
  72. if (elem.querySelector(`a[href^="https://www.mturk.com/mturk/preview?groupId="]`)) addButtons(elem);
  73. }
  74. }
  75. });
  76. });
  77.  
  78. observer.observe(document.getElementById(`messageList`), {childList: true});
  79.  
  80. document.addEventListener(`click`, function (event) {
  81. const elem = event.target;
  82.  
  83. if (elem.matches(`.HIT-Catcher-Panda`)) {
  84. sendToHC(false, elem.dataset.key);
  85. nom(elem);
  86. }
  87. if (elem.matches(`.HIT-Catcher-Once`)) {
  88. sendToHC(true, elem.dataset.key);
  89. nom(elem);
  90. }
  91. });