CH Export MTurk Quals

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

目前为 2014-11-01 提交的版本,查看 最新版本

  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 2.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 $qualid = $src.find('a[id*="requestQualLink"]');
  93. var $qualtitle = $src.find('a[class="capsulelink"]');
  94. var $author = $src.find('td[class="capsule_field_title"]:contains("Author:")').next();
  95. var $value = $src.find('td[class="capsule_field_title"]:contains("Qualification Value:")').next();
  96. var $users = $src.find('td[class="capsule_field_title"]:contains("Qualified Users:")').next();
  97. var $description = $src.find('td[class="capsule_field_title"]:contains("Description:")').next();
  98. var $dateassigned = $src.find('td[class="capsule_field_title"]:contains("Date Assigned:")').next();
  99. var $dateretake = $src.find('td[class="capsule_field_title"]:contains("Retake date:")').next();
  100.  
  101. var j = 0;
  102. for (j = 0; j < $qualtitle.length; j++)
  103. {
  104. // console.log("Qual Export j=" + j);
  105. var qualid = $qualid.eq(j).attr("href").split('=')[1];
  106. var qualtitle = $qualtitle.eq(j).text().trim();
  107. var author = $author.eq(j).text().trim();
  108. var value = $value.eq(j).text().trim();
  109. var users = $users.eq(j).text().trim();
  110. var description = $description.eq(j).text().trim().replace(/\r\n|\n|\r|\t/g, ' ');
  111. var dateassigned = $dateassigned.eq(j).text().trim();
  112. 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
  113.  
  114. var key = qualid;
  115. if (qualhistory[key] === undefined)
  116. {
  117. qualhistory[key] = {qualtitle:"", author:"", value:0, users:0, description:"", dateassigned:"", dateretake:"", qualid:""};
  118. qualhistory[key].qualtitle = qualtitle;
  119. qualhistory[key].author = author;
  120. qualhistory[key].value = value;
  121. qualhistory[key].users = users;
  122. qualhistory[key].description = description;
  123. qualhistory[key].dateassigned = dateassigned;
  124. qualhistory[key].dateretake = dateretake;
  125. qualhistory[key].qualid = qualid;
  126. }
  127. }
  128. }
  129.  
  130. // advance to the next page of quals, and display the finished output when there is no next page anymore
  131. function qualdetail_loop(next_URL)
  132. {
  133. // console.log("Qual Export qualdetail_loop");
  134. if (global_run === true)
  135. {
  136. if (next_URL.length !== 0)
  137. {
  138. $.get(next_URL, function(data)
  139. {
  140. var $src = $(data);
  141. var maxpagerate = $src.find('td[class="error_title"]:contains("You have exceeded the maximum allowed page request rate for this website.")');
  142. if (maxpagerate.length === 0)
  143. {
  144. page_num++;
  145. // console.log("Qual Export qualdetail_loop page_num=" + page_num);
  146. set_progress_report("Processing" + " page " + page_num, false);
  147. console.log(progress_report.textContent);
  148. scrape($src);
  149. $next_URL = $src.find('a[href^="/mturk/viewquals"]:contains("Next")');
  150. next_URL = ($next_URL.length !== 0) ? $next_URL.attr("href") : "";
  151. setTimeout(function(){qualdetail_loop(next_URL);}, QUALDETAIL_DELAY);
  152. }
  153. else
  154. {
  155. setTimeout(function(){qualdetail_loop(next_URL);}, MPRE_DELAY);
  156. // console.log("Qual Export qualdetail_loop MPRE");
  157. }
  158. });
  159. }
  160. else
  161. {
  162. // console.log("Qual Export writing output");
  163. for (var key in qualhistory)
  164. {
  165. var obj = qualhistory[key];
  166. for (var prop in obj)
  167. {
  168. if(obj.hasOwnProperty(prop))
  169. {
  170. text_area.value += obj[prop]+"\t";
  171. }
  172. }
  173. text_area.value += "\n";
  174. }
  175. qualdetail_loop_finished = true;
  176. // console.log("Qual Export start_running false");
  177. global_run = false;
  178. big_red_button.textContent = "Start";
  179. set_progress_report("Stopped", true);
  180. }
  181. }
  182. }
  183.  
  184.  
  185. // when you click the Start button, write the header row to the output, and start scraping the first qual page
  186. function start_running()
  187. {
  188. if (big_red_button.textContent == "Start")
  189. {
  190. // console.log("Qual Export start_running");
  191. global_run = true;
  192. qualdetail_loop_finished = true;
  193. big_red_button.textContent = "Stop";
  194. set_progress_report("Running", false);
  195. text_area.value = "";
  196. // qualtitle, author, value, users, description, dateassigned, dateretake
  197. text_area.value += "Qualification Title\tAuthor (Requester)\tValue\tQualified Users\tDescription\tDate Assigned\tRetake Date\tQualification ID\n";
  198.  
  199. qualdetail_loop('findquals?earned=true');
  200. }
  201. else
  202. {
  203. // console.log("Qual Export start_running false");
  204. global_run = false;
  205. big_red_button.textContent = "Start";
  206. set_progress_report("Stopped", true);
  207. }
  208. }
  209.  
  210.  
  211. // create the button and the output text area
  212. function show_interface()
  213. {
  214. // console.log("Qual Export show_interface");
  215. control_panel.removeChild(big_red_button);
  216.  
  217. control_panel.appendChild(document.createTextNode("Export Quals: "));
  218.  
  219. big_red_button.textContent = "Start";
  220. big_red_button.onclick = function(){start_running();};
  221. control_panel.appendChild(big_red_button);
  222. control_panel.appendChild(document.createTextNode(" "));
  223. control_panel.appendChild(progress_report); // 'Running' or 'Stopped' or 'Finished'
  224. control_panel.appendChild(p);
  225. text_area.style.height = 200;
  226. text_area.style.width = "100%";
  227. control_panel.appendChild(text_area); // display area for the export output
  228. }
  229.  
  230.  
  231. }