Hit to TM

Send hit to TM

  1. // ==UserScript==
  2. // @name Hit to TM
  3. // @version 1.0
  4. // @description Send hit to TM
  5. // @author saqfish
  6. // @include https://www.mturk.com/mturk/accept*
  7. // @include https://www.mturk.com/mturk/findhits*
  8. // @include https://www.mturk.com/mturk/searchbar*
  9. // @include https://www.mturk.com/mturk/sorthits*
  10. // @include https://www.mturk.com/mturk/sortsearchbar*
  11. // @include https://www.mturk.com/mturk/viewhits*
  12. // @include https://www.mturk.com/mturk/viewsearchbar*
  13. // @grant none
  14. // @grant GM_log
  15. // @grant GM_getValue
  16. // @grant GM_setValue
  17. // @require http://code.jquery.com/jquery-2.1.0.min.js
  18. // @namespace https://greasyfork.org/users/13769
  19. // ==/UserScript==
  20.  
  21. var delay = 1000; // Set your delay from here. It is in milliseconds.
  22.  
  23. var link = "";
  24. var parentSpan;
  25. var a = 0;
  26.  
  27. var reqnames = [];
  28. $('span.requesterIdentity').each(function(){
  29. reqnames.push($(this).text());
  30. });
  31. var hittitles = [];
  32. $('a[id^=capsule]').each(function(){
  33. hittitles.push($(this).text());
  34. });
  35.  
  36. $('a[href^="/mturk/preview?"]').parent().each(function(z){
  37. $(this).find('a[href^="/mturk/preview?"]').each(function(f){
  38. link = $(this).attr('href');
  39. var oldlink = link.split('?');
  40. //oldlink[0] = "/mturk/previewandaccept";
  41. oldlink[0] = "";
  42. var newlink = oldlink.join('?');
  43. var tmlink = document.createElement("a");
  44. tmlink.className = newlink;
  45. tmlink.setAttribute('id', 'tmlink' + a);
  46. tmlink.setAttribute('href', "javascript:void(0);");
  47. tmlink.setAttribute('style', 'padding-left: 20px;');
  48. tmlink.innerHTML = "TM";
  49. $(this).parent().append(tmlink);
  50. a++;
  51. console.log(newlink);
  52. });
  53. });
  54. $("a[id^='tmlink']").on("click", function(b) {
  55. var link = $(this).attr('class');
  56. var idd = $(this).attr('id').substring(6);
  57. console.log($(this).closest('span').find('.requesterIdentity'));
  58. sendTM(reqnames[idd]+"--"+hittitles[idd],link,"nrm");
  59. });
  60.  
  61. function sendTM(name,link,mode){
  62. tmlink = link.split("=");
  63. if (mode == "nrm"){
  64. var watcher = {
  65. id : tmlink[1],
  66. duration : delay,
  67. type : 'hit',
  68. name : name,
  69. auto : true,
  70. alert : true,
  71. stopOnCatch : false
  72. };
  73. };
  74.  
  75. sendMessage({
  76. header : 'add_watcher',
  77. content : watcher,
  78. timestamp : true
  79. });
  80. };
  81.  
  82. function sendMessage(message) {
  83. var header = message.header;
  84. var content = message.content || new Date().getTime();
  85. var timestamp = message.timestamp && new Date().getTime();
  86. localStorage.setItem('notifier_msg_' + header, JSON.stringify({ content: content, timestamp: timestamp}));
  87. //GM_setValue('notifier_msg_' + header, JSON.stringify({ content: content, timestamp: timestamp}));
  88. console.log("--Sent to TM--");
  89. }