HIT Scraper WITH EXPORT

Snag HITs.

目前為 2015-02-16 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name HIT Scraper WITH EXPORT
  3. // @author Kerek, TJ, and clickhappier
  4. // @description Snag HITs.
  5. // Based in part on code from mmmturkeybacon Export Mturk History and mmmturkeybacon Color Coded Search with Checkpoints
  6. // @namespace https://greasyfork.org/users/710
  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.5.9
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_setClipboard
  12. // @require http://code.jquery.com/jquery-latest.min.js
  13. // ==/UserScript==
  14.  
  15. //Fixes it soas not to rely on GM's storage schemes
  16. if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
  17. this.GM_getValue=function (key,def) {
  18. return localStorage[key] || def;
  19. };
  20. this.GM_setValue=function (key,value) {
  21. return localStorage[key]=value;
  22. };
  23. this.GM_deleteValue=function (key) {
  24. return localStorage.removeItem(key);
  25. };
  26. }
  27.  
  28. //alter the requester ignore last as you desire, case insensitive
  29. var default_list = ["oscar smith", "Diamond Tip Research LLC", "jonathon weber", "jerry torres", "Crowdsource", "we-pay-you-fast", "turk experiment", "jon brelig"];
  30. var ignore_list = default_list;
  31. if (GM_getValue("scraper_ignore_list"))
  32. ignore_list = GM_getValue("scraper_ignore_list").split('^');
  33. else
  34. GM_setValue("scraper_ignore_list", default_list.join('^'));
  35.  
  36. var include_list = [];
  37. if (GM_getValue("scraper_include_list"))
  38. include_list = GM_getValue("scraper_include_list").split('^');
  39.  
  40. //This is to update the hit export symbol
  41. var symbol = "☭";
  42.  
  43. //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.
  44. var correct_for_skips = true;
  45.  
  46. //weight the four TO ratings for the coloring. Default has pay twice as important as fairness and nothing for communication and fast.
  47. var COMM_WEIGHT = 0;
  48. var PAY_WEIGHT = 10;
  49. var FAIR_WEIGHT = 5;
  50. var FAST_WEIGHT = 0;
  51.  
  52. //Used for themeing, change the colors to change how scraper looks
  53. var GREEN = '#66CC66'; // > 4
  54. var LIGHTGREEN = '#ADFF2F'; // > 3 GREEN YELLOW
  55. var YELLOW = '#FFD700'; //Not used
  56. var ORANGE = '#FF9900'; // > 2
  57. var RED = '#FF3030'; // <= 2
  58. var BLUE = '#C0D9D9'; // no TO
  59. var GREY = 'lightGrey'; //TO down
  60. var BROWN = '#94704D'; //Font color
  61. var DARKGREY = '#9F9F9F'; //No HITDB, "Not Qualified" column
  62. var BACKGROUND_COLOR = "rgb(19, 19, 19)"; //Background of page
  63.  
  64. //display your hitdb records if applicable
  65. var check_hitDB = true;
  66.  
  67. //default text size
  68. var default_text_size=11;
  69.  
  70. //set to "true" to override checkbox setting and ding on new hits
  71. var newHitDing = false;
  72.  
  73. //DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
  74.  
  75. var status_text = "None";
  76. var shouldDing = false;
  77. var audio = document.createElement('audio');
  78. document.body.appendChild(audio);
  79. audio.src = 'data:audio/ogg;base64,T2dnUwACAAAAAAAAAAB8mpoRAAAAAFLKt9gBHgF2b3JiaXMAAAAAARErAAAAAAAAkGUAAAAAAACZAU9nZ1MAAAAAAAAAAAAAfJqaEQEAAACHYsq6Cy3///////////+1A3ZvcmJpcx0AAABYaXBoLk9yZyBsaWJWb3JiaXMgSSAyMDA1MDMwNAAAAAABBXZvcmJpcxJCQ1YBAAABAAxSFCElGVNKYwiVUlIpBR1jUFtHHWPUOUYhZBBTiEkZpXtPKpVYSsgRUlgpRR1TTFNJlVKWKUUdYxRTSCFT1jFloXMUS4ZJCSVsTa50FkvomWOWMUYdY85aSp1j1jFFHWNSUkmhcxg6ZiVkFDpGxehifDA6laJCKL7H3lLpLYWKW4q91xpT6y2EGEtpwQhhc+211dxKasUYY4wxxsXiUyiC0JBVAAABAABABAFCQ1YBAAoAAMJQDEVRgNCQVQBABgCAABRFcRTHcRxHkiTLAkJDVgEAQAAAAgAAKI7hKJIjSZJkWZZlWZameZaouaov+64u667t6roOhIasBADIAAAYhiGH3knMkFOQSSYpVcw5CKH1DjnlFGTSUsaYYoxRzpBTDDEFMYbQKYUQ1E45pQwiCENInWTOIEs96OBi5zgQGrIiAIgCAACMQYwhxpBzDEoGIXKOScggRM45KZ2UTEoorbSWSQktldYi55yUTkompbQWUsuklNZCKwUAAAQ4AAAEWAiFhqwIAKIAABCDkFJIKcSUYk4xh5RSjinHkFLMOcWYcowx6CBUzDHIHIRIKcUYc0455iBkDCrmHIQMMgEAAAEOAAABFkKhISsCgDgBAIMkaZqlaaJoaZooeqaoqqIoqqrleabpmaaqeqKpqqaquq6pqq5seZ5peqaoqp4pqqqpqq5rqqrriqpqy6ar2rbpqrbsyrJuu7Ks256qyrapurJuqq5tu7Js664s27rkearqmabreqbpuqrr2rLqurLtmabriqor26bryrLryratyrKua6bpuqKr2q6purLtyq5tu7Ks+6br6rbqyrquyrLu27au+7KtC7vourauyq6uq7Ks67It67Zs20LJ81TVM03X9UzTdVXXtW3VdW1bM03XNV1XlkXVdWXVlXVddWVb90zTdU1XlWXTVWVZlWXddmVXl0XXtW1Vln1ddWVfl23d92VZ133TdXVblWXbV2VZ92Vd94VZt33dU1VbN11X103X1X1b131htm3fF11X11XZ1oVVlnXf1n1lmHWdMLqurqu27OuqLOu+ruvGMOu6MKy6bfyurQvDq+vGseu+rty+j2rbvvDqtjG8um4cu7Abv+37xrGpqm2brqvrpivrumzrvm/runGMrqvrqiz7uurKvm/ruvDrvi8Mo+vquirLurDasq/Lui4Mu64bw2rbwu7aunDMsi4Mt+8rx68LQ9W2heHVdaOr28ZvC8PSN3a+AACAAQcAgAATykChISsCgDgBAAYhCBVjECrGIIQQUgohpFQxBiFjDkrGHJQQSkkhlNIqxiBkjknIHJMQSmiplNBKKKWlUEpLoZTWUmotptRaDKG0FEpprZTSWmopttRSbBVjEDLn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RSSimllFJKqKOUUkoppZRSAiGllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimVUkoppZRSSimllFJKKaUAIN8KBwD/BxtnWEk6KxwNLjRkJQAQDgAAGMMYhIw5JyWlhjEIpXROSkklNYxBKKVzElJKKYPQWmqlpNJSShmElGILIZWUWgqltFZrKam1lFIoKcUaS0qppdYy5ySkklpLrbaYOQelpNZaaq3FEEJKsbXWUmuxdVJSSa211lptLaSUWmstxtZibCWlllprqcXWWkyptRZbSy3G1mJLrcXYYosxxhoLAOBucACASLBxhpWks8LR4EJDVgIAIQEABDJKOeecgxBCCCFSijHnoIMQQgghREox5pyDEEIIIYSMMecghBBCCKGUkDHmHIQQQgghhFI65yCEUEoJpZRSSucchBBCCKWUUkoJIYQQQiillFJKKSGEEEoppZRSSiklhBBCKKWUUkoppYQQQiillFJKKaWUEEIopZRSSimllBJCCKGUUkoppZRSQgillFJKKaWUUkooIYRSSimllFJKCSWUUkoppZRSSikhlFJKKaWUUkoppQAAgAMHAIAAI+gko8oibDThwgMQAAAAAgACTACBAYKCUQgChBEIAAAAAAAIAPgAAEgKgIiIaOYMDhASFBYYGhweICIkAAAAAAAAAAAAAAAABE9nZ1MABAgkAAAAAAAAfJqaEQIAAAB89IOyJjhEQUNNRE5TRENHS0xTRllHSEpISUdORk1GSEdISUNHP0ZHS1IhquPYHv5OAgC/7wFATp2pUBdXuyHsT4XRISOWEsj9QgEA7CC99FBIaDsrM+hbibFaAl81wg+vGnum4/p5roRKJAAAQFGOdsUy794bb3kbX50b8wL0NECgHlr67FRjAIAlBqKQyl55KU64p02UMHrBl0yZbWiGBSJYvJwiAaLj+vfck0gAnrsDAJV8Gl9y2ovHlFW+iSn7ZmRlQAb9lx4A4hz/EEPP9W5bRn5ldI8wU4fR+xS3ZLKtvYvVL687nuL6t9yTeAC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8vqOL44wn79D/pIETNBW/AzzX9681U4DJzb4PYDesvZ34xswFUCkGrRAGD1Nx4AeF4pACxWbrDxrjgDwBwF';
  80. audio.setAttribute("id", "ding_noise");
  81. audio.volume = 1;
  82.  
  83. function newHits(dingNoise) {
  84. console.log(dingNoise);
  85. if (dingNoise || newHitDing)
  86. document.getElementById("ding_noise").play();
  87. }
  88.  
  89. //For editing the blocklist
  90. var div = document.createElement('div');
  91. var textarea = document.createElement('textarea');
  92.  
  93. div.style.position = 'fixed';
  94. div.style.width = '500px';
  95. div.style.height = '235px';
  96. div.style.left = '50%';
  97. div.style.right = '50%';
  98. div.style.margin = '-250px 0px 0px -250px';
  99. div.style.top = '300px';
  100. div.style.padding = '5px';
  101. div.style.border = '2px';
  102. div.style.backgroundColor = 'black';
  103. div.style.color = 'white';
  104. div.style.zIndex = '100';
  105. div.setAttribute('id','block_div');
  106.  
  107. textarea.style.padding = '2px';
  108. textarea.style.width = '500px';
  109. textarea.style.height = '180px';
  110. textarea.title = 'Block list';
  111. textarea.setAttribute('id','block_text');
  112.  
  113. div.textContent = 'Change the blocklist to be whatever you like, save to save it. Separate requesters with the ^ character. After clicking "Save", you\'ll need to scrape again to apply the changes.';
  114. div.style.fontSize = '12px';
  115. div.appendChild(textarea);
  116.  
  117. var save_button = document.createElement('button');
  118. var cancel_button = document.createElement('button');
  119.  
  120. save_button.textContent = 'Save';
  121. save_button.setAttribute('id', 'save_blocklist');
  122. save_button.style.height = '18px';
  123. save_button.style.width = '100px';
  124. save_button.style.fontSize = '10px';
  125. save_button.style.paddingLeft = '3px';
  126. save_button.style.paddingRight = '3px';
  127. save_button.style.backgroundColor = 'white';
  128. save_button.style.marginLeft = '5px';
  129.  
  130. cancel_button.textContent = 'Cancel';
  131. cancel_button.setAttribute('id', 'cancel_blocklist');
  132. cancel_button.style.height = '18px';
  133. cancel_button.style.width = '100px';
  134. cancel_button.style.fontSize = '10px';
  135. cancel_button.style.paddingLeft = '3px';
  136. cancel_button.style.paddingRight = '3px';
  137. cancel_button.style.backgroundColor = 'white';
  138. cancel_button.style.marginLeft = '5px';
  139.  
  140.  
  141. div.appendChild(save_button);
  142. div.appendChild(cancel_button);
  143.  
  144. $("#block_div").hide();
  145. save_button.addEventListener("click", function() {save_blocklist();}, false);
  146. cancel_button.addEventListener("click", function() {$("#block_div").hide();}, false);
  147. document.body.insertBefore(div, document.body.firstChild);
  148.  
  149. //For editing the include list
  150. var shouldInclude = false;
  151. var div2 = document.createElement('div');
  152. var textarea2 = document.createElement('textarea');
  153.  
  154. div2.style.position = 'fixed';
  155. div2.style.width = '500px';
  156. div2.style.height = '235px';
  157. div2.style.left = '50%';
  158. div2.style.right = '50%';
  159. div2.style.margin = '-250px 0px 0px -250px';
  160. div2.style.top = '300px';
  161. div2.style.padding = '5px';
  162. div2.style.border = '2px';
  163. div2.style.backgroundColor = 'black';
  164. div2.style.color = 'white';
  165. div2.style.zIndex = '100';
  166. div2.setAttribute('id','include_div');
  167.  
  168. textarea2.style.padding = '2px';
  169. textarea2.style.width = '500px';
  170. textarea2.style.height = '180px';
  171. textarea2.title = 'include list';
  172. textarea2.setAttribute('id','include_text');
  173.  
  174. div2.textContent = 'Used if you only want to see certain requesters. Separator is ^. Only takes effect if \"Use includelist\" is checked.';
  175. div2.style.fontSize = '12px';
  176. div2.appendChild(textarea2);
  177.  
  178. var save_button2 = document.createElement('button');
  179. var cancel_button2 = document.createElement('button');
  180.  
  181. save_button2.textContent = 'Save';
  182. save_button2.setAttribute('id', 'save_includelist');
  183. save_button2.style.height = '18px';
  184. save_button2.style.width = '100px';
  185. save_button2.style.fontSize = '10px';
  186. save_button2.style.paddingLeft = '3px';
  187. save_button2.style.paddingRight = '3px';
  188. save_button2.style.backgroundColor = 'white';
  189. save_button2.style.marginLeft = '5px';
  190.  
  191. cancel_button2.textContent = 'Cancel';
  192. cancel_button2.setAttribute('id', 'cancel_includelist');
  193. cancel_button2.style.height = '18px';
  194. cancel_button2.style.width = '100px';
  195. cancel_button2.style.fontSize = '10px';
  196. cancel_button2.style.paddingLeft = '3px';
  197. cancel_button2.style.paddingRight = '3px';
  198. cancel_button2.style.backgroundColor = 'white';
  199. cancel_button2.style.marginLeft = '5px';
  200.  
  201. div2.appendChild(save_button2);
  202. div2.appendChild(cancel_button2);
  203.  
  204. $("#include_div").hide();
  205. save_button2.addEventListener("click", function() {save_includelist();}, false);
  206. cancel_button2.addEventListener("click", function() {$("#include_div").hide();}, false);
  207. document.body.insertBefore(div2, document.body.firstChild);
  208.  
  209. function save_blocklist() {
  210. console.log("Save");
  211. var textarea = $("#block_text");
  212. var text = textarea.val();
  213. var block_list = text.split("^");
  214. var trimmed_list = [];
  215. for (var requester in block_list){
  216. if (block_list[requester].trim().length != 0)
  217. trimmed_list.push(block_list[requester].toLowerCase().trim());
  218. }
  219. console.log(trimmed_list);
  220. GM_setValue("scraper_ignore_list",trimmed_list.join('^'));
  221. ignore_list = GM_getValue("scraper_ignore_list").split('^');
  222. console.log("Save complete: ");
  223. console.log(ignore_list);
  224. $("#block_div").hide();
  225. }
  226.  
  227. function save_includelist() {
  228. console.log("Save");
  229. var textarea = $("#include_text");
  230. var text = textarea.val();
  231. var includes = text.split("^");
  232. console.log(includes);
  233. var trimmed_list = [];
  234. for (var requester in includes){
  235. if (includes[requester].trim().length != 0)
  236. trimmed_list.push(includes[requester].toLowerCase().trim());
  237. }
  238. GM_setValue("scraper_include_list",trimmed_list.join('^'));
  239. include_list = GM_getValue("scraper_include_list").split('^');
  240. console.log(include_list);
  241. $("#include_div").hide();
  242. }
  243.  
  244. var HITStorage = {};
  245. var indexedDB = window.indexedDB || window.webkitIndexedDB ||
  246. window.mozIndexedDB;
  247. window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.mozIDBTransaction;
  248. window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.mozIDBKeyRange;
  249. HITStorage.IDBTransactionModes = { "READ_ONLY": "readonly", "READ_WRITE": "readwrite", "VERSION_CHANGE": "versionchange" };
  250. var IDBKeyRange = window.IDBKeyRange;
  251.  
  252. HITStorage.indexedDB = {};
  253. HITStorage.indexedDB = {};
  254. HITStorage.indexedDB.db = null;
  255.  
  256. HITStorage.indexedDB.onerror = function(e) {
  257. console.log(e);
  258. };
  259.  
  260. var v=4;
  261.  
  262. HITStorage.indexedDB.checkTitle = function(title,button) {
  263. var request = indexedDB.open("HITDB", v);
  264. request.onsuccess = function(e) {
  265. HITStorage.indexedDB.db = e.target.result;
  266. var db = HITStorage.indexedDB.db;
  267. if (!db.objectStoreNames.contains("HIT"))
  268. {
  269. db.close();
  270. return;
  271. }
  272. var trans = db.transaction(["HIT"], HITStorage.IDBTransactionModes.READ_ONLY);
  273. var store = trans.objectStore("HIT");
  274. var index = store.index("title");
  275. index.get(title).onsuccess = function(event)
  276. {
  277. if (event.target.result === undefined)
  278. {
  279. console.log(title + ' not found');
  280. history[button].titledb=false;
  281. }
  282. else
  283. {
  284. console.log(title + ' found');
  285. history[button].titledb=true;
  286. }
  287. db.close();
  288. };
  289. };
  290. request.onerror = HITStorage.indexedDB.onerror;
  291. };
  292.  
  293. HITStorage.indexedDB.checkRequester = function(id,button) {
  294. var request = indexedDB.open("HITDB", v);
  295. request.onsuccess = function(e) {
  296. HITStorage.indexedDB.db = e.target.result;
  297. var db = HITStorage.indexedDB.db;
  298. if (!db.objectStoreNames.contains("HIT"))
  299. {
  300. db.close();
  301. return;
  302. }
  303. var trans = db.transaction(["HIT"], HITStorage.IDBTransactionModes.READ_ONLY);
  304. var store = trans.objectStore("HIT");
  305. var index = store.index("requesterId");
  306. index.get(id).onsuccess = function(event)
  307. {
  308. if (event.target.result === undefined)
  309. {history[button].reqdb=false;
  310. console.log(id + ' not found');
  311. }
  312. else
  313. {
  314. history[button].reqdb=true;
  315. console.log(id + ' found');
  316. }
  317. db.close();
  318. };
  319. };
  320. request.onerror = HITStorage.indexedDB.onerror;
  321. };
  322.  
  323. var PAGES_TO_SCRAPE = 3;
  324. var MINIMUM_HITS = 100;
  325. var SEARCH_REFRESH=0;
  326. var URL_BASE = "/mturk/searchbar?searchWords=&selectedSearchType=hitgroups";
  327. var initial_url = URL_BASE;
  328. var TO_REQ_URL = "http://turkopticon.ucsd.edu/reports?id=";
  329. var found_key_list=[];
  330. var last_clear_time = new Date().getTime();
  331. var searched_once = false;
  332. var save_new_results_time = 120;
  333. var save_results_time = 3600;
  334. var default_type = 0;
  335. var cur_loc = window.location.href;
  336. var time_input = document.createElement("INPUT");
  337. time_input.value = 0;
  338. var page_input = document.createElement("INPUT");
  339. page_input.value = 3;
  340. var min_input = document.createElement("INPUT");
  341. var new_time_display_input = document.createElement("INPUT");
  342. new_time_display_input.value = 300;
  343. var reward_input = document.createElement("INPUT");
  344. var qual_input = document.createElement("INPUT");
  345. qual_input.type = "checkbox";
  346. if (!document.getElementById('lnkWorkerSignin'))
  347. qual_input.checked = true;
  348. var masters_input = document.createElement("INPUT");
  349. masters_input.type = "checkbox";
  350. var sort_input1 = document.createElement("INPUT");
  351. sort_input1.type = "radio";
  352. sort_input1.name = "sort_type";
  353. sort_input1.value = "latest";
  354. sort_input1.checked = true;
  355. var sort_input2 = document.createElement("INPUT");
  356. sort_input2.type = "radio";
  357. sort_input2.name = "sort_type";
  358. sort_input2.value = "most";
  359. var sort_input3 = document.createElement("INPUT");
  360. sort_input3.type = "radio";
  361. sort_input3.name = "sort_type";
  362. sort_input3.value = "amount";
  363. var sort_input4 = document.createElement("INPUT");
  364. sort_input4.type = "radio";
  365. sort_input4.name = "sort_type";
  366. sort_input4.value = "A-Z";
  367. var sort_input_invert = document.createElement("INPUT");
  368. sort_input_invert.type = "checkbox";
  369. var friesAreDone = document.createElement("INPUT");
  370. friesAreDone.type = "checkbox";
  371. var correctForSkips = document.createElement("INPUT");
  372. correctForSkips.type = "checkbox";
  373. correctForSkips.checked = true;
  374. var matchOnly = document.createElement("INPUT");
  375. matchOnly.type = "checkbox";
  376.  
  377. var search_input = document.createElement("INPUT");
  378.  
  379. var LINK_BASE = "https://www.mturk.com";
  380. var STATUSDETAIL_DELAY = 250;
  381. var MPRE_DELAY = 3000;
  382.  
  383. $('body').css('background', BACKGROUND_COLOR);
  384.  
  385. var next_page = 1;
  386.  
  387. var API_PROXY_BASE = 'https://mturk-api.istrack.in/';
  388. var API_MULTI_ATTRS_URL = API_PROXY_BASE + 'multi-attrs.php?ids=';
  389. var REVIEWS_BASE = 'http://turkopticon.ucsd.edu/';
  390.  
  391. var control_panel_HTML = '<div id="control_panel" style="margin: 0 auto 0 auto;' +
  392. 'border-bottom: 1px solid #000000; margin-bottom: 5px; ' +
  393. 'background-color: ' + BACKGROUND_COLOR + ';"></div>';
  394. $('body > :not(#control_panel)').hide(); //hide all nodes directly under the body
  395. $('body').prepend(control_panel_HTML);
  396.  
  397. var control_panel = document.getElementById("control_panel");
  398. var big_red_button = document.createElement("BUTTON");
  399. var reset_blocks = document.createElement("BUTTON");
  400. var include_button = document.createElement("BUTTON");
  401. var progress_report = document.createTextNode("Stopped");
  402. var status_report = document.createTextNode("None");
  403. var text_area = document.createElement("TABLE");
  404. big_red_button.textContent = "Show Interface";
  405. big_red_button.onclick = function(){show_interface();};
  406. control_panel.appendChild(big_red_button);
  407.  
  408. show_interface();
  409.  
  410. var global_run = false;
  411. var statusdetail_loop_finished = false;
  412. var date_header = "";
  413. var history = {};
  414. var wait_loop;
  415.  
  416. function set_progress_report(text, force)
  417. {
  418. if (global_run == true || force == true)
  419. {
  420. progress_report.textContent = text;
  421. status_report.textContent = status_text;
  422. }
  423. }
  424.  
  425. function get_progress_report()
  426. {
  427. return progress_report.textContent;
  428. }
  429.  
  430. function wait_until_stopped()
  431. {
  432. if (global_run == true)
  433. {
  434. if (statusdetail_loop_finished == true)
  435. {
  436. big_red_button.textContent = "Start";
  437. set_progress_report("Finished", false);
  438. }
  439. else
  440. {
  441. setTimeout(function(){wait_until_stopped();}, 500);
  442. }
  443. }
  444. }
  445.  
  446. function display_wait_time(wait_time)
  447. {
  448. if (global_run == true)
  449. {
  450. var current_progress = get_progress_report();
  451. if (current_progress.indexOf("Searching again in")!==-1)
  452. {
  453. set_progress_report(current_progress.replace(/Searching again in \d+ seconds/ , "Searching again in " + wait_time + " seconds"),false);
  454. }
  455. else
  456. set_progress_report(current_progress + " Searching again in " + wait_time + " seconds.", false);
  457. if (wait_time>1)
  458. setTimeout(function(){display_wait_time(wait_time-1);}, 1000);
  459. }
  460. }
  461.  
  462. function dispArr(ar)
  463. {
  464. var disp = "";
  465. for (var z = 0; z < ar.length; z++)
  466. {
  467. disp += "id " + z + " is " + ar[z] + " ";
  468. }
  469. console.log(disp);
  470. }
  471.  
  472. function scrape($src)
  473. {
  474. var $requester = $src.find('a[href^="/mturk/searchbar?selectedSearchType=hitgroups&requester"]');
  475. var $title = $src.find('a[class="capsulelink"]');
  476. var $reward = $src.find('span[class="reward"]');
  477. var $preview = $src.find('a[href^="/mturk/preview?"]');
  478. var $qualified = $src.find('a[href^="/mturk/notqualified?"],a[id^="private_hit"]');
  479. var $times = $src.find('a[id^="duration_to_complete"]');
  480. var $descriptions = $src.find('a[id^="description"]');
  481. var not_qualified_group_IDs=[];
  482. var $quals = $src.find('a[id^="qualificationsRequired"]');
  483. $qualified.each(function(){
  484. var groupy = $(this).attr('href');
  485. if (groupy){
  486. groupy = groupy.replace(/\/mturk\/notqualified\?hitGroupId=([A-Z0-9]+)(&.+)?/,"$1");
  487. groupy = groupy.replace("/mturk/notqualified?hit","");
  488. }
  489. not_qualified_group_IDs.push(groupy);
  490. });
  491. var $mixed = $src.find('a[href^="/mturk/preview?"],a[href^="/mturk/notqualified?"],a[id^="private_hit"]');
  492. console.log($mixed);
  493. var listy =[];
  494. $mixed.each(function(){
  495. var groupy = $(this).attr('href');
  496. if (groupy)
  497. {
  498. groupy = groupy.replace(/\/mturk\/notqualified\?hitGroupId=([A-Z0-9]+)(&.+)?/,"$1");
  499. groupy = groupy.replace("/mturk/notqualified?hit","");
  500. groupy = groupy.replace("/mturk/preview?groupId=","");
  501. }
  502. listy.push(groupy);
  503. });
  504. //console.log(listy);
  505. //listy = listy.filter(function(elem, pos) {
  506. // return listy.indexOf(elem) == pos;
  507. //});
  508. //console.log(listy);
  509. for (var j = 0; j < $requester.length; j++)
  510. {
  511. var $hits = $requester.eq(j).parent().parent().parent().parent().parent().parent().find('td[class="capsule_field_text"]');
  512. var requester_name = $requester.eq(j).text().trim();
  513. var requester_link = $requester.eq(j).attr('href');
  514. var group_ID=(listy[j] ? listy[j].replace(/\/mturk\/notqualified\?hitGroupId=([A-Z0-9]+)(&.+)?/,"$1") : "");
  515. if (listy[j] && listy[j].indexOf("notqualified") > -1)
  516. noqual = true;
  517. group_ID=group_ID.replace("/mturk/notqualified?hit","");
  518. var masters = false;
  519. var title = $title.eq(j).text().trim();
  520. var preview_link = "/mturk/preview?groupId=" + group_ID;
  521. console.log(listy[j]);
  522. console.log(group_ID);
  523. if (!group_ID || group_ID.length == 0){
  524. preview_link = requester_link;
  525. title += " (Requester link substituted)";
  526. }
  527. var reward = $reward.eq(j).text().trim();
  528. var hits = $hits.eq(4).text().trim();
  529. var time = $times.eq(j).parent()[0].nextSibling.nextSibling.innerHTML;
  530. var description = $descriptions.eq(j).parent()[0].nextSibling.nextSibling.innerHTML;
  531. //console.log(description);
  532. var requester_id = requester_link.replace('/mturk/searchbar?selectedSearchType=hitgroups&requesterId=','');
  533. var accept_link;
  534. accept_link = preview_link.replace('preview','previewandaccept');
  535. /*HIT SCRAPER ADDITION*/
  536. var qElements = $quals.eq(j).parent().parent().parent().find('tr');
  537. //console.log(qElements);
  538. var qualifications = [];
  539. for (var i = 1; i < qElements.length; i++) {
  540. 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, ' ')));
  541. if (qElements[i].childNodes[1].textContent.trim().replace(/\s+/g, ' ').indexOf("Masters") != -1)
  542. masters=true;
  543. }
  544. var qualList = (qualifications.join(', ') ? qualifications.join(', ') : "None");
  545. key = requester_name+title+reward+group_ID;
  546. if (found_key_list.indexOf(key) == -1)
  547. found_key_list.push(key);
  548. else
  549. {
  550. console.log("DUPE: "+key);
  551. continue;
  552. }
  553. if (history[key] == undefined)
  554. {
  555. 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:"",masters:false};
  556. history[key].req_link = requester_link;
  557. history[key].prev_link = preview_link;
  558. history[key].requester = requester_name;
  559. history[key].title = title;
  560. history[key].reward = reward;
  561. history[key].hits = hits;
  562. history[key].rid = requester_id;
  563. history[key].acc_link = accept_link;
  564. history[key].time = time;
  565. history[key].quals = qualList;
  566. history[key].description = description;
  567. history[key].masters = masters;
  568. HITStorage.indexedDB.checkRequester(requester_id,key);
  569. HITStorage.indexedDB.checkTitle(title,key);
  570. if (searched_once)
  571. {
  572. history[key].initial_time = new Date().getTime();//-1000*(save_new_results_time - SEARCH_REFRESH);
  573. history[key].new_result = 0;
  574. }
  575. else
  576. {
  577. history[key].initial_time = new Date().getTime()-1000*save_new_results_time;
  578. history[key].new_result = 1000*save_new_results_time;
  579. }
  580. if (not_qualified_group_IDs.indexOf(group_ID)!==-1)
  581. history[key].qualified = false;
  582. else
  583. history[key].qualified = true;
  584. history[key].found_this_time = true;
  585. }
  586. else
  587. {
  588. history[key].new_result = new Date().getTime() - history[key].initial_time;
  589. history[key].found_this_time = true;
  590. history[key].hits = hits;
  591. }
  592. }
  593. }
  594.  
  595. function statusdetail_loop(next_URL)
  596. {
  597. if (global_run == true)
  598. {
  599. if (next_URL.length != 0)
  600. {
  601. $.get(next_URL, function(data)
  602. {
  603. var $src = $(data);
  604. var maxpagerate = $src.find('td[class="error_title"]:contains("You have exceeded the maximum allowed page request rate for this website.")');
  605. if (maxpagerate.length == 0)
  606. {
  607. if (next_page > PAGES_TO_SCRAPE)
  608. {
  609. if(status_text.indexOf("Correcting for skips") == -1)
  610. status_text += ". Correcting for skips";
  611. }
  612. set_progress_report("Processing page " + next_page, false);
  613. scrape($src);
  614. $next_URL = $src.find('a[href^="/mturk/viewsearchbar"]:contains("Next")');
  615. next_URL = ($next_URL.length != 0) ? $next_URL.attr("href") : "";
  616. next_page++;
  617. if (default_type == 1)
  618. {
  619. var hmin = MINIMUM_HITS+1;
  620. for (j = 0; j < found_key_list.length; j++)
  621. {
  622. console.log(history[found_key_list[j]]);
  623. if (history[found_key_list[j]].hits < hmin)
  624. {
  625. next_URL = "";
  626. next_page = -1;
  627. break;
  628. }
  629. }
  630. }
  631. else if (next_page > PAGES_TO_SCRAPE && correct_for_skips)
  632. {
  633. var skipped_hits = 0;
  634. var added_pages = 0;
  635. for (j = 0; j < found_key_list.length; j++)
  636. {
  637. var obj = history[found_key_list[j]];
  638. if (!ignore_check(obj.requester,obj.title))
  639. skipped_hits++;
  640. }
  641. added_pages = Math.floor(skipped_hits/10);
  642. if (skipped_hits%10 >6)
  643. added_pages++;
  644. if (next_page > PAGES_TO_SCRAPE + added_pages)
  645. {
  646. next_URL = "";
  647. next_page = -1;
  648. }
  649. }
  650. else if (next_page > PAGES_TO_SCRAPE)
  651. {
  652. next_URL = "";
  653. next_page = -1;
  654. }
  655. setTimeout(function(){statusdetail_loop(next_URL);}, STATUSDETAIL_DELAY);
  656. }
  657. else
  658. {
  659. console.log("MPRE");
  660. setTimeout(function(){statusdetail_loop(next_URL);}, MPRE_DELAY);
  661. }
  662. });
  663. }
  664. else
  665. {
  666. searched_once = true;
  667. var found_hits = found_key_list.length;
  668. var shown_hits = 0;
  669. var new_hits = 0;
  670. var url = API_MULTI_ATTRS_URL;
  671. var rids = [];
  672. var lastRow = text_area.rows.length - 1;
  673. for (i = lastRow; i>0; i--)
  674. text_area.deleteRow(i);
  675. for (j = 0; j < found_key_list.length; j++)
  676. {
  677. //(function(url,rids,j) {
  678. var obj = history[found_key_list[j]];
  679. if (ignore_check(obj.requester,obj.title) && obj.found_this_time){
  680. ++shown_hits;
  681. //console.log(obj);
  682. //hit export will update col_heads[1]
  683. 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>","M"];
  684. var row = text_area.insertRow(text_area.rows.length);
  685. url += obj.rid + ',';
  686. rids.push(obj.rid);
  687. if (check_hitDB)
  688. {
  689. col_heads.push("R");
  690. col_heads.push("T");
  691. }
  692. if (!obj.qualified)
  693. {
  694. col_heads.push("Not Qualified");
  695. }
  696. for (i=0; i<col_heads.length; i++)
  697. {
  698. var this_cell = row.insertCell(i);
  699. row.cells[i].style.fontSize = default_text_size;
  700. this_cell.innerHTML = col_heads[i];
  701. if(i>1)
  702. this_cell.style.textAlign = 'center';
  703. if (i==6)
  704. {
  705. var listOfQuals = obj.quals.replace(/,/g,'\n');
  706. listOfQuals = listOfQuals.replace(/\[(.*?)\]/g,'');
  707. this_cell.title=listOfQuals;
  708. if (obj.masters)
  709. {
  710. this_cell.style.backgroundColor="#551A8B";
  711. this_cell.innerHTML="Y";
  712. }
  713. else
  714. {
  715. this_cell.style.backgroundColor="#0066CC";
  716. this_cell.innerHTML="N";
  717. }
  718. }
  719. if (check_hitDB)
  720. {
  721. if (i==7)
  722. {
  723. if (obj.reqdb){
  724. this_cell.style.backgroundColor = GREEN;
  725. this_cell.addEventListener("click", (function (obj) { return function() {search_deleg(obj,0);}})(obj));
  726. }
  727. else
  728. this_cell.style.backgroundColor = RED;
  729. }
  730. else if (i==8)
  731. {
  732. if (obj.titledb){
  733. this_cell.style.backgroundColor = GREEN;
  734. this_cell.addEventListener("click", (function (obj) { return function() {search_deleg(obj,1);}})(obj));
  735. }
  736. else
  737. this_cell.style.backgroundColor = RED;
  738. }
  739. else if (i==9)
  740. this_cell.style.backgroundColor = DARKGREY;
  741. }
  742. else if (i==7)
  743. this_cell.style.backgroundColor = DARKGREY;
  744. }
  745. if (Object.keys(history).length>0)
  746. {
  747. if (obj.new_result < 1000*save_new_results_time)
  748. {
  749. new_hits++;
  750. for (i in col_heads)
  751. {
  752. row.cells[i].style.fontSize = default_text_size + 1;
  753. row.cells[i].style.fontWeight = "bold";
  754. }
  755. }
  756. }
  757. button = document.createElement('button'); //HIT SCRAPER ADDITION
  758. button.textContent = 'vB';
  759. button.title = 'Export this HIT description as vBulletin formatted text';
  760. button.style.height = '14px';
  761. button.style.width = '30px';
  762. button.style.fontSize = '8px';
  763. button.style.border = '1px solid';
  764. button.style.padding = '0px';
  765. button.style.backgroundColor = 'transparent';
  766. button2 = document.createElement('button'); //BUTTON TO BLOCK REQUESTER
  767. button2.textContent = 'R';
  768. button2.title = 'Add requester to block list';
  769. button2.style.height = '14px';
  770. button2.style.width = '15px';
  771. button2.style.fontSize = '8px';
  772. button2.style.border = '1px solid';
  773. button2.style.padding = '0px';
  774. button2.style.backgroundColor = 'transparent';
  775. button3 = document.createElement('button'); //BUTTON TO BLOCK TITLE
  776. button3.textContent = 'T';
  777. button3.title = 'Add title to block list';
  778. button3.style.height = '14px';
  779. button3.style.width = '15px';
  780. button3.style.fontSize = '8px';
  781. button3.style.border = '1px solid';
  782. button3.style.padding = '0px';
  783. button3.style.backgroundColor = 'transparent';
  784. button4 = document.createElement('button');
  785. button4.textContent = 'IRC';
  786. button4.style.height = '14px';
  787. button4.style.width = '30px';
  788. button4.style.fontSize = '8px';
  789. button4.style.border = '1px solid';
  790. button4.style.padding = '0px';
  791. button4.style.backgroundColor = 'transparent';
  792. button4.title = 'Click to save Hit information to your clipboard';
  793. //button.addEventListener("click", function() {export_func_deleg(j);}.bind(null,j), false);
  794. button.addEventListener("click", (function (obj,j) { return function() {export_func_deleg(obj,j);}})(obj,j));
  795. row.cells[1].appendChild(document.createTextNode(" "));
  796. row.cells[1].appendChild(button);
  797. button4.addEventListener("click", (function (obj,j) { return function() {export_irc_deleg(obj,j);}})(obj,j));
  798. row.cells[1].appendChild(document.createTextNode(" "));
  799. row.cells[1].appendChild(button4);
  800. button2.addEventListener("click", (function (obj,j) { return function() {block_deleg(obj,0);}})(obj,j));
  801. row.cells[0].appendChild(document.createTextNode(" "));
  802. row.cells[0].appendChild(button2);
  803. button3.addEventListener("click", (function (obj,j) { return function() {block_deleg(obj,1);}})(obj,j));
  804. row.cells[0].appendChild(button3);
  805. }
  806. //});
  807. }
  808. set_progress_report("Scrape complete. " + shown_hits + " HITs found (" + new_hits + " new results). " + (found_hits - shown_hits) + " HITs ignored.", false);
  809. if (new_hits > 0){
  810. newHits(shouldDing);
  811. }
  812. url = url.substring(0,url.length - 1);
  813. //console.log(url);
  814. var success_flag = false;
  815. GM_xmlhttpRequest(
  816. {
  817. method: "GET",
  818. url: url,
  819. onload: function (results)
  820. {
  821. //console.log(results.responseText);
  822. rdata = $.parseJSON(results.responseText);
  823. for (i = 0; i < rids.length; i++)
  824. {
  825. text_area.rows[i+1].style.backgroundColor = GREY;
  826. if (rdata[rids[i]])
  827. {
  828. var pay = rdata[rids[i]].attrs.pay;
  829. var reviews = rdata[rids[i]].reviews;
  830. var average = 0;
  831. var sum = 0;
  832. var divisor = 0;
  833. var comm = rdata[rids[i]].attrs.comm;
  834. var fair = rdata[rids[i]].attrs.fair;
  835. var fast = rdata[rids[i]].attrs.fast;
  836. var titleText = "comm: "+comm+"\nfair: "+fair+"\nfast: "+fast+"\npay: "+pay;
  837. if (comm > 0)
  838. {
  839. sum += COMM_WEIGHT*comm;
  840. divisor += COMM_WEIGHT;
  841. }
  842. if (pay > 0)
  843. {
  844. sum += PAY_WEIGHT*pay;
  845. divisor += PAY_WEIGHT;
  846. }
  847. if (fair > 0)
  848. {
  849. sum += FAIR_WEIGHT*fair;
  850. divisor += FAIR_WEIGHT;
  851. }
  852. if (fast > 0)
  853. {
  854. sum += FAST_WEIGHT*fast;
  855. divisor += FAST_WEIGHT;
  856. }
  857. if (divisor > 0)
  858. {
  859. average = sum/divisor;
  860. }
  861. text_area.rows[i+1].cells[4].innerHTML = "<a href='"+ TO_REQ_URL+rids[i] +"' target='_blank'>" + pay + "</a>";
  862. text_area.rows[i+1].cells[4].setAttribute("title", titleText);
  863. if (reviews > 4)
  864. {
  865. if (average > 4.49)
  866. text_area.rows[i+1].style.backgroundColor = GREEN;
  867. else if (average > 3.49)
  868. text_area.rows[i+1].style.backgroundColor = LIGHTGREEN;
  869. //else if (average > 2.99)
  870. // text_area.rows[i+1].style.backgroundColor = YELLOW;
  871. else if (average > 1.99)
  872. text_area.rows[i+1].style.backgroundColor = ORANGE;
  873. else if (average > 0)
  874. text_area.rows[i+1].style.backgroundColor = RED;
  875. }
  876. }
  877. else
  878. {
  879. text_area.rows[i+1].cells[4].innerHTML = "No data";
  880. }
  881. }
  882. success_flag = true;
  883. }
  884. });
  885. if (!success_flag)
  886. for (i = 0; i < rids.length; i++) text_area.rows[i+1].style.backgroundColor = GREY;
  887. statusdetail_loop_finished = true;
  888. if (SEARCH_REFRESH>0)
  889. {
  890. wait_loop = setTimeout(function(){if (global_run) start_it();}, 1000*SEARCH_REFRESH);
  891. display_wait_time(SEARCH_REFRESH);
  892. }
  893. else
  894. {
  895. global_run = false;
  896. big_red_button.textContent = "Start";
  897. }
  898. }
  899. }
  900. }
  901.  
  902. function ignore_check(r,t){
  903. tempList = ignore_list.map(function(item) { return item.toLowerCase(); });
  904. foundR = -1;
  905. foundT = -1;
  906. foundR = tempList.indexOf(r.toLowerCase());
  907. foundT = tempList.indexOf(t.toLowerCase());
  908. if (shouldInclude){
  909. console.log(include_list);
  910. temp = include_list.map(function(item) { return item.toLowerCase(); }).indexOf(r.toLowerCase());
  911. console.log(temp);
  912. if (temp != -1)
  913. foundR = -1;
  914. else
  915. foundR = 0;
  916. }
  917. found = foundR == -1 && foundT == -1;
  918. //console.log("r: "+r+" t: "+t+" f: "+found);
  919. return found;
  920. //return -1 == ignore_list.map(function(item) { return item.toLowerCase(); }).indexOf(r.toLowerCase());
  921. }
  922.  
  923. function start_running()
  924. {
  925. if (big_red_button.textContent == "Start")
  926. {
  927. status_text="";
  928. ignore_list = GM_getValue("scraper_ignore_list").split('^');
  929. if (GM_getValue("scraper_include_list"))
  930. include_list = GM_getValue("scraper_include_list").split('^');
  931. global_run = true;
  932. initial_url = URL_BASE;
  933. if (search_input.value.length>0)
  934. {
  935. initial_url = initial_url.replace("searchWords=", "searchWords=" + search_input.value);
  936. }
  937. if (time_input.value.replace(/[^0-9]+/g,"") != "")
  938. {
  939. SEARCH_REFRESH = Number(time_input.value);
  940. }
  941. if (page_input.value.replace(/[^0-9]+/g,"") != "")
  942. {
  943. PAGES_TO_SCRAPE = Number(page_input.value);
  944. }
  945. if (min_input.value.replace(/[^0-9]+/g,"") != "")
  946. {
  947. if (!sort_input2.checked)
  948. status_text += " Minimum batch size selected but not sorting by most available";
  949. MINIMUM_HITS = Number(min_input.value);
  950. }
  951. if (new_time_display_input.value.replace(/[^0-9]+/g,"") != "")
  952. {
  953. save_new_results_time = Number(new_time_display_input.value);
  954. }
  955. if (reward_input.value.replace(/[^0-9]+/g,"") != "")
  956. {
  957. initial_url += "&minReward=" + reward_input.value;
  958. }
  959. else
  960. {
  961. initial_url += "&minReward=0.00";
  962. }
  963. if (qual_input.checked)
  964. {
  965. initial_url += "&qualifiedFor=on";
  966. }
  967. else
  968. {
  969. initial_url += "&qualifiedFor=off";
  970. }
  971. if (masters_input.checked)
  972. {
  973. initial_url += "&requiresMasterQual=on";
  974. }
  975. if (sort_input1.checked)
  976. {
  977. initial_url+= "&sortType=LastUpdatedTime%3A";
  978. default_type = 0;
  979. }
  980. else if (sort_input2.checked)
  981. {
  982. initial_url+= "&sortType=NumHITs%3A";
  983. default_type = 1;
  984. status_text += " Sorting by NumHITs ignores correct for skips in favor of minimum batch size";
  985. }
  986. else if (sort_input3.checked)
  987. {
  988. initial_url+= "&sortType=Reward%3A";
  989. default_type = 0;
  990. }
  991. else if (sort_input4.checked)
  992. {
  993. initial_url += "&sortType=Title%3A";
  994. }
  995. if (sort_input_invert.checked)
  996. {
  997. if (sort_input4.checked)
  998. initial_url += "1";
  999. else
  1000. initial_url += "0";
  1001. }
  1002. else
  1003. {
  1004. if (sort_input4.checked)
  1005. initial_url += "0";
  1006. else
  1007. initial_url += "1";
  1008. }
  1009. if (friesAreDone.checked)
  1010. {
  1011. shouldDing = true;
  1012. }
  1013. else {
  1014. shouldDing = false;
  1015. }
  1016. if (correctForSkips.checked){
  1017. if (matchOnly.checked)
  1018. {
  1019. status_text += " Match only checked, ignoring skip correction to prevent issues.";
  1020. correct_for_skips = false;
  1021. }
  1022. else{
  1023. correct_for_skips = true;
  1024. }
  1025. }
  1026. else {
  1027. correct_for_skips = false;
  1028. }
  1029. if (matchOnly.checked){
  1030. if (include_list.length == 0){
  1031. status_text += " No items in include list. Ignoring inclusion checkbox.";
  1032. shouldInclude = false;
  1033. }
  1034. else
  1035. shouldInclude = true;
  1036. }
  1037. else{
  1038. shouldInclude = false;
  1039. }
  1040. if (status_text == "")
  1041. status_text = "None";
  1042. initial_url+="&pageNumber=1&searchSpec=HITGroupSearch"
  1043. start_it();
  1044. }
  1045. else
  1046. {
  1047. global_run = false;
  1048. clearTimeout(wait_loop);
  1049. big_red_button.textContent = "Start";
  1050. set_progress_report("Stopped", true);
  1051. }
  1052. }
  1053.  
  1054. function start_it()
  1055. {
  1056. statusdetail_loop_finished = false;
  1057. big_red_button.textContent = "Stop";
  1058. found_key_list=[];
  1059. var ctime = new Date().getTime()
  1060. if (ctime - last_clear_time > save_results_time*666)
  1061. {
  1062. var last_history=history;
  1063. history = {};
  1064. for (var key in last_history)
  1065. {
  1066. if (last_history[key].new_result<save_results_time*1000)
  1067. {
  1068. history[key]=last_history[key];
  1069. if (last_history[key].found_this_time)
  1070. {
  1071. last_history[key].found_this_time = false;
  1072. if (last_history[key].new_result>save_new_results_time*1000)
  1073. last_history[key].initial_time = ctime-1000*save_new_results_time;
  1074. }
  1075. }
  1076. }
  1077. last_clear_time = ctime;
  1078. }
  1079. next_page = 1;
  1080. statusdetail_loop(initial_url);
  1081. }
  1082.  
  1083.  
  1084. function show_interface()
  1085. {
  1086. control_panel.style.color = BROWN;
  1087. control_panel.style.fontSize = 14;
  1088. control_panel.removeChild(big_red_button);
  1089. control_panel.appendChild(document.createTextNode("Auto-refresh delay: "));
  1090. time_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
  1091. time_input.title = "Enter search refresh delay in seconds\n" + "Enter 0 for no auto-refresh\n" + "Default is 0 (no auto-refresh)";
  1092. time_input.size = 3;
  1093. control_panel.appendChild(time_input);
  1094. control_panel.appendChild(document.createTextNode(" "));
  1095. control_panel.appendChild(document.createTextNode("| Pages to scrape: "));
  1096. page_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
  1097. page_input.title = "Enter number of pages to scrape\n" + "Default is 3";
  1098. page_input.size = 3;
  1099. control_panel.appendChild(page_input);
  1100. control_panel.appendChild(document.createTextNode(" Correct for skips: "));
  1101. correctForSkips.title = "Searches additional pages to get a consistent number of results. Helpful if you're blocking a lot of people";
  1102. control_panel.appendChild(correctForSkips);
  1103. control_panel.appendChild(document.createTextNode(" "));
  1104. control_panel.appendChild(document.createTextNode("| Minimum batch size: "));
  1105. min_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
  1106. min_input.title = "Enter minimum HITs for batch search\n" + "Default is 100";
  1107. min_input.size = 3;
  1108. control_panel.appendChild(min_input);
  1109. control_panel.appendChild(document.createTextNode(" "));
  1110. control_panel.appendChild(document.createTextNode("| New HIT highlighting: "));
  1111. new_time_display_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
  1112. new_time_display_input.title = "Enter time (in seconds) to keep new HITs highlighted\n" + "Default is 300 (5 minutes)";
  1113. new_time_display_input.size = 6;
  1114. control_panel.appendChild(new_time_display_input);
  1115. control_panel.appendChild(document.createTextNode(" "));
  1116. control_panel.appendChild(document.createTextNode("| Ding on new hit: "));
  1117. control_panel.appendChild(friesAreDone);
  1118. control_panel.appendChild(document.createElement("P"));
  1119. control_panel.appendChild(document.createTextNode("Minimum reward: "));
  1120. reward_input.size = 6;
  1121. control_panel.appendChild(reward_input);
  1122. control_panel.appendChild(document.createTextNode(" "));
  1123. control_panel.appendChild(document.createTextNode("| Qualified: "));
  1124. control_panel.appendChild(qual_input);
  1125. control_panel.appendChild(document.createTextNode(" "));
  1126. control_panel.appendChild(document.createTextNode("| Masters: "));
  1127. control_panel.appendChild(masters_input);
  1128. control_panel.appendChild(document.createTextNode(" "));
  1129. control_panel.appendChild(document.createTextNode("| Sort types: "));
  1130. control_panel.appendChild(document.createTextNode(" Latest: "));
  1131. control_panel.appendChild(sort_input1);
  1132. control_panel.appendChild(document.createTextNode("| Most Available: "));
  1133. control_panel.appendChild(sort_input2);
  1134. control_panel.appendChild(document.createTextNode("| Amount: "));
  1135. control_panel.appendChild(sort_input3);
  1136. control_panel.appendChild(document.createTextNode("| A-Z: "));
  1137. control_panel.appendChild(sort_input4);
  1138. control_panel.appendChild(document.createTextNode("| Invert: "));
  1139. control_panel.appendChild(sort_input_invert);
  1140. control_panel.appendChild(document.createElement("P"));
  1141. control_panel.appendChild(search_input);
  1142. search_input.size = 20;
  1143. search_input.title = "Enter a search term to include\n" + "Default is blank (no included terms)";
  1144. search_input.placeholder="Enter search terms here";
  1145. control_panel.appendChild(document.createTextNode(" "));
  1146. control_panel.appendChild(document.createTextNode("| Use includelist: "));
  1147. control_panel.appendChild(document.createTextNode(" "));
  1148. matchOnly.title = "Be sure to edit the include list or nothing will be displayed.";
  1149. control_panel.appendChild(matchOnly);
  1150. big_red_button.textContent = "Start";
  1151. big_red_button.onclick = function(){start_running();};
  1152. reset_blocks.textContent = "Edit blocklist";
  1153. reset_blocks.setAttribute("id","blocklist_reset_button");
  1154. reset_blocks.onclick = function(){
  1155. console.log("in");
  1156. var textarea = $("#block_text");
  1157. var text = "";
  1158. for (var i in ignore_list){
  1159. text += ignore_list[i]+"^";
  1160. }
  1161. textarea.text(text.substring(0, text.length - 1));
  1162. $("#block_div").show();
  1163. };
  1164. include_button.textContent = "Edit includes";
  1165. include_button.id = "includes_reset_button";
  1166. include_button.onclick = function() {
  1167. var div = $("#include_div");
  1168. var textarea = $("#include_text");
  1169. var text = "";
  1170. for (var i in include_list){
  1171. text += include_list[i]+"^";
  1172. }
  1173. textarea.text(text.substring(0, text.length - 1));
  1174. $("#include_div").show();
  1175. };
  1176. control_panel.appendChild(document.createTextNode(" | "));
  1177. control_panel.appendChild(big_red_button);
  1178. control_panel.appendChild(document.createTextNode(" "));
  1179. control_panel.appendChild(reset_blocks);
  1180. control_panel.appendChild(document.createTextNode(" "));
  1181. control_panel.appendChild(include_button);
  1182. control_panel.appendChild(document.createElement("P"));
  1183. control_panel.appendChild(progress_report);
  1184. control_panel.appendChild(document.createElement("P"));
  1185. control_panel.appendChild(document.createTextNode("Status messages: "));
  1186. control_panel.appendChild(status_report);
  1187. control_panel.appendChild(document.createElement("P"));
  1188. text_area.style.fontWeight = 400;
  1189. text_area.createCaption().innerHTML = "HITs";
  1190. var col_heads = ['Requester','Title','Reward','HITs Available','TO pay','Accept HIT','M?'];
  1191. var row = text_area.createTHead().insertRow(0);
  1192. text_area.caption.style.fontWeight = 800;
  1193. text_area.caption.style.color = BROWN;
  1194. if (default_text_size > 10)
  1195. text_area.cellPadding=Math.min(Math.max(1,Math.floor((default_text_size-10)/2)),5);
  1196. //console.log(text_area.cellPadding);
  1197. //text_area.cellPadding=2;
  1198. text_area.caption.style.fontSize = 28;
  1199. text_area.rows[0].style.fontWeight = 800;
  1200. text_area.rows[0].style.color = BROWN;
  1201. for (i=0; i<col_heads.length; i++)
  1202. {
  1203. var this_cell = row.insertCell(i);
  1204. this_cell.innerHTML = col_heads[i];
  1205. this_cell.style.fontSize = 14;
  1206. if (i > 1)
  1207. this_cell.style.textAlign = 'center';
  1208. }
  1209. control_panel.appendChild(text_area);
  1210. }
  1211.  
  1212. /********HIT EXPORT ADDITIONS*****/
  1213.  
  1214. var EDIT = false;
  1215. var HIT;
  1216.  
  1217. var TO_BASE = "http://turkopticon.ucsd.edu/";
  1218. var API_BASE = "https://mturk-api.istrack.in/";
  1219. var API_URL = API_BASE + "multi-attrs.php?ids=";
  1220.  
  1221. DEFAULT_TEMPLATE = '[table][tr][td][b]Title:[/b] [url={prev_link}][COLOR=blue]{title}[/COLOR][/url]\n';
  1222. DEFAULT_TEMPLATE += '[b]Requester:[/b] [url=https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId={rid}][COLOR=blue]{requester}[/COLOR][/url]';
  1223. DEFAULT_TEMPLATE += ' [{rid}] ([url='+TO_BASE+'{rid}][COLOR=blue]TO[/COLOR][/url])';
  1224. DEFAULT_TEMPLATE += '\n[b]TO Ratings:[/b]{to_stuff}';
  1225. DEFAULT_TEMPLATE += '\n[b]Description:[/b] {description}';
  1226. DEFAULT_TEMPLATE += '\n[b]Time:[/b] {time}';
  1227. DEFAULT_TEMPLATE += '\n[b]Hits Available:[/b] {hits}';
  1228. DEFAULT_TEMPLATE += '\n[b]Reward:[/b] [COLOR=green][b]{reward}[/b][/COLOR]';
  1229. DEFAULT_TEMPLATE += '\n[b]Qualifications:[/b] {quals}[/td][/tr][/table]';
  1230.  
  1231. var TEMPLATE;
  1232. var EASYLINK;
  1233.  
  1234. if (typeof GM_getValue === 'undefined')
  1235. TEMPLATE = null;
  1236. else {
  1237. TEMPLATE = GM_getValue('HITScraper Template');
  1238. EASYLINK = GM_getValue('HITScraper Easylink');
  1239. }
  1240. if (TEMPLATE == null) {
  1241. TEMPLATE = DEFAULT_TEMPLATE;
  1242. }
  1243.  
  1244. function buildXhrUrl(rai) {
  1245. var url = API_URL;
  1246. var ri = rai;
  1247. url += rai;
  1248. return url;
  1249. }
  1250.  
  1251. function makeXhrQuery(url) {
  1252. var xhr = new XMLHttpRequest();
  1253. try{
  1254. xhr.open('GET', url, false);
  1255. xhr.send(null);
  1256. return $.parseJSON(xhr.response);
  1257. }
  1258. catch(err){
  1259. return "TO DOWN";
  1260. }
  1261. }
  1262.  
  1263. function getNamesForEmptyResponses(rai, resp) {
  1264. for (var rid in rai) {
  1265. if (rai.hasOwnProperty(rid) && resp[rid] == "") {
  1266. resp[rid] = $.parseJSON('{"name": "' + rai[rid][0].innerHTML + '"}');
  1267. }
  1268. }
  1269. return resp;
  1270. }
  1271.  
  1272. function getKeys(obj) {
  1273. var keys = [];
  1274. for (var key in obj) {
  1275. keys.push(key);
  1276. }
  1277. return keys;
  1278. }
  1279.  
  1280. function export_func_deleg(item,index) {
  1281. //console.log(item);
  1282. export_func(item);
  1283. }
  1284.  
  1285. function export_irc_deleg(item,index) {
  1286. //console.log(item);
  1287. export_irc(item);
  1288. }
  1289.  
  1290. function block_deleg(item,index) {
  1291. //console.log(item);
  1292. block(item,index);
  1293. }
  1294.  
  1295. function block(hit,index){
  1296. var blockType = ["requester","title"];
  1297. var blockThis = hit[blockType[index]];
  1298. ignore_list.push(blockThis);
  1299. GM_setValue("scraper_ignore_list",ignore_list.join('^'));
  1300. //console.log(GM_getValue("scraper_ignore_list"));
  1301. alert("\""+blockThis+"\" ignored. Re-scrape");
  1302. }
  1303.  
  1304. function search_deleg(item,index) {
  1305. console.log(item);
  1306. var searches = ["rid","title"];
  1307. search(item,searches[index]);
  1308. }
  1309.  
  1310. function hit_sort_func()
  1311. {
  1312. return function(a,b) {
  1313. if (a.date == b.date) {
  1314. if (a.requesterName < b.requesterName)
  1315. return -1;
  1316. if (a.requesterName > b.requesterName)
  1317. return 1;
  1318. if (a.title < b.title)
  1319. return -1;
  1320. if (a.title > b.title)
  1321. return 1;
  1322. if (a.status < b.status)
  1323. return -1;
  1324. if (a.status > b.status)
  1325. return 1;
  1326. }
  1327. if (a.date > b.date)
  1328. return 1;
  1329. if (a.date < b.date)
  1330. return -1;
  1331. };
  1332. }
  1333.  
  1334. function escapeRegExp(str) {
  1335. return str.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  1336. }
  1337.  
  1338. function search(item,search_type){
  1339. //return true;/*
  1340. var request = indexedDB.open("HITDB", v);
  1341. request.onsuccess = function(e) {
  1342. HITStorage.indexedDB.db = e.target.result;
  1343. var db = HITStorage.indexedDB.db;
  1344. var trans = db.transaction(["HIT"], HITStorage.IDBTransactionModes.READ_ONLY);
  1345. var store = trans.objectStore("HIT");
  1346. var req;
  1347. var results = [];
  1348. var index;
  1349. var range;
  1350. req = store.openCursor();
  1351. req.onsuccess = function(event) {
  1352. var cursor = event.target.result;
  1353. if (cursor) {
  1354. hit = cursor.value;
  1355. var keys = ['title', 'requesterId'];
  1356. var re = new RegExp(escapeRegExp(item[search_type]),"ig");
  1357. for (var k in keys)
  1358. {
  1359. if (hit[keys[k]] != null && re.test(hit[keys[k]].trim())){
  1360. results.push(cursor.value);
  1361. }
  1362. }
  1363. cursor.continue();
  1364. }
  1365. else {
  1366. console.log(results);
  1367. results.sort(hit_sort_func());
  1368. show_results(results);
  1369. }
  1370. db.close();
  1371. };
  1372. request.onerror = HITStorage.indexedDB.onerror;/**/
  1373. }
  1374. }
  1375.  
  1376. function format_hit_line (hit, odd, status_color, new_day)
  1377. {
  1378. var line = '<tr style="background-color:';
  1379. if (odd)
  1380. line += '#f1f3eb;';
  1381. else
  1382. line += 'white;';
  1383. line += ' valign=top;';
  1384. if (new_day)
  1385. line += ' border: 0px dotted #000000; border-width: 2px 0px 0px 0px">';
  1386. else
  1387. line += '">';
  1388. line += '<td>' + hit.date + '</td>';
  1389. if (hit.requesterLink != null)
  1390. line += '<td style="width:165px"><a href="' + hit.requesterLink + '" title="Contact this Requester">' + hit.requesterName + '</a></td>';
  1391. else
  1392. line += '<td style="width:165px">' + hit.requesterName + '</td>';
  1393. line += '<td style="width:213px">' + hit.title + '</td>';
  1394. line += '<td style="width:45px">$' + hit.reward.toFixed(2) + '</td>';
  1395. line += '<td style="color:' + status_color + '; width:55px">' + hit.status + '</td>';
  1396. line += '<td><div style="width:225px; overflow:hidden">' + hit.feedback + '</div></td>';
  1397. line += '</tr>\n';
  1398. return line;
  1399. }
  1400.  
  1401. function status_color (status)
  1402. {
  1403. var color = "green";
  1404. if (status.match("Pending Approval"))
  1405. color = "orange";
  1406. else if (status.match("Rejected"))
  1407. color = "red";
  1408. return color;
  1409. }
  1410.  
  1411. function show_results (results){
  1412. resultsWindow = window.open();
  1413. resultsWindow.document.write("<html><head><title>Status Detail Search Results</title></head><body>\n");
  1414. resultsWindow.document.write("<h1>HITs matching your search:</h1>\n");
  1415. resultsWindow.document.write('<table style="border: 1px solid black;border-collapse:collapse;width:90%;margin-left:auto;margin-right:auto;">\n');
  1416. resultsWindow.document.write('<tr style="background-color:lightgrey"><th>Date</th><th>Requester</th><th>HIT Title</th><th>Reward</th><th>Status</th><th>Feedback</th></tr>\n');
  1417. var odd = true;
  1418. var sum = 0;
  1419. var sum_rejected = 0;
  1420. var sum_approved = 0;
  1421. var sum_pending = 0;
  1422. var new_day = false;
  1423. for (var i=0; i<results.length; i++) {
  1424. odd = !odd;
  1425. sum += results[i].reward;
  1426. if (results[i].status == 'Rejected')
  1427. sum_rejected += results[i].reward;
  1428. else if (results[i].status == 'Pending Approval')
  1429. sum_pending += results[i].reward;
  1430. else
  1431. sum_approved += results[i].reward;
  1432. if (i>0 && (results[i-1].date != results[i].date))
  1433. new_day = true;
  1434. else
  1435. new_day = false;
  1436. resultsWindow.document.write(format_hit_line(results[i], odd, status_color(results[i].status), new_day ));
  1437. }
  1438. resultsWindow.document.write('<tr style="background-color:lightgrey"><th></th><th></th><th></th><th>$' + sum.toFixed(2) + '</th><th></th><th></th></tr>\n');
  1439. resultsWindow.document.write("</table>");
  1440. resultsWindow.document.write("<p>Found " + results.length + " matching HITs. $" + sum_approved.toFixed(2) + " approved, " +
  1441. "$" + sum_rejected.toFixed(2) + " rejected and $" + sum_pending.toFixed(2) + " pending.</p>");
  1442. resultsWindow.document.write("</body></html>")
  1443. resultsWindow.document.close();
  1444. }
  1445.  
  1446.  
  1447. function export_func(item) {
  1448. HIT = item;
  1449. edit_button.textContent = 'Edit Template';
  1450. apply_template(item);
  1451. div.style.display = 'block';
  1452. textarea.select();
  1453. }
  1454.  
  1455. function export_irc(item) {
  1456. display(item);
  1457. }
  1458.  
  1459. function apply_template(hit_data) {
  1460. var txt = TEMPLATE;
  1461. var vars = ['title', 'requester', 'rid', 'description', 'reward', 'quals', 'prev_link', 'time', 'hits', 'to_stuff', 'to_text'];
  1462. var resp = null;
  1463. if (txt.indexOf('{to_text}') >= 0 || txt.indexOf('{to_stuff}') >= 0){
  1464. var url = buildXhrUrl(hit_data["rid"]);
  1465. resp = makeXhrQuery(url);
  1466. //console.log(resp);
  1467. }
  1468. var toText = "";
  1469. var toStuff = "";
  1470. var toData = "";
  1471. var numResp = (resp == null || resp == "TO DOWN" ? "n/a" : resp[hit_data["rid"]].reviews);
  1472. if (resp == "TO DOWN"){
  1473. toStuff = " [URL=\""+TO_BASE+hit_data['rid']+"\"]TO down.[/URL]";
  1474. toText = toStuff;
  1475. }
  1476. else if (resp == null || resp[hit_data["rid"]].attrs == null && resp != "TO DOWN") {
  1477. toStuff = " No TO ";
  1478. toText = " No TO ";
  1479. toStuff += "[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"]";
  1480. toStuff += "(Submit a new TO rating for this requester)[/URL]";
  1481. }
  1482. else {
  1483. for (var key in resp[hit_data["rid"]].attrs) {
  1484. //toText += "\n[*]"+key+": "+resp[hit_data["requesterId"]].attrs[key]+"\n";
  1485. var i = 0;
  1486. var color = "green";
  1487. var name = key;
  1488. var num = Math.floor(resp[hit_data["rid"]].attrs[key]);
  1489. switch (key){
  1490. case "comm":
  1491. name = "Communicativity";
  1492. break;
  1493. case "pay":
  1494. name = "Generosity";
  1495. break;
  1496. case "fast":
  1497. name = "Promptness";
  1498. break;
  1499. case "fair":
  1500. name = "Fairness";
  1501. break;
  1502. default:
  1503. name = key;
  1504. break;
  1505. }
  1506. switch (num){
  1507. case 0:
  1508. color = "red";
  1509. break;
  1510. case 1:
  1511. color = "red";
  1512. break;
  1513. case 2:
  1514. color = "orange";
  1515. break;
  1516. case 3:
  1517. color = "yellow";
  1518. break;
  1519. default:
  1520. break;
  1521. }
  1522. toText += (num > 0 ? "\n[color="+color+"]" : "\n");
  1523. for (i; i < num; i++){
  1524. toText += "[b]"+symbol+"[/b]"
  1525. }
  1526. toText += (num > 0 ? "[/color]" : "")
  1527. if (i < 5){
  1528. toText += "[color=white]";
  1529. for (i; i < 5; i++)
  1530. toText += "[b]"+symbol+"[/b]";
  1531. toText += "[/color]";
  1532. }
  1533. toText += " "+Number(resp[hit_data["rid"]].attrs[key]).toFixed(2)+" "+name;
  1534. toData += Number(resp[hit_data["rid"]].attrs[key]).toFixed(2) + ",";
  1535. }
  1536. //toText += "[/list]";
  1537. 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]");
  1538. toStuff = '\n[img]http://data.istrack.in/to/' + toData.slice(0,-1) + '.png[/img]';
  1539. toStuff += (txt.indexOf('{to_stuff}') >= 0 ? (txt.indexOf('{to_text}') >= 0 ? "" : toText) : "");
  1540. toStuff += "\nNumber of Reviews: "+numResp;
  1541. toStuff += "[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"]";
  1542. toStuff += "\n(Submit a new TO rating for this requester)[/URL]";
  1543. }
  1544. for (var i = 0; i < vars.length; i++) {
  1545. t = new RegExp('\{' + vars[i] + '\}', 'g');
  1546. if (vars[i] == "to_stuff") {
  1547. txt = txt.replace(t, toStuff);
  1548. }
  1549. else if (vars[i] == "to_text") {
  1550. txt = txt.replace(t, toText);
  1551. }
  1552. else if (vars[i] == "prev_link") {
  1553. txt = txt.replace(t,"https://www.mturk.com"+hit_data[vars[i]]);
  1554. }
  1555. else if (vars[i] == "acc_link") {
  1556. txt = txt.replace(t,"https://www.mturk.com"+hit_data[vars[i]]);
  1557. }
  1558. else
  1559. txt = txt.replace(t, hit_data[vars[i]]);
  1560. }
  1561. textarea.value = txt;
  1562. }
  1563. function hide_func(div) {
  1564. if (EDIT == false)
  1565. div.style.display = 'none';
  1566. }
  1567. function edit_func() {
  1568. if (EDIT == true) {
  1569. EDIT = false;
  1570. TEMPLATE = textarea.value;
  1571. edit_button.textContent = 'Edit Template';
  1572. apply_template(HIT);
  1573. }
  1574. else {
  1575. console.log("Editing");
  1576. EDIT = true;
  1577. edit_button.textContent = 'Show Changes';
  1578. save_button.disabled = false;
  1579. textarea.value = TEMPLATE;
  1580. }
  1581. }
  1582. function default_func() {
  1583. GM_deleteValue('HITScraper Template');
  1584. TEMPLATE = DEFAULT_TEMPLATE;
  1585. EDIT = false;
  1586. edit_button.textContent = 'Edit Template';
  1587. apply_template(HIT);
  1588. }
  1589. function save_func() {
  1590. if (EDIT)
  1591. TEMPLATE = textarea.value;
  1592. GM_setValue('HITScraper Template', TEMPLATE);
  1593. }
  1594. var div = document.createElement('div');
  1595. var textarea = document.createElement('textarea');
  1596. var div2 = document.createElement('label');
  1597. div.style.position = 'fixed';
  1598. div.style.width = '500px';
  1599. div.style.height = '235px';
  1600. div.style.left = '50%';
  1601. div.style.right = '50%';
  1602. div.style.margin = '-250px 0px 0px -250px';
  1603. div.style.top = '300px';
  1604. div.style.padding = '5px';
  1605. div.style.border = '2px';
  1606. div.style.backgroundColor = 'black';
  1607. div.style.color = 'white';
  1608. div.style.zIndex = '100';
  1609. textarea.style.padding = '2px';
  1610. textarea.style.width = '500px';
  1611. textarea.style.height = '200px';
  1612. 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}';
  1613. div.textContent = 'Press Ctrl+C to copy to clipboard. Click textarea to close';
  1614. div.style.fontSize = '12px';
  1615. div.appendChild(textarea);
  1616. var edit_button = document.createElement('button');
  1617. var save_button = document.createElement('button');
  1618. var default_button = document.createElement('button');
  1619. var easy_button = document.createElement('button');
  1620. edit_button.textContent = 'Edit Template';
  1621. edit_button.setAttribute('id', 'edit_button');
  1622. edit_button.style.height = '18px';
  1623. edit_button.style.width = '100px';
  1624. edit_button.style.fontSize = '10px';
  1625. edit_button.style.paddingLeft = '3px';
  1626. edit_button.style.paddingRight = '3px';
  1627. edit_button.style.backgroundColor = 'white';
  1628. save_button.textContent = 'Save Template';
  1629. save_button.setAttribute('id', 'save_button');
  1630. save_button.style.height = '18px';
  1631. save_button.style.width = '100px';
  1632. save_button.style.fontSize = '10px';
  1633. save_button.style.paddingLeft = '3px';
  1634. save_button.style.paddingRight = '3px';
  1635. save_button.style.backgroundColor = 'white';
  1636. save_button.style.marginLeft = '5px';
  1637. easy_button.textContent = 'Change Adfly Url';
  1638. easy_button.setAttribute('id', 'easy_button');
  1639. easy_button.style.height = '18px';
  1640. easy_button.style.width = '100px';
  1641. easy_button.style.fontSize = '10px';
  1642. easy_button.style.paddingLeft = '3px';
  1643. default_button.textContent = ' D ';
  1644. default_button.setAttribute('id', 'default_button');
  1645. default_button.style.height = '18px';
  1646. default_button.style.width = '20px';
  1647. default_button.style.fontSize = '10px';
  1648. default_button.style.paddingLeft = '3px';
  1649. default_button.style.paddingRight = '3px';
  1650. default_button.style.backgroundColor = 'white';
  1651. default_button.style.marginLeft = '5px';
  1652. default_button.title = 'Return default template';
  1653. div.appendChild(edit_button);
  1654. div.appendChild(save_button);
  1655. div.appendChild(default_button);
  1656. div.appendChild(easy_button);
  1657. save_button.disabled = true;
  1658. div.style.display = 'none';
  1659. textarea.addEventListener("click", function() {hide_func(div);}, false);
  1660. edit_button.addEventListener("click", function() {edit_func();}, false);
  1661. save_button.addEventListener("click", function() {save_func();}, false);
  1662. default_button.addEventListener("click", function() {default_func();}, false);
  1663. document.body.insertBefore(div, document.body.firstChild);
  1664.  
  1665. //Functions below were added for the irc export with the help of clickhappier and Cristo
  1666.  
  1667. function getTO(f){
  1668. var toComp = [];
  1669. var toUrl = 'https://mturk-api.istrack.in/multi-attrs.php?ids='+f;
  1670. requestTO = new XMLHttpRequest();
  1671. requestTO.onreadystatechange = function () {
  1672. if ((requestTO.readyState ===4) && (requestTO.status ===200)) {
  1673. if(requestTO.responseText.split(':').length > 2){
  1674. var toInfo = requestTO.responseText.split('{')[3].split('}')[0].split(',');
  1675. for (var t = 0; t < 3; t++){
  1676. var arrTo = toInfo[t].split(':');
  1677. toComp.push(arrTo[1].substring(1,4));
  1678. }
  1679. } else {
  1680. toComp = ['-','-','-'];
  1681. }
  1682. }
  1683. };
  1684. requestTO.open('GET', toUrl, false);
  1685. requestTO.send(null);
  1686. return toComp;
  1687. }
  1688.  
  1689. function sleep(ms){ // from http://www.digimantra.com/tutorials/sleep-or-wait-function-in-javascript/
  1690. var dt = new Date();
  1691. dt.setTime(dt.getTime() + ms);
  1692. while (new Date().getTime() < dt.getTime());
  1693. }
  1694. function ns4tShorten(url){ // mturk-only URL shortener on Tjololo's server ns4t.net
  1695. console.log("ns4tShorten function");
  1696. var shortRes;
  1697. var urlT = "https://ns4t.net/yourls-api.php" + "?action=shorturl&url=" + encodeURIComponent(url) + "&format=simple&title=MTurk&username=publicuser&password=publicpass";
  1698. requestNs4t = new XMLHttpRequest();
  1699. requestNs4t.onreadystatechange = function () {
  1700. if (requestNs4t.readyState == 4) {
  1701. if (requestNs4t.status == 200) {
  1702. shortRes = requestNs4t.responseText;
  1703. console.log("ns4t.net response: " + requestNs4t.status + " " + requestNs4t.statusText + " " + requestNs4t.responseText);
  1704. }
  1705. else {
  1706. console.log('ns4t.net unsuccessful: ' + requestNs4t.status + " " + requestNs4t.statusText);
  1707. }
  1708. }
  1709. };
  1710. requestNs4t.open('GET', urlT, false);
  1711. requestNs4t.send(null);
  1712. return shortRes;
  1713. }
  1714. function tnyimShorten(url){ // Tny.im URL Shortener - http://tny.im/aboutapi.php - this is only possible this way because their server has the "Access-Control-Allow-Origin = *" headers enabled (the above TO mirror server does too)
  1715. console.log("tnyimShorten function");
  1716. var shortRes;
  1717. var urlT = "https://tny.im/yourls-api.php" + "?action=shorturl&url=" + encodeURIComponent(url) + "&format=simple&title=MTurk";
  1718. requestTnyim = new XMLHttpRequest();
  1719. requestTnyim.onreadystatechange = function () {
  1720. if (requestTnyim.readyState == 4) {
  1721. if (requestTnyim.status == 200) {
  1722. shortRes = requestTnyim.responseText;
  1723. console.log("tny.im response: " + requestTnyim.status + " " + requestTnyim.statusText + " " + requestTnyim.responseText);
  1724. }
  1725. else {
  1726. console.log('tny.im unsuccessful: ' + requestTnyim.status + " " + requestTnyim.statusText);
  1727. }
  1728. }
  1729. };
  1730. requestTnyim.open('GET', urlT, false);
  1731. requestTnyim.send(null);
  1732. return shortRes;
  1733. }
  1734. function googlShorten(url){ // Goo.gl URL Shortener
  1735. console.log("googlShorten function");
  1736. var shortRes;
  1737. var urlG = "https://www.googleapis.com/urlshortener/v1/url";
  1738. var requestGoogl = new XMLHttpRequest();
  1739. requestGoogl.open("POST", urlG, false);
  1740. requestGoogl.setRequestHeader("Content-Type", "application/json");
  1741. requestGoogl.onreadystatechange = function() {
  1742. if (requestGoogl.readyState == 4) {
  1743. if (requestGoogl.status == 200) {
  1744. shortRes = JSON.parse(requestGoogl.response).id;
  1745. console.log("goo.gl response: " + requestGoogl.status + " " + requestGoogl.statusText + " " + JSON.parse(requestGoogl.response).id );
  1746. }
  1747. else {
  1748. console.log('goo.gl unsuccessful: ' + requestGoogl.status + " " + requestGoogl.statusText);
  1749. }
  1750. }
  1751. };
  1752. var data = new Object();
  1753. data.longUrl = url;
  1754. requestGoogl.send(JSON.stringify(data));
  1755.  
  1756. return shortRes;
  1757. }
  1758. function shortenUrl(url){
  1759. sleep(300); // milliseconds delay - wait some milliseconds (currently less than 1/3rd of a second) between shortens to reduce chance of hitting usage limits
  1760. var shortRes;
  1761. shortRes = googlShorten(url);
  1762. if ( shortRes === undefined ) { // if you reached the Google URL shortener's temporary usage limits or the server is otherwise unavailable
  1763. shortRes = ns4tShorten(url);
  1764. if ( shortRes === undefined ) { // if you reached the ns4t.net URL shortener's temporary limits or the server is otherwise unavailable
  1765. shortRes = tnyimShorten(url);
  1766. if ( shortRes === undefined ) { // if you reached the tny.im URL shortener's temporary limits too or the server is otherwise unavailable
  1767. shortRes = "(x)";
  1768. }
  1769. }
  1770. }
  1771. return shortRes;
  1772. }
  1773.  
  1774. // output display box
  1775. var ircexportdiv = document.createElement('div');
  1776. var ircexporttextarea = document.createElement('textarea');
  1777. ircexportdiv.style.position = 'fixed';
  1778. ircexportdiv.style.width = '500px';
  1779. ircexportdiv.style.height = '155px';
  1780. ircexportdiv.style.left = '50%';
  1781. ircexportdiv.style.right = '50%';
  1782. ircexportdiv.style.margin = '-250px 0px 0px -250px';
  1783. ircexportdiv.style.top = '300px';
  1784. ircexportdiv.style.padding = '5px';
  1785. ircexportdiv.style.border = '2px';
  1786. ircexportdiv.style.backgroundColor = 'black';
  1787. ircexportdiv.style.color = 'white';
  1788. ircexportdiv.style.zIndex = '100';
  1789. ircexportdiv.setAttribute('id','ircexport_div');
  1790. ircexportdiv.style.display = 'none';
  1791. ircexporttextarea.style.padding = '2px';
  1792. ircexporttextarea.style.width = '500px';
  1793. ircexporttextarea.style.height = '130px';
  1794. ircexporttextarea.title = 'IRC Export Output';
  1795. ircexporttextarea.setAttribute('id','ircexport_text');
  1796. ircexportdiv.textContent = 'IRC Export: Press Ctrl+C to (re-)copy to clipboard. Click textarea to close.';
  1797. ircexportdiv.style.fontSize = '12px';
  1798. ircexportdiv.appendChild(ircexporttextarea);
  1799. document.body.insertBefore(ircexportdiv, document.body.firstChild);
  1800. ircexporttextarea.addEventListener("click", function(){ ircexportdiv.style.display = 'none'; }, false);
  1801.  
  1802. function display(hit){
  1803. //var theButton = e.target;
  1804. //theButton.style.backgroundColor = '#CC0000';
  1805. //var capHand = document.getElementById('capsule'+theButton.getAttribute("place")+'-0');
  1806. //var tBodies = capHand.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  1807. console.log(hit);
  1808. //return 0;
  1809. var capReq = hit["requester"];
  1810. var capReqId = hit["rid"];
  1811. var capTitle = hit["title"];
  1812. var capRew = hit["reward"];
  1813.  
  1814. var capTime = hit["time"];
  1815.  
  1816. var capAvailable = hit["time"];
  1817.  
  1818. var qualList = hit["quals"];
  1819. var qualColl = qualList.split(',');
  1820. var masterStat = '';
  1821. for ( var m = 0; m < qualColl.length; m++ ) {
  1822. if ( qualColl[m].indexOf('Masters') > -1 ) {
  1823. masterStat = 'MASTERS • ';
  1824. }
  1825. }
  1826. var capUrl = shortenUrl('https://www.mturk.com'+hit["prev_link"]);
  1827. var capReqUrl = shortenUrl('https://www.mturk.com'+hit["req_link"]);
  1828. var hitLinkUnav = '';
  1829. //if ( capGId == 'unavailable' ) { capUrl = capReqUrl; hitLinkUnav = " (preview link unavailable)"; } // handle logged-out export requests for HITs with no preview/notqualified links
  1830. if (capUrl.indexOf("requesterId") > -1)
  1831. {
  1832. hitLinkUnav = " (preview link unavailable)";
  1833. }
  1834. var toLink = shortenUrl('http://turkopticon.ucsd.edu/'+capReqId);
  1835. var capToStats = getTO(capReqId);
  1836. var shortUrlUnav = '';
  1837. if ( capUrl == '(x)' && capGId != 'unavailable' )
  1838. {
  1839. shortUrlUnav = ' \r\n^ https://www.mturk.com'+hit["prev_link"];
  1840. } // add the full-length preview link at the end if both URL shortener attempts failed
  1841. var exString = masterStat + 'Requester: ' + capReq + ' ' + capReqUrl + ' • ' + 'HIT: ' + capTitle + ' ' + capUrl + hitLinkUnav + ' • ' + 'Pay: ' + capRew + ' • ' + 'Avail: ' + capAvailable + ' • ' + 'Time Limit: ' + capTime + ' • ' + 'TO: ' + 'Pay='+capToStats[1] + ' Fair='+capToStats[2] + ' Comm='+capToStats[0] + ' ' + toLink + shortUrlUnav ;
  1842. GM_setClipboard(exString);
  1843. ircexporttextarea.textContent = exString;
  1844. ircexportdiv.style.display = 'block';
  1845. ircexporttextarea.select();
  1846. }