HIT Export Mod for HIT Catcher

Adds panda and once links to HIT exports

当前为 2017-04-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name HIT Export Mod for HIT Catcher
  3. // @namespace https://gist.github.com/Kadauchi
  4. // @version 1.0.3
  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. elem.closest(`li[id^="post-"]`).querySelector(`img[src="styles/dark/ratings/panda.png"]`).click();
  48. }
  49. }
  50.  
  51. for (let elem of document.getElementsByClassName(`ctaBbcodeTable`)) {
  52. if (elem.querySelector(`a[href^="https://www.mturk.com/mturk/preview?groupId="]`)) addButtons(elem);
  53. }
  54.  
  55. const observer = new MutationObserver(function (mutations) {
  56. mutations.forEach(function (mutation) {
  57. for (let i = 0; i < mutation.addedNodes.length; i++) {
  58. const added = mutation.addedNodes[i];
  59.  
  60. for (let elem of added.getElementsByClassName(`ctaBbcodeTable`)) {
  61. if (elem.querySelector(`a[href^="https://www.mturk.com/mturk/preview?groupId="]`)) addButtons(elem);
  62. }
  63. }
  64. });
  65. });
  66.  
  67. observer.observe(document.getElementById(`messageList`), {childList: true});
  68.  
  69. document.addEventListener(`click`, function (event) {
  70. const elem = event.target;
  71.  
  72. if (elem.matches(`.HIT-Catcher-Panda`)) {
  73. sendToHC(false, elem.dataset.key);
  74. nom(elem);
  75. }
  76. if (elem.matches(`.HIT-Catcher-Once`)) {
  77. sendToHC(true, elem.dataset.key);
  78. nom(elem);
  79. }
  80. });