Greasy Fork 支持简体中文。

DTs Dashboard Charts

Adds charts to the mturk dashboard

目前為 2014-07-24 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name DTs Dashboard Charts
  3. // @namespace localhost
  4. // @version 0.3b
  5. // @description Adds charts to the mturk dashboard
  6. // @match https://www.mturk.com/mturk/dashboard
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js
  8. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/jquery.jqplot.js
  9. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/plugins/jqplot.pieRenderer.js
  10. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/plugins/jqplot.dateAxisRenderer.min.js
  11. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/plugins/jqplot.canvasAxisTickRenderer.js
  12. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/plugins/jqplot.canvasAxisLabelRenderer.js
  13. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/plugins/jqplot.canvasTextRenderer.js
  14. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/plugins/jqplot.categoryAxisRenderer.js
  15. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/plugins/jqplot.barRenderer.js
  16. // @require http://cdn.jsdelivr.net/jqplot/1.0.8/plugins/jqplot.pointLabels.js
  17. // @resource jqplot http://cdn.jsdelivr.net/jqplot/1.0.8/jquery.jqplot.css
  18. // @grant GM_addStyle
  19. // @grant GM_getResourceText
  20. // @run-at document-end
  21. // @copyright 2014+, DeliriumTremens
  22. // ==/UserScript==
  23.  
  24. var jqplotCSS = GM_getResourceText("jqplot");
  25. GM_addStyle(jqplotCSS);
  26.  
  27.  
  28. // Display dollar and hit count charts
  29. var dates = [];
  30. $('a[href*="statusdetail"]').each( function () {
  31. dates.push($(this).attr('href'));
  32. });
  33. var HITStorage = {};
  34. HITStorage.indexedDB = {};
  35. HITStorage.indexedDB.db = null;
  36. var curr = new Date;
  37. var first = curr.getDate() - curr.getDay();
  38. var last = first + 6;
  39.  
  40. var firstday = new Date(curr.setDate(first));
  41.  
  42. firstdy = (firstday.getFullYear() + '-' + ('0' + (firstday.getMonth()+1)).slice(-2) + '-' + ('0' + (firstday.getDate())).slice(-2));
  43. seconddy = (firstday.getFullYear() + '-' + ('0' + (firstday.getMonth()+1)).slice(-2) + '-' + ('0' + (firstday.getDate()+1)).slice(-2));
  44. thirddy = (firstday.getFullYear() + '-' + ('0' + (firstday.getMonth()+1)).slice(-2) + '-' + ('0' + (firstday.getDate()+2)).slice(-2));
  45. fourthdy = (firstday.getFullYear() + '-' + ('0' + (firstday.getMonth()+1)).slice(-2) + '-' + ('0' + (firstday.getDate()+3)).slice(-2));
  46. fifthdy = (firstday.getFullYear() + '-' + ('0' + (firstday.getMonth()+1)).slice(-2) + '-' + ('0' + (firstday.getDate()+4)).slice(-2));
  47. sixthdy = (firstday.getFullYear() + '-' + ('0' + (firstday.getMonth()+1)).slice(-2) + '-' + ('0' + (firstday.getDate()+5)).slice(-2));
  48. seventhdy = (firstday.getFullYear() + '-' + ('0' + (firstday.getMonth()+1)).slice(-2) + '-' + ('0' + (firstday.getDate()+6)).slice(-2));
  49. var hitMeter = {};
  50. hitMeter[firstdy.toString()] = 0;
  51. hitMeter[seconddy.toString()] = 0;
  52. hitMeter[thirddy.toString()] = 0;
  53. hitMeter[fourthdy.toString()] = 0;
  54. hitMeter[fifthdy.toString()] = 0;
  55. hitMeter[sixthdy.toString()] = 0;
  56. hitMeter[seventhdy.toString()] = 0;
  57. var hitCounter = {};
  58. hitCounter[firstdy.toString()] = 0;
  59. hitCounter[seconddy.toString()] = 0;
  60. hitCounter[thirddy.toString()] = 0;
  61. hitCounter[fourthdy.toString()] = 0;
  62. hitCounter[fifthdy.toString()] = 0;
  63. hitCounter[sixthdy.toString()] = 0;
  64. hitCounter[seventhdy.toString()] = 0;
  65. function HITpull() {
  66. var request = indexedDB.open("HITDB", 4);
  67. request.onsuccess = function(e) {
  68. HITStorage.indexedDB.db = e.target.result;
  69. var db = HITStorage.indexedDB.db;
  70. var results = [];
  71. var tmp_results = {};
  72. var transaction = db.transaction('HIT','readonly');
  73. var store = transaction.objectStore('HIT');
  74. var index = store.index('date');
  75. var range = IDBKeyRange.bound(firstdy, seventhdy, false, false);
  76. index.openCursor(range).onsuccess = function(event) {
  77. var cursor = event.target.result;
  78. if (cursor) {
  79. var hit = cursor.value;
  80. if (tmp_results[hit.date] === undefined) {
  81. tmp_results[hit.date] = [];
  82. tmp_results[hit.date][0] = hit.reward;
  83. tmp_results[hit.date][1] = 1;
  84. tmp_results[hit.date][2] = hit.date;
  85. }
  86. else if (hit.status === 'Rejected'){}
  87. else {
  88. tmp_results[hit.date][0] += hit.reward;
  89. tmp_results[hit.date][1] += 1;
  90. tmp_results[hit.date][2] = hit.date;
  91. }
  92. cursor.continue();
  93. }
  94. else {
  95. for (var key in tmp_results) {
  96. results.push(tmp_results[key]);
  97. }
  98. printHitCount(results);
  99. printDollarCount(results);
  100. }
  101. db.close();
  102. };
  103. request.onerror = HITStorage.indexedDB.onerror;
  104. };
  105. }
  106. function printHitCount (results) {
  107. $(".container-content:eq(1)").append('<div id="hitCount" style="height:200px;width:350px;float:left;"></div>');
  108. for (var key in results) {
  109. hitMeter[results[key][2]] += results[key][1];
  110. };
  111. var ticks = ['Sun','Mon','Tue','Wed','Thur','Fri','Sat'];
  112. var plot2 = $.jqplot('hitCount', [[hitMeter[firstdy.toString()],hitMeter[seconddy.toString()],hitMeter[thirddy.toString()],hitMeter[fourthdy.toString()],hitMeter[fifthdy.toString()],
  113. hitMeter[sixthdy.toString()],hitMeter[seventhdy.toString()]]], {
  114. animate: !$.jqplot.use_excanvas,
  115. seriesDefaults:{
  116. renderer:$.jqplot.BarRenderer,
  117. rendererOptions: {fillToZero: true},
  118. pointLabels: {
  119. show: true,
  120. hideZeros: true,
  121. location: 'n',
  122. ypadding: 1
  123. }
  124. },
  125. series:[
  126. {label:firstdy.toString()},
  127. {label:seconddy.toString()},
  128. {label:thirddy.toString()},
  129. {label:fourthdy.toString()},
  130. {label:fifthdy.toString()},
  131. {label:sixthdy.toString()},
  132. {label:seventhdy.toString()}
  133. ],
  134. title: {
  135. text: 'Daily Count (Current Week)',
  136. fontFamily: '"Trebuchet MS", Arial, Helvetica, sans-serif',
  137. fontSize: '10pt',
  138. textColor: '#666666'
  139. },
  140. axes: {
  141. xaxis: {
  142. tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
  143. tickOptions: {
  144. //angle: -15,
  145. fontSize: '8pt',
  146. showGridline: false,
  147. formatString: '%a'
  148. },
  149. renderer: $.jqplot.CategoryAxisRenderer,
  150. ticks: ticks
  151. },
  152. yaxis: {
  153. tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
  154. tickOptions: {
  155. fontSize: '8pt',
  156. markSize: '0'
  157. },
  158. pad: 1.2,
  159. min: 0
  160. }
  161. }
  162. });
  163. var imgData = $('#hitCount').jqplotToImageStr({});
  164. $('#hitCount').on('click',function () {
  165. $.ajax({
  166. url: 'https://api.imgur.com/3/image',
  167. headers: {
  168. 'Authorization': 'Client-ID 6ebabcf714f0bb3'
  169. },
  170. type: 'POST',
  171. data: {
  172. 'image': imgData.substr(22)
  173. },
  174. success: function(response) { prompt("Copy to clipboard: Ctrl+C, Enter", response.data.link); }
  175. });
  176. });
  177. };
  178. function printDollarCount (results) {
  179. $(".container-content:eq(1)").append('<div id="dollarCount" style="height:200px;width:350px;float:right;"></div>');
  180. for (var key in results) {
  181. hitCounter[results[key][2]] += results[key][0];;
  182. };
  183. var ticks = ['Sun','Mon','Tue','Wed','Thur','Fri','Sat'];
  184. var plot2 = $.jqplot('dollarCount', [[hitCounter[firstdy.toString()],hitCounter[seconddy.toString()],hitCounter[thirddy.toString()],hitCounter[fourthdy.toString()],
  185. hitCounter[fifthdy.toString()],hitCounter[sixthdy.toString()],hitCounter[seventhdy.toString()]]], {
  186. animate: !$.jqplot.use_excanvas,
  187. seriesDefaults:{
  188. renderer:$.jqplot.BarRenderer,
  189. rendererOptions: {fillToZero: true},
  190. pointLabels: {
  191. show: true,
  192. hideZeros: true,
  193. location: 'n',
  194. formatString: '$%#.2f',
  195. ypadding: 1
  196. }
  197. },
  198. series:[
  199. {label:firstdy.toString()},
  200. {label:seconddy.toString()},
  201. {label:thirddy.toString()},
  202. {label:fourthdy.toString()},
  203. {label:fifthdy.toString()},
  204. {label:sixthdy.toString()},
  205. {label:seventhdy.toString()}
  206. ],
  207. title: {
  208. text: 'Daily Earnings (Current Week)',
  209. fontFamily: '"Trebuchet MS", Arial, Helvetica, sans-serif',
  210. fontSize: '10pt',
  211. textColor: '#666666'
  212. },
  213. axes: {
  214. xaxis: {
  215. tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
  216. tickOptions: {
  217. //angle: -15,
  218. fontSize: '8pt',
  219. showGridline: false
  220. },
  221. renderer: $.jqplot.CategoryAxisRenderer,
  222. ticks: ticks
  223. },
  224. yaxis: {
  225. tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
  226. tickOptions: {
  227. fontSize: '8pt',
  228. prefix: '$',
  229. markSize: '0'
  230. },
  231. pad: 1.2,
  232. min: 0
  233. }
  234. }
  235. });
  236. var imgData = $('#dollarCount').jqplotToImageStr({});
  237. $('#dollarCount').on('click',function () {
  238. $.ajax({
  239. url: 'https://api.imgur.com/3/image',
  240. headers: {
  241. 'Authorization': 'Client-ID 6ebabcf714f0bb3'
  242. },
  243. type: 'POST',
  244. data: {
  245. 'image': imgData.substr(22)
  246. },
  247. success: function(response) { prompt("Copy to clipboard: Ctrl+C, Enter", response.data.link); }
  248. });
  249. });
  250. }
  251. HITpull();