HIT Scraper WITH EXPORT

Snag HITs.

当前为 2014-06-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name HIT Scraper WITH EXPORT
  3. // @author Kerek and TJ
  4. // @description Snag HITs.
  5. // Based in part on code from mmmturkeybacon Export Mturk History and mmmturkeybacon Color Coded Search with Checkpoints
  6. // @namespace http://userscripts.org/users/536998
  7. // @match https://www.mturk.com/mturk/findhits?match=true#hit_scraper*
  8. // @match https://www.mturk.com/mturk/findhits?match=true?hit_scraper*
  9. // @version 1.3.0.12
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @grant GM_deleteValue
  14. // @require http://code.jquery.com/jquery-latest.min.js
  15. // ==/UserScript==
  16.  
  17. //alter the requester ignore last as you desire, case insensitive
  18. var default_list = ["oscar smith", "Diamond Tip Research LLC", "jonathon weber", "jerry torres", "Crowdsource", "we-pay-you-fast", "turk experiment", "jon brelig"];
  19. var ignore_list = default_list;
  20. if (GM_getValue("scraper_ignore_list"))
  21. ignore_list = GM_getValue("scraper_ignore_list");
  22.  
  23. //This is to update the hit export symbol
  24. var symbol = "⚖";
  25.  
  26. //this searches extra pages if you skip too much, helps fill out results if you hit a chunk of ignored HITs. Change to true for this behavior.
  27. var correct_for_skips = false;
  28.  
  29. //weight the four TO ratings for the coloring. Default has pay twice as important as fairness and nothing for communication and fast.
  30. var COMM_WEIGHT = 0;
  31. var PAY_WEIGHT = 10;
  32. var FAIR_WEIGHT = 5;
  33. var FAST_WEIGHT = 0;
  34.  
  35. //display your hitdb records if applicable
  36. var check_hitDB = true;
  37.  
  38. //default text size
  39. var default_text_size=11;
  40.  
  41.  
  42.  
  43. var HITStorage = {};
  44. var indexedDB = window.indexedDB || window.webkitIndexedDB ||
  45. window.mozIndexedDB;
  46. window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.mozIDBTransaction;
  47. window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.mozIDBKeyRange;
  48. HITStorage.IDBTransactionModes = { "READ_ONLY": "readonly", "READ_WRITE": "readwrite", "VERSION_CHANGE": "versionchange" };
  49. var IDBKeyRange = window.IDBKeyRange;
  50.  
  51. HITStorage.indexedDB = {};
  52. HITStorage.indexedDB = {};
  53. HITStorage.indexedDB.db = null;
  54.  
  55. HITStorage.indexedDB.onerror = function(e) {
  56. console.log(e);
  57. };
  58.  
  59. var v=4;
  60.  
  61. HITStorage.indexedDB.checkTitle = function(title,button) {
  62. var request = indexedDB.open("HITDB", v);
  63. request.onsuccess = function(e) {
  64. HITStorage.indexedDB.db = e.target.result;
  65. var db = HITStorage.indexedDB.db;
  66. if (!db.objectStoreNames.contains("HIT"))
  67. {
  68. db.close();
  69. return;
  70. }
  71. var trans = db.transaction(["HIT"], HITStorage.IDBTransactionModes.READ_ONLY);
  72. var store = trans.objectStore("HIT");
  73.  
  74. var index = store.index("title");
  75. index.get(title).onsuccess = function(event)
  76. {
  77. if (event.target.result === undefined)
  78. {
  79. console.log(title + ' not found');
  80. history[button].titledb=false;
  81. }
  82. else
  83. {
  84. console.log(title + ' found');
  85. history[button].titledb=true;
  86. }
  87. db.close();
  88. };
  89. };
  90. request.onerror = HITStorage.indexedDB.onerror;
  91. };
  92.  
  93. HITStorage.indexedDB.checkRequester = function(id,button) {
  94. var request = indexedDB.open("HITDB", v);
  95. request.onsuccess = function(e) {
  96. HITStorage.indexedDB.db = e.target.result;
  97. var db = HITStorage.indexedDB.db;
  98. if (!db.objectStoreNames.contains("HIT"))
  99. {
  100. db.close();
  101. return;
  102. }
  103. var trans = db.transaction(["HIT"], HITStorage.IDBTransactionModes.READ_ONLY);
  104. var store = trans.objectStore("HIT");
  105.  
  106. var index = store.index("requesterId");
  107. index.get(id).onsuccess = function(event)
  108. {
  109. if (event.target.result === undefined)
  110. {history[button].reqdb=false;
  111. console.log(id + ' not found');
  112. }
  113. else
  114. {
  115. history[button].reqdb=true;
  116. console.log(id + ' found');
  117. }
  118. db.close();
  119. };
  120. };
  121. request.onerror = HITStorage.indexedDB.onerror;
  122. };
  123.  
  124. var PAGES_TO_SCRAPE = 3;
  125. var MINIMUM_HITS = 100;
  126. var SEARCH_REFRESH=0;
  127. var URL_BASE = "/mturk/searchbar?searchWords=&selectedSearchType=hitgroups";
  128. var initial_url = URL_BASE;
  129. var TO_REQ_URL = "http://turkopticon.ucsd.edu/reports?id=";
  130. var found_key_list=[];
  131. var last_clear_time = new Date().getTime();
  132. var searched_once = false;
  133. var save_new_results_time = 120;
  134. var save_results_time = 3600;
  135. var default_type = 0;
  136. var cur_loc = window.location.href;
  137. var time_input = document.createElement("INPUT");
  138. time_input.value = 0;
  139. var page_input = document.createElement("INPUT");
  140. page_input.value = 3;
  141. var min_input = document.createElement("INPUT");
  142. var new_time_display_input = document.createElement("INPUT");
  143. new_time_display_input.value = 300;
  144. var reward_input = document.createElement("INPUT");
  145. var qual_input = document.createElement("INPUT");
  146. qual_input.type = "checkbox";
  147. qual_input.checked = true;
  148. var masters_input = document.createElement("INPUT");
  149. masters_input.type = "checkbox";
  150. var sort_input1 = document.createElement("INPUT");
  151. sort_input1.type = "radio";
  152. sort_input1.name = "sort_type";
  153. sort_input1.value = "latest";
  154. sort_input1.checked = true;
  155. var sort_input2 = document.createElement("INPUT");
  156. sort_input2.type = "radio";
  157. sort_input2.name = "sort_type";
  158. sort_input2.value = "most";
  159. var sort_input3 = document.createElement("INPUT");
  160. sort_input3.type = "radio";
  161. sort_input3.name = "sort_type";
  162. sort_input3.value = "amount";
  163.  
  164. var search_input = document.createElement("INPUT");
  165.  
  166. var LINK_BASE = "https://www.mturk.com";
  167. var BACKGROUND_COLOR = "rgb(19, 19, 19)";
  168. var STATUSDETAIL_DELAY = 250;
  169. var MPRE_DELAY = 3000;
  170.  
  171. var next_page = 1;
  172.  
  173. var GREEN = '#66CC66'; // > 4
  174. var LIGHTGREEN = '#ADFF2F'; // > 3 GREEN YELLOW
  175. var YELLOW = '#FFD700';
  176. var ORANGE = '#FF9900'; // > 2
  177. var RED = '#FF3030'; // <= 2
  178. var BLUE = '#C0D9D9'; // no TO
  179. var GREY = 'lightGrey';
  180. var BROWN = '#94704D';
  181. var DARKGREY = '#9F9F9F';
  182. $('body').css('background', BACKGROUND_COLOR);
  183.  
  184. var API_PROXY_BASE = 'https://api.turkopticon.istrack.in/';
  185. var API_MULTI_ATTRS_URL = API_PROXY_BASE + 'multi-attrs.php?ids=';
  186. var REVIEWS_BASE = 'http://turkopticon.ucsd.edu/';
  187.  
  188. var control_panel_HTML = '<div id="control_panel" style="margin: 0 auto 0 auto;' +
  189. 'border-bottom: 1px solid #000000; margin-bottom: 5px; ' +
  190. 'background-color: ' + BACKGROUND_COLOR + ';"></div>';
  191. $('body > :not(#control_panel)').hide(); //hide all nodes directly under the body
  192. $('body').prepend(control_panel_HTML);
  193.  
  194. var control_panel = document.getElementById("control_panel");
  195. var big_red_button = document.createElement("BUTTON");
  196. var reset_blocks = document.createElement("BUTTON");
  197. var progress_report = document.createTextNode("Stopped");
  198. var text_area = document.createElement("TABLE");
  199. big_red_button.textContent = "Show Interface";
  200. big_red_button.onclick = function(){show_interface();};
  201. reset_blocks.textContent = "Reset blocklist";
  202. reset_blocks.onclick = function(){
  203. console.log("in");
  204. if (confirm("Are you sure you want to delete your blocklist?")){
  205. GM_deleteValue("scraper_ignore_list");
  206. ignore_list = default_list;
  207. alert("Ignore list reset to default, please re-scrape");
  208. }
  209. };
  210. control_panel.appendChild(big_red_button);
  211. control_panel.appendChild(reset_blocks);
  212.  
  213. show_interface();
  214.  
  215. var global_run = false;
  216. var statusdetail_loop_finished = false;
  217. var date_header = "";
  218. var history = {};
  219. var wait_loop;
  220.  
  221. function set_progress_report(text, force)
  222. {
  223. if (global_run == true || force == true)
  224. {
  225. progress_report.textContent = text;
  226. }
  227. }
  228.  
  229. function get_progress_report()
  230. {
  231. return progress_report.textContent;
  232. }
  233.  
  234. function wait_until_stopped()
  235. {
  236. if (global_run == true)
  237. {
  238. if (statusdetail_loop_finished == true)
  239. {
  240. big_red_button.textContent = "Start";
  241. set_progress_report("Finished", false);
  242. }
  243. else
  244. {
  245. setTimeout(function(){wait_until_stopped();}, 500);
  246. }
  247. }
  248. }
  249.  
  250. function display_wait_time(wait_time)
  251. {
  252. if (global_run == true)
  253. {
  254. var current_progress = get_progress_report();
  255. if (current_progress.indexOf("Searching again in")!==-1)
  256. {
  257. set_progress_report(current_progress.replace(/Searching again in \d+ seconds/ , "Searching again in " + wait_time + " seconds"),false);
  258. }
  259. else
  260. set_progress_report(current_progress + " Searching again in " + wait_time + " seconds.", false);
  261. if (wait_time>1)
  262. setTimeout(function(){display_wait_time(wait_time-1);}, 1000);
  263. }
  264. }
  265.  
  266. function dispArr(ar)
  267. {
  268. var disp = "";
  269. for (var z = 0; z < ar.length; z++)
  270. {
  271. disp += "id " + z + " is " + ar[z] + " ";
  272. }
  273. console.log(disp);
  274. }
  275.  
  276. function scrape($src)
  277. {
  278. var $requester = $src.find('a[href^="/mturk/searchbar?selectedSearchType=hitgroups&requester"]');
  279. var $title = $src.find('a[class="capsulelink"]');
  280. var $reward = $src.find('span[class="reward"]');
  281. var $preview = $src.find('a[href^="/mturk/preview?"]');
  282. var $qualified = $src.find('a[href^="/mturk/notqualified?"]');
  283. var $times = $src.find('a[id^="duration_to_complete"]');
  284. var $descriptions = $src.find('a[id^="description"]');
  285. var not_qualified_group_IDs=[];
  286. var $quals = $src.find('a[id^="qualificationsRequired"]');
  287. $qualified.each(function(){
  288. var groupy = $(this).attr('href');
  289. groupy = groupy.replace("/mturk/notqualified?hitId=","");
  290. not_qualified_group_IDs.push(groupy);
  291. });
  292. var $mixed = $src.find('a[href^="/mturk/preview?"],a[href^="/mturk/notqualified?"]');
  293. var listy =[];
  294. $mixed.each(function(){
  295. var groupy = $(this).attr('href');
  296. groupy = groupy.replace("/mturk/notqualified?hitId=","");
  297. groupy = groupy.replace("/mturk/preview?groupId=","");
  298. listy.push(groupy);
  299. });
  300. listy = listy.filter(function(elem, pos) {
  301. return listy.indexOf(elem) == pos;
  302. });
  303.  
  304. for (var j = 0; j < $requester.length; j++)
  305. {
  306. var $hits = $requester.eq(j).parent().parent().parent().parent().parent().parent().find('td[class="capsule_field_text"]');
  307. var requester_name = $requester.eq(j).text().trim();
  308. var requester_link = $requester.eq(j).attr('href');
  309. var group_ID=listy[j];
  310. var preview_link = "/mturk/preview?groupId=" + group_ID;
  311. var title = $title.eq(j).text().trim();
  312. var reward = $reward.eq(j).text().trim();
  313. var hits = $hits.eq(4).text().trim();
  314. var time = $times.eq(j).parent()[0].nextSibling.nextSibling.innerHTML;
  315. var description = $descriptions.eq(j).parent()[0].nextSibling.nextSibling.innerHTML;
  316. //console.log(description);
  317. var requester_id = requester_link.replace('/mturk/searchbar?selectedSearchType=hitgroups&requesterId=','');
  318. var accept_link;
  319. accept_link = preview_link.replace('preview','previewandaccept');
  320. /*HIT SCRAPER ADDITION*/
  321. var qElements = $quals.eq(j).parent().parent().parent().find('tr');
  322. //console.log(qElements);
  323.  
  324. var qualifications = [];
  325. for (var i = 1; i < qElements.length; i++) {
  326. qualifications.push((qElements[i].childNodes[1].textContent.trim().replace(/\s+/g, ' ').indexOf("Masters") != -1 ? "[color=red][b]"+qElements[i].childNodes[1].textContent.trim().replace(/\s+/g, ' ')+"[/b][/color]" : qElements[i].childNodes[1].textContent.trim().replace(/\s+/g, ' ')));
  327. }
  328. var qualList = (qualifications.join(', ') ? qualifications.join(', ') : "None");
  329.  
  330. key = requester_name+title+reward+group_ID;
  331. found_key_list.push(key);
  332. if (history[key] == undefined)
  333. {
  334. history[key] = {requester:"", title:"", description:"", reward:"", hits:"", req_link:"", quals:"", prev_link:"", rid:"", acc_link:"", new_result:"", qualified:"", found_this_time:"", initial_time:"", reqdb:"",titledb:"",time:""};
  335. history[key].req_link = requester_link;
  336. history[key].prev_link = preview_link;
  337. history[key].requester = requester_name;
  338. history[key].title = title;
  339. history[key].reward = reward;
  340. history[key].hits = hits;
  341. history[key].rid = requester_id;
  342. history[key].acc_link = accept_link;
  343. history[key].time = time;
  344. history[key].quals = qualList;
  345. history[key].description = description;
  346. HITStorage.indexedDB.checkRequester(requester_id,key);
  347. HITStorage.indexedDB.checkTitle(title,key);
  348. if (searched_once)
  349. {
  350. history[key].initial_time = new Date().getTime();//-1000*(save_new_results_time - SEARCH_REFRESH);
  351. history[key].new_result = 0;
  352. }
  353. else
  354. {
  355. history[key].initial_time = new Date().getTime()-1000*save_new_results_time;
  356. history[key].new_result = 1000*save_new_results_time;
  357. }
  358. if (not_qualified_group_IDs.indexOf(group_ID)!==-1)
  359. history[key].qualified = false;
  360. else
  361. history[key].qualified = true;
  362.  
  363. history[key].found_this_time = true;
  364. }
  365. else
  366. {
  367. history[key].new_result = new Date().getTime() - history[key].initial_time;
  368. history[key].found_this_time = true;
  369. history[key].hits = hits;
  370. }
  371. }
  372. }
  373.  
  374. function statusdetail_loop(next_URL)
  375. {
  376. if (global_run == true)
  377. {
  378. if (next_URL.length != 0)
  379. {
  380. $.get(next_URL, function(data)
  381. {
  382. var $src = $(data);
  383. var maxpagerate = $src.find('td[class="error_title"]:contains("You have exceeded the maximum allowed page request rate for this website.")');
  384. if (maxpagerate.length == 0)
  385. {
  386. set_progress_report("Processing page " + next_page, false);
  387. scrape($src);
  388. $next_URL = $src.find('a[href^="/mturk/viewsearchbar"]:contains("Next")');
  389. next_URL = ($next_URL.length != 0) ? $next_URL.attr("href") : "";
  390. next_page++;
  391. if (default_type == 1)
  392. {
  393. var hmin = MINIMUM_HITS+1;
  394. for (j = 0; j < found_key_list.length; j++)
  395. {
  396. if (history[found_key_list[j]].hits < hmin)
  397. {
  398. next_URL = "";
  399. next_page = -1;
  400. break;
  401. }
  402. }
  403. }
  404. else if (next_page > PAGES_TO_SCRAPE && correct_for_skips)
  405. {
  406. var skipped_hits = 0;
  407. var added_pages = 0;
  408. for (j = 0; j < found_key_list.length; j++)
  409. {
  410. var obj = history[found_key_list[j]];
  411. if (! ignore_check(obj.requester,obj.title))
  412. skipped_hits++;
  413. }
  414. added_pages = Math.floor(skipped_hits/10);
  415. if (skipped_hits%10 >6)
  416. added_pages++;
  417. if (next_page > PAGES_TO_SCRAPE + added_pages)
  418. {
  419. next_URL = "";
  420. next_page = -1;
  421. }
  422. }
  423. else if (next_page > PAGES_TO_SCRAPE)
  424. {
  425. next_URL = "";
  426. next_page = -1;
  427. }
  428. setTimeout(function(){statusdetail_loop(next_URL);}, STATUSDETAIL_DELAY);
  429. }
  430. else
  431. {
  432. console.log("MPRE");
  433. setTimeout(function(){statusdetail_loop(next_URL);}, MPRE_DELAY);
  434. }
  435. });
  436. }
  437. else
  438. {
  439. searched_once = true;
  440. var found_hits = found_key_list.length;
  441. var shown_hits = 0;
  442. var new_hits = 0;
  443. var url = API_MULTI_ATTRS_URL;
  444. var rids = [];
  445. var lastRow = text_area.rows.length - 1;
  446. for (i = lastRow; i>0; i--)
  447. text_area.deleteRow(i);
  448. for (j = 0; j < found_key_list.length; j++)
  449. {
  450. //(function(url,rids,j) {
  451. var obj = history[found_key_list[j]];
  452. if (ignore_check(obj.requester,obj.title) && obj.found_this_time){
  453. ++shown_hits;
  454. //console.log(obj);
  455. //hit export will update col_heads[1]
  456. var col_heads = ["<a href='"+ LINK_BASE+obj.req_link +"' target='_blank'>" + obj.requester + "</a>","<a href='"+ LINK_BASE+obj.prev_link +"' target='_blank' title='"+ obj.description +"'>" + obj.title + "</a>",obj.reward,obj.hits,"TO down","<a href='"+ LINK_BASE+obj.acc_link +"' target='_blank'>Accept</a>"];
  457. var row = text_area.insertRow(text_area.rows.length);
  458. url += obj.rid + ',';
  459. rids.push(obj.rid);
  460. if (check_hitDB)
  461. {
  462. col_heads.push("R");
  463. col_heads.push("T");
  464. }
  465. if (!obj.qualified)
  466. {
  467. col_heads.push("Not Qualified");
  468. }
  469. for (i=0; i<col_heads.length; i++)
  470. {
  471. var this_cell = row.insertCell(i);
  472. row.cells[i].style.fontSize = default_text_size;
  473. this_cell.innerHTML = col_heads[i];
  474. if(i>1)
  475. this_cell.style.textAlign = 'center';
  476. if (check_hitDB)
  477. {
  478. if (i==6)
  479. {
  480. if (obj.reqdb)
  481. this_cell.style.backgroundColor = GREEN;
  482. else
  483. this_cell.style.backgroundColor = RED;
  484. }
  485. else if (i==7)
  486. {
  487. if (obj.titledb)
  488. this_cell.style.backgroundColor = GREEN;
  489. else
  490. this_cell.style.backgroundColor = RED;
  491. }
  492. else if (i==8)
  493. this_cell.style.backgroundColor = DARKGREY;
  494. }
  495. else if (i==6)
  496. this_cell.style.backgroundColor = DARKGREY;
  497. }
  498. if (Object.keys(history).length>0)
  499. {
  500. if (obj.new_result < 1000*save_new_results_time)
  501. {
  502. new_hits++;
  503. for (i in col_heads)
  504. {
  505. row.cells[i].style.fontSize = default_text_size + 1;
  506. row.cells[i].style.fontWeight = "bold";
  507. }
  508. }
  509. }
  510. button = document.createElement('button'); //HIT SCRAPER ADDITION
  511. button.textContent = 'vB';
  512. button.title = 'Export this HIT description as vBulletin formatted text';
  513. button.style.height = '14px';
  514. button.style.width = '30px';
  515. button.style.fontSize = '8px';
  516. button.style.border = '1px solid';
  517. button.style.padding = '0px';
  518. button.style.backgroundColor = 'transparent';
  519. button2 = document.createElement('button'); //BUTTON TO BLOCK REQUESTER
  520. button2.textContent = 'BLOCK';
  521. button2.title = 'Add requester to block list';
  522. button2.style.height = '14px';
  523. button2.style.width = '30px';
  524. button2.style.fontSize = '8px';
  525. button2.style.border = '1px solid';
  526. button2.style.padding = '0px';
  527. button2.style.backgroundColor = 'transparent';
  528. //button.addEventListener("click", function() {export_func_deleg(j);}.bind(null,j), false);
  529. button.addEventListener("click", (function (obj,j) { return function() {export_func_deleg(obj,j);}})(obj,j));
  530. row.cells[1].appendChild(button);
  531. button2.addEventListener("click", (function (obj,j) { return function() {block_deleg(obj,j);}})(obj,j));
  532. row.cells[0].appendChild(button2);
  533. }
  534. //});
  535. }
  536. set_progress_report("Scrape complete. " + shown_hits + " HITs found (" + new_hits + " new results). " + (found_hits - shown_hits) + " HITs ignored.", false);
  537. url = url.substring(0,url.length - 1);
  538. //console.log(url);
  539. var success_flag = false;
  540. GM_xmlhttpRequest(
  541. {
  542. method: "GET",
  543. url: url,
  544. onload: function (results)
  545. {
  546. //console.log(results.responseText);
  547. rdata = $.parseJSON(results.responseText);
  548. for (i = 0; i < rids.length; i++)
  549. {
  550. text_area.rows[i+1].style.backgroundColor = GREY;
  551. if (rdata[rids[i]])
  552. {
  553. var pay = rdata[rids[i]].attrs.pay
  554. var reviews = rdata[rids[i]].reviews
  555. var average = 0;
  556. var sum = 0;
  557. var divisor = 0;
  558. var comm = rdata[rids[i]].attrs.comm;
  559. var fair = rdata[rids[i]].attrs.fair;
  560. var fast = rdata[rids[i]].attrs.fast;
  561. if (comm > 0)
  562. {
  563. sum += COMM_WEIGHT*comm;
  564. divisor += COMM_WEIGHT;
  565. }
  566. if (pay > 0)
  567. {
  568. sum += PAY_WEIGHT*pay;
  569. divisor += PAY_WEIGHT;
  570. }
  571. if (fair > 0)
  572. {
  573. sum += FAIR_WEIGHT*fair;
  574. divisor += FAIR_WEIGHT;
  575. }
  576. if (fast > 0)
  577. {
  578. sum += FAST_WEIGHT*fast;
  579. divisor += FAST_WEIGHT;
  580. }
  581. if (divisor > 0)
  582. {
  583. average = sum/divisor;
  584. }
  585. text_area.rows[i+1].cells[4].innerHTML = "<a href='"+ TO_REQ_URL+rids[i] +"' target='_blank'>" + pay + "</a>";
  586. if (reviews > 4)
  587. {
  588. if (average > 4.49)
  589. text_area.rows[i+1].style.backgroundColor = GREEN;
  590. else if (average > 3.49)
  591. text_area.rows[i+1].style.backgroundColor = LIGHTGREEN;
  592. //else if (average > 2.99)
  593. // text_area.rows[i+1].style.backgroundColor = YELLOW;
  594. else if (average > 1.99)
  595. text_area.rows[i+1].style.backgroundColor = ORANGE;
  596. else if (average > 0)
  597. text_area.rows[i+1].style.backgroundColor = RED;
  598. }
  599. }
  600. else
  601. {
  602. text_area.rows[i+1].cells[4].innerHTML = "No data";
  603. }
  604. }
  605. success_flag = true;
  606. }
  607. });
  608. if (!success_flag)
  609. for (i = 0; i < rids.length; i++) text_area.rows[i+1].style.backgroundColor = GREY;
  610. statusdetail_loop_finished = true;
  611. if (SEARCH_REFRESH>0)
  612. {
  613. wait_loop = setTimeout(function(){if (global_run) start_it();}, 1000*SEARCH_REFRESH);
  614. display_wait_time(SEARCH_REFRESH);
  615. }
  616. else
  617. {
  618. global_run = false;
  619. big_red_button.textContent = "Start";
  620. }
  621. }
  622. }
  623. }
  624.  
  625. function ignore_check(r,t){
  626. return -1 == ignore_list.map(function(item) { return item.toLowerCase(); }).indexOf(r.toLowerCase());
  627. }
  628.  
  629. function start_running()
  630. {
  631. if (big_red_button.textContent == "Start")
  632. {
  633. global_run = true;
  634. initial_url = URL_BASE;
  635. if (search_input.value.length>0)
  636. {
  637. initial_url = initial_url.replace("searchWords=", "searchWords=" + search_input.value);
  638. }
  639. if (time_input.value.replace(/[^0-9]+/g,"") != "")
  640. {
  641. SEARCH_REFRESH = Number(time_input.value);
  642. }
  643. if (page_input.value.replace(/[^0-9]+/g,"") != "")
  644. {
  645. PAGES_TO_SCRAPE = Number(page_input.value);
  646. }
  647. if (min_input.value.replace(/[^0-9]+/g,"") != "")
  648. {
  649. MINIMUM_HITS = Number(min_input.value);
  650. }
  651. if (new_time_display_input.value.replace(/[^0-9]+/g,"") != "")
  652. {
  653. save_new_results_time = Number(new_time_display_input.value);
  654. }
  655. if (reward_input.value.replace(/[^0-9]+/g,"") != "")
  656. {
  657. initial_url += "&minReward=" + reward_input.value;
  658. }
  659. else
  660. {
  661. initial_url += "&minReward=0.00";
  662. }
  663. if (qual_input.checked)
  664. {
  665. initial_url += "&qualifiedFor=on"
  666. }
  667. else
  668. {
  669. initial_url += "&qualifiedFor=off"
  670. }
  671. if (masters_input.checked)
  672. {
  673. initial_url += "&requiresMasterQual=on"
  674. }
  675. if (sort_input1.checked)
  676. {
  677. initial_url+= "&sortType=LastUpdatedTime%3A1";
  678. default_type = 0;
  679. }
  680. else if (sort_input2.checked)
  681. {
  682. initial_url+= "&sortType=NumHITs%3A1";
  683. default_type = 1;
  684. }
  685. else if (sort_input3.checked)
  686. {
  687. initial_url+= "&sortType=Reward%3A1";
  688. default_type = 0;
  689. }
  690. initial_url+="&pageNumber=1&searchSpec=HITGroupSearch"
  691. start_it();
  692. }
  693. else
  694. {
  695. global_run = false;
  696. clearTimeout(wait_loop);
  697. big_red_button.textContent = "Start";
  698. set_progress_report("Stopped", true);
  699. }
  700. }
  701.  
  702. function start_it()
  703. {
  704. statusdetail_loop_finished = false;
  705. big_red_button.textContent = "Stop";
  706. found_key_list=[];
  707. var ctime = new Date().getTime()
  708. if (ctime - last_clear_time > save_results_time*666)
  709. {
  710. var last_history=history;
  711. history = {};
  712. for (var key in last_history)
  713. {
  714. if (last_history[key].new_result<save_results_time*1000)
  715. {
  716. history[key]=last_history[key];
  717. if (last_history[key].found_this_time)
  718. {
  719. last_history[key].found_this_time = false;
  720. if (last_history[key].new_result>save_new_results_time*1000)
  721. last_history[key].initial_time = ctime-1000*save_new_results_time;
  722. }
  723. }
  724.  
  725. }
  726. last_clear_time = ctime;
  727. }
  728. next_page = 1;
  729. statusdetail_loop(initial_url);
  730. }
  731.  
  732.  
  733. function show_interface()
  734. {
  735. control_panel.style.color = BROWN;
  736. control_panel.style.fontSize = 14;
  737. control_panel.removeChild(big_red_button);
  738. control_panel.appendChild(document.createTextNode("Auto-refresh delay: "));
  739. time_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
  740. time_input.title = "Enter search refresh delay in seconds\n" + "Enter 0 for no auto-refresh\n" + "Default is 0 (no auto-refresh)";
  741. time_input.size = 3;
  742. control_panel.appendChild(time_input);
  743. control_panel.appendChild(document.createTextNode(" "));
  744. control_panel.appendChild(document.createTextNode("Pages to scrape: "));
  745. page_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
  746. page_input.title = "Enter number of pages to scrape\n" + "Default is 4";
  747. page_input.size = 3;
  748. control_panel.appendChild(page_input);
  749. control_panel.appendChild(document.createTextNode(" "));
  750. control_panel.appendChild(document.createTextNode("Minimum batch size: "));
  751. min_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
  752. min_input.title = "Enter minimum HITs for batch search\n" + "Default is 100";
  753. min_input.size = 3;
  754. control_panel.appendChild(min_input);
  755. control_panel.appendChild(document.createTextNode(" "));
  756. control_panel.appendChild(document.createTextNode("New HIT highlighting: "));
  757. new_time_display_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
  758. new_time_display_input.title = "Enter time (in seconds) to keep new HITs highlighted\n" + "Default is 300 (5 minutes)";
  759. new_time_display_input.size = 6;
  760. control_panel.appendChild(new_time_display_input);
  761. control_panel.appendChild(document.createElement("P"));
  762. control_panel.appendChild(document.createTextNode("Minimum reward: "));
  763. reward_input.size = 6;
  764. control_panel.appendChild(reward_input);
  765. control_panel.appendChild(document.createTextNode(" "));
  766.  
  767. control_panel.appendChild(document.createTextNode("Qualified"));
  768. control_panel.appendChild(qual_input);
  769. control_panel.appendChild(document.createTextNode(" "));
  770. control_panel.appendChild(document.createTextNode("Masters"));
  771. control_panel.appendChild(masters_input);
  772. control_panel.appendChild(document.createTextNode(" "));
  773. control_panel.appendChild(document.createTextNode("Sort types: "));
  774. control_panel.appendChild(sort_input1);
  775. control_panel.appendChild(document.createTextNode("Latest"));
  776. control_panel.appendChild(sort_input2);
  777. control_panel.appendChild(document.createTextNode("Most Available"));
  778. control_panel.appendChild(sort_input3);
  779. control_panel.appendChild(document.createTextNode("Amount"));
  780. control_panel.appendChild(document.createElement("P"));
  781. control_panel.appendChild(search_input);
  782. search_input.size = 20;
  783. search_input.title = "Enter a search term to include\n" + "Default is blank (no included terms)";
  784. search_input.placeholder="Enter search terms here";
  785. control_panel.appendChild(document.createTextNode(" "));
  786. big_red_button.textContent = "Start";
  787. big_red_button.onclick = function(){start_running();};
  788. reset_blocks.textContent = "Reset blocklist";
  789. reset_blocks.onclick = function(){
  790. console.log("in");
  791. if (confirm("Are you sure you want to delete your blocklist?")){
  792. GM_deleteValue("scraper_ignore_list");
  793. ignore_list = default_list;
  794. alert("Ignore list reset to default, please re-scrape");
  795. }
  796. };
  797. control_panel.appendChild(big_red_button);
  798. control_panel.appendChild(reset_blocks);
  799. control_panel.appendChild(document.createTextNode(" "));
  800. control_panel.appendChild(progress_report);
  801. control_panel.appendChild(document.createElement("P"));
  802. text_area.style.fontWeight = 400;
  803. text_area.createCaption().innerHTML = "HITs";
  804. var col_heads = ['Requester','Title','Reward','HITs Available','TO pay',"Accept HIT"];
  805. var row = text_area.createTHead().insertRow(0);
  806. text_area.caption.style.fontWeight = 800;
  807. text_area.caption.style.color = BROWN;
  808. if (default_text_size > 10)
  809. text_area.cellPadding=Math.min(Math.max(1,Math.floor((default_text_size-10)/2)),5);
  810. //console.log(text_area.cellPadding);
  811. //text_area.cellPadding=2;
  812. text_area.caption.style.fontSize = 28;
  813. text_area.rows[0].style.fontWeight = 800;
  814. text_area.rows[0].style.color = BROWN;
  815. for (i=0; i<col_heads.length; i++)
  816. {
  817. var this_cell = row.insertCell(i);
  818. this_cell.innerHTML = col_heads[i];
  819. this_cell.style.fontSize = 14;
  820. if (i > 1)
  821. this_cell.style.textAlign = 'center';
  822. }
  823. control_panel.appendChild(text_area);
  824. }
  825.  
  826. /********HIT EXPORT ADDITIONS*****/
  827.  
  828. var EDIT = false;
  829. var HIT;
  830.  
  831. var TO_BASE = "http://turkopticon.ucsd.edu/";
  832. var API_BASE = "https://api.turkopticon.istrack.in/";
  833. var API_URL = API_BASE + "multi-attrs.php?ids=";
  834. DEFAULT_TEMPLATE = '[table][tr][td][b]Title:[/b] [url={prev_link}][COLOR=blue]{title}[/COLOR][/url]\n';
  835. DEFAULT_TEMPLATE += '[b]Requester:[/b] [url=https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId={rid}][COLOR=blue]{requester}[/COLOR][/url]';
  836. DEFAULT_TEMPLATE += ' [{rid}] ([url='+TO_BASE+'{rid}][COLOR=blue]TO[/COLOR][/url])';
  837. DEFAULT_TEMPLATE += '\n[b]TO Ratings:[/b]{to_stuff}';
  838. DEFAULT_TEMPLATE += '\n[b]Description:[/b] {description}';
  839. DEFAULT_TEMPLATE += '\n[b]Time:[/b] {time}';
  840. DEFAULT_TEMPLATE += '\n[b]Reward:[/b] [COLOR=green][b]{reward}[/b][/COLOR]';
  841. DEFAULT_TEMPLATE += '\n[b]Qualifications:[/b] {quals}[/td][/tr][/table]';
  842.  
  843. var TEMPLATE;
  844. var EASYLINK;
  845.  
  846. if (typeof GM_getValue === 'undefined')
  847. TEMPLATE = null;
  848. else {
  849. TEMPLATE = GM_getValue('HITScraper Template');
  850. EASYLINK = GM_getValue('HITScraper Easylink');
  851. }
  852. if (TEMPLATE == null) {
  853. TEMPLATE = DEFAULT_TEMPLATE;
  854. }
  855.  
  856. function buildXhrUrl(rai) {
  857. var url = API_URL;
  858. var ri = rai;
  859. url += rai;
  860. return url;
  861. }
  862.  
  863. function makeXhrQuery(url) {
  864. var xhr = new XMLHttpRequest();
  865. try{
  866. xhr.open('GET', url, false);
  867. xhr.send(null);
  868. return $.parseJSON(xhr.response);
  869. }
  870. catch(err){
  871. return "TO DOWN";
  872. }
  873. }
  874.  
  875. function getNamesForEmptyResponses(rai, resp) {
  876. for (var rid in rai) {
  877. if (rai.hasOwnProperty(rid) && resp[rid] == "") {
  878. resp[rid] = $.parseJSON('{"name": "' + rai[rid][0].innerHTML + '"}');
  879. }
  880. }
  881. return resp;
  882. }
  883.  
  884. function getKeys(obj) {
  885. var keys = [];
  886. for (var key in obj) {
  887. keys.push(key);
  888. }
  889. return keys;
  890. }
  891.  
  892. function export_func_deleg(item,index) {
  893. //console.log(item);
  894. export_func(item);
  895. }
  896.  
  897. function block_deleg(item,index) {
  898. //console.log(item);
  899. block(item);
  900. }
  901.  
  902. function block(hit){
  903. var requester = hit["requester"];
  904. ignore_list.push(requester);
  905. GM_setValue("scraper_ignore_list",ignore_list);
  906. console.log(GM_getValue("scraper_ignore_list"));
  907. alert(requester+" ignored. Re-scrape");
  908. }
  909.  
  910. function export_func(item) {
  911. HIT = item;
  912. edit_button.textContent = 'Edit Template';
  913. apply_template(item);
  914. div.style.display = 'block';
  915. textarea.select();
  916. }
  917.  
  918. function apply_template(hit_data) {
  919. var txt = TEMPLATE;
  920.  
  921. var vars = ['title', 'requester', 'rid', 'description', 'reward', 'quals', 'prev_link', 'time', 'hits', 'to_stuff', 'to_text'];
  922.  
  923. var resp = null;
  924. if (txt.indexOf('{to_text}') >= 0 || txt.indexOf('{to_stuff}') >= 0){
  925. var url = buildXhrUrl(hit_data["rid"]);
  926. resp = makeXhrQuery(url);
  927. //console.log(resp);
  928. }
  929. var toText = "";
  930. var toStuff = "";
  931. var toData = "";
  932. var numResp = (resp == null || resp == "TO DOWN" ? "n/a" : resp[hit_data["rid"]].reviews);
  933. if (resp == "TO DOWN"){
  934. toStuff = " [URL=\""+TO_BASE+hit_data['rid']+"\"]TO down.[/URL]";
  935. toText = toStuff;
  936. }
  937. else if (resp == null || resp[hit_data["rid"]].attrs == null && resp != "TO DOWN") {
  938. toStuff = " No TO ";
  939. toText = " No TO ";
  940. toStuff += "[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"]";
  941. toStuff += "(Submit a new TO rating for this requester)[/URL]";
  942. }
  943. else {
  944. for (var key in resp[hit_data["rid"]].attrs) {
  945. //toText += "\n[*]"+key+": "+resp[hit_data["requesterId"]].attrs[key]+"\n";
  946. var i = 0;
  947. var color = "green";
  948. var name = key;
  949. var num = Math.floor(resp[hit_data["rid"]].attrs[key]);
  950. switch (key){
  951. case "comm":
  952. name = "Communicativity";
  953. break;
  954. case "pay":
  955. name = "Generosity";
  956. break;
  957. case "fast":
  958. name = "Promptness";
  959. break;
  960. case "fair":
  961. name = "Fairness";
  962. break;
  963. default:
  964. name = key;
  965. break;
  966. }
  967. switch (num){
  968. case 0:
  969. color = "red";
  970. break;
  971. case 1:
  972. color = "red";
  973. break;
  974. case 2:
  975. color = "orange";
  976. break;
  977. case 3:
  978. color = "yellow";
  979. break;
  980. default:
  981. break;
  982. }
  983. toText += (num > 0 ? "\n[color="+color+"]" : "\n");
  984. for (i; i < num; i++){
  985. toText += "[b]"+symbol+"[/b]"
  986. }
  987. toText += (num > 0 ? "[/color]" : "")
  988. if (i < 5){
  989. toText += "[color=white]";
  990. for (i; i < 5; i++)
  991. toText += "[b]"+symbol+"[/b]";
  992. toText += "[/color]";
  993. }
  994. toText += " "+Number(resp[hit_data["rid"]].attrs[key]).toFixed(2)+" "+name;
  995. toData += Number(resp[hit_data["rid"]].attrs[key]).toFixed(2) + ",";
  996. }
  997. //toText += "[/list]";
  998. toText += (txt.indexOf('{to_stuff}') >= 0 ? "" : "\nNumber of Reviews: "+numResp+"\n[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"](Submit a new TO rating for this requester)[/URL]");
  999. toStuff = '\n[img]http://data.istrack.in/to/' + toData.slice(0,-1) + '.png[/img]';
  1000. toStuff += (txt.indexOf('{to_stuff}') >= 0 ? (txt.indexOf('{to_text}') >= 0 ? "" : toText) : "");
  1001. toStuff += "\nNumber of Reviews: "+numResp;
  1002. toStuff += "[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"]";
  1003. toStuff += "\n(Submit a new TO rating for this requester)[/URL]";
  1004. }
  1005. for (var i = 0; i < vars.length; i++) {
  1006. t = new RegExp('\{' + vars[i] + '\}', 'g');
  1007. if (vars[i] == "to_stuff") {
  1008. txt = txt.replace(t, toStuff);
  1009. }
  1010. else if (vars[i] == "to_text"){
  1011. txt = txt.replace(t, toText);
  1012. }
  1013. else if (vars[i] == "prev_link"){
  1014. txt = txt.replace(t,"https://www.mturk.com"+hit_data[vars[i]]);
  1015. }
  1016. else if (vars[i] == "acc_link"){
  1017. txt = txt.replace(t,"https://www.mturk.com"+hit_data[vars[i]]);
  1018. }
  1019. else
  1020. txt = txt.replace(t, hit_data[vars[i]]);
  1021. }
  1022. textarea.value = txt;
  1023. }
  1024.  
  1025. function hide_func(div) {
  1026. if (EDIT == false)
  1027. div.style.display = 'none';
  1028. }
  1029.  
  1030. function edit_func() {
  1031. if (EDIT == true) {
  1032. EDIT = false;
  1033. TEMPLATE = textarea.value;
  1034. edit_button.textContent = 'Edit Template';
  1035. apply_template(HIT);
  1036. }
  1037. else {
  1038. console.log("Editing");
  1039. EDIT = true;
  1040. edit_button.textContent = 'Show Changes';
  1041. save_button.disabled = false;
  1042. textarea.value = TEMPLATE;
  1043. }
  1044. }
  1045.  
  1046. function default_func() {
  1047. GM_deleteValue('HITScraper Template');
  1048. TEMPLATE = DEFAULT_TEMPLATE;
  1049. EDIT = false;
  1050. edit_button.textContent = 'Edit Template';
  1051. apply_template(HIT);
  1052. }
  1053.  
  1054. function save_func() {
  1055. if (EDIT)
  1056. TEMPLATE = textarea.value;
  1057. GM_setValue('HITScraper Template', TEMPLATE);
  1058. }
  1059.  
  1060. var div = document.createElement('div');
  1061. var textarea = document.createElement('textarea');
  1062. var div2 = document.createElement('label');
  1063.  
  1064. div.style.position = 'fixed';
  1065. div.style.width = '500px';
  1066. div.style.height = '235px';
  1067. div.style.left = '50%';
  1068. div.style.right = '50%';
  1069. div.style.margin = '-250px 0px 0px -250px';
  1070. div.style.top = '300px';
  1071. div.style.padding = '5px';
  1072. div.style.border = '2px';
  1073. div.style.backgroundColor = 'black';
  1074. div.style.color = 'white';
  1075. div.style.zIndex = '100';
  1076.  
  1077. textarea.style.padding = '2px';
  1078. textarea.style.width = '500px';
  1079. textarea.style.height = '200px';
  1080. textarea.title = '{title}\n{requester}\n{rid}\n{description}\n{reward}\n{quals}\n{prev_link}\n{time}\n{hit}\n{to_stuff}\n{to_text}';
  1081.  
  1082. div.textContent = 'Press Ctrl+C to copy to clipboard. Click textarea to close';
  1083. div.style.fontSize = '12px';
  1084. div.appendChild(textarea);
  1085.  
  1086. var edit_button = document.createElement('button');
  1087. var save_button = document.createElement('button');
  1088. var default_button = document.createElement('button');
  1089. var easy_button = document.createElement('button');
  1090.  
  1091. edit_button.textContent = 'Edit Template';
  1092. edit_button.setAttribute('id', 'edit_button');
  1093. edit_button.style.height = '18px';
  1094. edit_button.style.width = '100px';
  1095. edit_button.style.fontSize = '10px';
  1096. edit_button.style.paddingLeft = '3px';
  1097. edit_button.style.paddingRight = '3px';
  1098. edit_button.style.backgroundColor = 'white';
  1099.  
  1100. save_button.textContent = 'Save Template';
  1101. save_button.setAttribute('id', 'save_button');
  1102. save_button.style.height = '18px';
  1103. save_button.style.width = '100px';
  1104. save_button.style.fontSize = '10px';
  1105. save_button.style.paddingLeft = '3px';
  1106. save_button.style.paddingRight = '3px';
  1107. save_button.style.backgroundColor = 'white';
  1108. save_button.style.marginLeft = '5px';
  1109.  
  1110. easy_button.textContent = 'Change Adfly Url';
  1111. easy_button.setAttribute('id', 'easy_button');
  1112. easy_button.style.height = '18px';
  1113. easy_button.style.width = '100px';
  1114. easy_button.style.fontSize = '10px';
  1115. easy_button.style.paddingLeft = '3px';
  1116. default_button.textContent = ' D ';
  1117. default_button.setAttribute('id', 'default_button');
  1118. default_button.style.height = '18px';
  1119. default_button.style.width = '20px';
  1120. default_button.style.fontSize = '10px';
  1121. default_button.style.paddingLeft = '3px';
  1122. default_button.style.paddingRight = '3px';
  1123. default_button.style.backgroundColor = 'white';
  1124. default_button.style.marginLeft = '5px';
  1125. default_button.title = 'Return default template';
  1126. div.appendChild(edit_button);
  1127. div.appendChild(save_button);
  1128. div.appendChild(default_button);
  1129. div.appendChild(easy_button);
  1130. save_button.disabled = true;
  1131.  
  1132. div.style.display = 'none';
  1133. textarea.addEventListener("click", function() {hide_func(div);}, false);
  1134. edit_button.addEventListener("click", function() {edit_func();}, false);
  1135. save_button.addEventListener("click", function() {save_func();}, false);
  1136. default_button.addEventListener("click", function() {default_func();}, false);
  1137. document.body.insertBefore(div, document.body.firstChild);