CH Export MTurk Quals

Exports your Mturk qualifications as tab-separated values - adapted from mmmturkeybacon Export Mturk History.

目前为 2014-09-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CH Export MTurk Quals
  3. // @author clickhappier
  4. // @namespace clickhappier
  5. // @description Exports your Mturk qualifications as tab-separated values - adapted from mmmturkeybacon Export Mturk History.
  6. // @include https://www.mturk.com/mturk/findquals?*
  7. // @include https://www.mturk.com/mturk/viewquals?*
  8. // @require http://code.jquery.com/jquery-latest.min.js
  9. // @version 1.0c
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // I made this script (adapted from mmmturkeybacon's Export Mturk History), because on mturk.com, your qual list is only
  14. // sortable by qual name. To use this script, go to the "Qualifications Assigned To You" page. Click the Start button.
  15. // It generates a list of all your currently assigned quals. When it finishes running, select all the output in the
  16. // text box, and copy it into a spreadsheet. Then you can sort and filter as desired, using your spreadsheet program's
  17. // functionality - for example, to see which quals you most recently received, or all quals from a certain requester.
  18. // And if you save copies of past versions of the output list, you can compare them in the future to see changes if desired.
  19.  
  20.  
  21.  
  22. // check if you're on the "Qualifications Assigned To You" page, so you don't think you can run this on the huge list of all quals
  23. var assignedCheck = $('a.nonboldsubnavclass').text().trim();
  24. if ( assignedCheck === 'Qualifications Assigned To You' ) {
  25. // console.log("Qual Export Enabled");
  26.  
  27.  
  28. // create variables
  29.  
  30. var BACKGROUND_COLOR = "#FFFFFF";
  31. var QUALDETAIL_DELAY = 500;
  32. var MPRE_DELAY = 2000;
  33.  
  34. var control_panel_HTML = '<div id="control_panel" style="margin: 0 auto 0 auto;' +
  35. 'border-bottom: 1px solid #000000; margin-bottom: 5px; ' +
  36. 'background-color: ' + BACKGROUND_COLOR + ';"></div>';
  37.  
  38. $('body').prepend(control_panel_HTML);
  39. var control_panel = document.getElementById("control_panel");
  40. var big_red_button = document.createElement("BUTTON");
  41. var progress_report = document.createTextNode("Stopped");
  42. var p = document.createElement("P");
  43. var text_area = document.createElement("TEXTAREA");
  44.  
  45. big_red_button.textContent = "Show Interface";
  46. big_red_button.onclick = function(){show_interface();};
  47. control_panel.appendChild(big_red_button);
  48.  
  49. var global_run = false;
  50. var qualdetail_loop_finished = false;
  51. var page_num = 0;
  52. var qualhistory = {};
  53.  
  54.  
  55. // update the status text displayed next to the start/stop button
  56.  
  57. function set_progress_report(text, force)
  58. {
  59. // console.log("Qual Export set_progress_report");
  60. if (global_run === true || force === true)
  61. {
  62. progress_report.textContent = text;
  63. }
  64. }
  65.  
  66.  
  67. // check if the scraping is done
  68.  
  69. function wait_until_stopped()
  70. {
  71. // console.log("Qual Export wait_until_stopped");
  72. if (global_run === true)
  73. {
  74. if (qualdetail_loop_finished === true)
  75. {
  76. big_red_button.textContent = "Start";
  77. set_progress_report("Finished", false);
  78. }
  79. else
  80. {
  81. setTimeout(function(){wait_until_stopped();}, 500);
  82. }
  83. }
  84. }
  85.  
  86.  
  87. // collect the qual data from each page
  88.  
  89. function scrape($src)
  90. {
  91. // console.log("Qual Export scrape");
  92. var $qualtitle = $src.find('a[class="capsulelink"]');
  93. var $author = $src.find('td[class="capsule_field_title"]:contains("Author:")').next();
  94. var $value = $src.find('td[class="capsule_field_title"]:contains("Qualification Value:")').next();
  95. var $users = $src.find('td[class="capsule_field_title"]:contains("Qualified Users:")').next();
  96. var $description = $src.find('td[class="capsule_field_title"]:contains("Description:")').next();
  97. var $dateassigned = $src.find('td[class="capsule_field_title"]:contains("Date Assigned:")').next();
  98. var $dateretake = $src.find('td[class="capsule_field_title"]:contains("Retake date:")').next();
  99.  
  100. var j = 0;
  101. for (j = 0; j < $qualtitle.length; j++)
  102. {
  103. // console.log("Qual Export j=" + j);
  104. var qualtitle = $qualtitle.eq(j).text().trim();
  105. var author = $author.eq(j).text().trim();
  106. var value = $value.eq(j).text().trim();
  107. var users = $users.eq(j).text().trim();
  108. var description = $description.eq(j).text().trim().replace(/\r\n|\n|\r|\t/g, ' ');
  109. var dateassigned = $dateassigned.eq(j).text().trim();
  110. var dateretake = $dateretake.eq(j).text().trim().replace(/\(.*?\)|\r\n|\n|\r|\t| ( )*/g, ' ').trim(); // removes parenthetical note about how far in the future a retake date is, and the excessive whitespace in between that and the actual date
  111.  
  112. var key = qualtitle+author;
  113. if (qualhistory[key] === undefined)
  114. {
  115. qualhistory[key] = {qualtitle:"", author:"", value:0, users:0, description:"", dateassigned:"", dateretake:""};
  116. qualhistory[key].qualtitle = qualtitle;
  117. qualhistory[key].author = author;
  118. qualhistory[key].value = value;
  119. qualhistory[key].users = users;
  120. qualhistory[key].description = description;
  121. qualhistory[key].dateassigned = dateassigned;
  122. qualhistory[key].dateretake = dateretake;
  123. }
  124. }
  125. }
  126.  
  127. // advance to the next page of quals, and display the finished output when there is no next page anymore
  128. function qualdetail_loop(next_URL)
  129. {
  130. // console.log("Qual Export qualdetail_loop");
  131. if (global_run === true)
  132. {
  133. if (next_URL.length !== 0)
  134. {
  135. $.get(next_URL, function(data)
  136. {
  137. var $src = $(data);
  138. var maxpagerate = $src.find('td[class="error_title"]:contains("You have exceeded the maximum allowed page request rate for this website.")');
  139. if (maxpagerate.length === 0)
  140. {
  141. page_num++;
  142. // console.log("Qual Export qualdetail_loop page_num=" + page_num);
  143. set_progress_report("Processing" + " page " + page_num, false);
  144. console.log(progress_report.textContent);
  145. scrape($src);
  146. $next_URL = $src.find('a[href^="/mturk/viewquals"]:contains("Next")');
  147. next_URL = ($next_URL.length !== 0) ? $next_URL.attr("href") : "";
  148. setTimeout(function(){qualdetail_loop(next_URL);}, QUALDETAIL_DELAY);
  149. }
  150. else
  151. {
  152. setTimeout(function(){qualdetail_loop(next_URL);}, MPRE_DELAY);
  153. // console.log("Qual Export qualdetail_loop MPRE");
  154. }
  155. });
  156. }
  157. else
  158. {
  159. // console.log("Qual Export writing output");
  160. for (var key in qualhistory)
  161. {
  162. var obj = qualhistory[key];
  163. for (var prop in obj)
  164. {
  165. if(obj.hasOwnProperty(prop))
  166. {
  167. text_area.value += obj[prop]+"\t";
  168. }
  169. }
  170. text_area.value += "\n";
  171. }
  172. qualdetail_loop_finished = true;
  173. // console.log("Qual Export start_running false");
  174. global_run = false;
  175. big_red_button.textContent = "Start";
  176. set_progress_report("Stopped", true);
  177. }
  178. }
  179. }
  180.  
  181.  
  182. // when you click the Start button, write the header row to the output, and start scraping the first qual page
  183. function start_running()
  184. {
  185. if (big_red_button.textContent == "Start")
  186. {
  187. // console.log("Qual Export start_running");
  188. global_run = true;
  189. qualdetail_loop_finished = true;
  190. big_red_button.textContent = "Stop";
  191. set_progress_report("Running", false);
  192. text_area.value = "";
  193. // qualtitle, author, value, users, description, dateassigned, dateretake
  194. text_area.value += "Qualification Title\tAuthor (Requester)\tValue\tQualified Users\tDescription\tDate Assigned\tRetake Date\n";
  195.  
  196. qualdetail_loop('findquals?earned=true');
  197. }
  198. else
  199. {
  200. // console.log("Qual Export start_running false");
  201. global_run = false;
  202. big_red_button.textContent = "Start";
  203. set_progress_report("Stopped", true);
  204. }
  205. }
  206.  
  207.  
  208. // create the button and the output text area
  209. function show_interface()
  210. {
  211. // console.log("Qual Export show_interface");
  212. control_panel.removeChild(big_red_button);
  213.  
  214. control_panel.appendChild(document.createTextNode("Export Quals: "));
  215.  
  216. big_red_button.textContent = "Start";
  217. big_red_button.onclick = function(){start_running();};
  218. control_panel.appendChild(big_red_button);
  219. control_panel.appendChild(document.createTextNode(" "));
  220. control_panel.appendChild(progress_report); // 'Running' or 'Stopped' or 'Finished'
  221. control_panel.appendChild(p);
  222. text_area.style.height = 200;
  223. text_area.style.width = "100%";
  224. control_panel.appendChild(text_area); // display area for the export output
  225. }
  226.  
  227.  
  228. }