auto mark

华理评选教系统

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

  1. // ==UserScript==
  2. // @name auto mark
  3. // @namespace 华理评选教系统自动评分
  4. // @description 华理评选教系统
  5. // @version 1.310
  6. // @include http://pjb.ecust.edu.cn/pingce/*
  7. // ==/UserScript==
  8.  
  9.  
  10. //辅助函数
  11. function loadStyle(css){
  12. if(typeof GM_addStyle!='undefined') {
  13. GM_addStyle(css);
  14. }
  15. else{
  16. var heads=document.getElementsByTagName('head');
  17. if(heads.length>0){
  18. var node=document.createElement('style');
  19. node.type='text/css';
  20. node.appendChild(document.createTextNode(css));
  21. heads[0].appendChild(node);
  22. }
  23. }
  24. }
  25. function $(id){
  26. 'use script';
  27. if(typeof id != 'undefined'){
  28. return document.getElementById(id);
  29. }
  30. }
  31.  
  32.  
  33. var b = document.getElementsByTagName('input');
  34. var table = document.getElementsByTagName('table')[1];
  35. var k = 0 , sum = 0;
  36. var a = [b[0]];
  37. for( var i = 0, l = b.length; i < l; i++ ){
  38. if( b[i].type == 'radio' ) {
  39. a[++k] = b[i];
  40. }
  41. }
  42. for ( var i = 1, len = a.length, dif = a[1].value - a[0].value; i < len ; i++){
  43. dif = Math.abs( a[i].value - a[i == 0 ? 0 : i - 1].value ) > dif ? dif : Math.abs( a[i].value - a[i - 1].value );
  44. }
  45.  
  46. var isopen = 'closed';
  47.  
  48.  
  49. //添加按钮
  50. var float_window = document.createElement( 'div' );
  51. var float_button = document.createElement( 'div' );
  52. var float_content = document.createElement( 'div' );
  53. float_button.id = 'float_button';
  54. float_window.id = 'float_window';
  55. float_content.id = 'float_content';
  56. float_button.innerHTML = '<';
  57. document.body.appendChild( float_window );
  58. float_window.appendChild( float_button );
  59. float_window.appendChild( float_content );
  60. var box = '<div id = "score">分数在40到100之间</div>';
  61. box += '<div>';
  62. box += '<input type = "button" id = "haoping" value="好评"/>';
  63. box += '<input type = "button" id = "chaping" value="差评"/>';
  64. box += '</div>';
  65. box += '<div>';
  66. box += '<input type = "button" id = "suiji" value="随机"/>';
  67. box += '<label>大于等于</label>';
  68. box += '<input id = "range_low" class = "range" type="text" maxlength = 3></input>';
  69. box += '<label>小于等于</label>';
  70. box += '<input id = "range_upper" class = "range" type="text" maxlength = 3></input>';
  71. box += '</div>';
  72. float_content.innerHTML = box;
  73. var hpbutton = $('haoping');
  74. var cpbutton = $('chaping');
  75. var sjbutton = $('suiji');
  76. var score = $('score');
  77.  
  78. var css = "@namespace url(http://www.w3.org/1999/xhtml);";
  79. css += '#float_window{ background-color:#FCFCFC;width:14px;height:14px;top:20%;right:10px;position:fixed;padding:4px;border:2px;border-radius:4px;box-shadow:0px 0px 8px #dddddd;z-index:9999; }';
  80. css += '#float_window >*{margin:2px;}';
  81. css += '#float_window input[type="button"]{border:1px solid #BBBBBB;border-radius:3px;background-color:#FCFCFC;margin:3px;}';
  82. css += '#float_content{ background-color:#f7f7f7;padding:1px;border:1px solid rgb(221,221,221);border-radius:4px;display:none;overflow:hidden; }';
  83. css += '#float_button{ background-color:whitesmoke;width:16px;height:16px;position:absolute;top:0px;right:0px;border:1px solid #BBBBBB;border-radius:4px;text-align:center;cursor:pointer;z-Index:9 }';
  84. css += '#score{margin:3px;position: relative;left:6px;font-size:14px}';
  85. css += 'input.range{width:30px;}'
  86. loadStyle(css);
  87.  
  88. float_button.addEventListener( 'click',showmenu,false );
  89.  
  90. function showmenu(){
  91. var floatWindowWidthMax = 220;
  92. var floatWindowHeightMax = 86;
  93. var floatWindowWidthMin = 14;
  94. var floatWindowHeightMin = 14;
  95. if( isopen == 'closed' ){
  96. float_button.innerHTML = '>';
  97. float_content.style.display = 'block';
  98. var w_width = floatWindowWidthMin;
  99. var w_height = floatWindowHeightMin;
  100. var timer = setInterval( function(){
  101. if( w_height < floatWindowHeightMax ){
  102. float_window.style.width = w_width + 'px';
  103. float_window.style.height = w_height + 'px';
  104. float_content.style.width = w_width - 8 + 'px';
  105. float_content.style.height = w_height - 8 + 'px';
  106. w_width += ( floatWindowWidthMax - floatWindowWidthMin ) / 100;
  107. w_height += ( floatWindowHeightMax - floatWindowHeightMin ) / 100;
  108. }else{
  109. clearInterval( timer );
  110. }
  111. },5)
  112. float_window.addEventListener( 'mouseleave',fadeout,false);
  113. float_window.addEventListener( 'mouseenter',fadein,false);
  114. isopen = 'opened';
  115. }
  116. else if ( isopen == 'opened' ){
  117. float_window.removeEventListener( 'mouseleave',fadeout,false );
  118. float_window.removeEventListener( 'mouseenter',fadein,false );
  119. float_button.innerHTML = '<';
  120. w_width = floatWindowWidthMax;
  121. w_height = floatWindowHeightMax;
  122. var timer = setInterval( function(){
  123. if( w_width > floatWindowWidthMin ){
  124. w_width -= ( floatWindowWidthMax - floatWindowWidthMin ) / 100;
  125. w_height -= ( floatWindowHeightMax - floatWindowHeightMin ) / 100;
  126. float_window.style.width = w_width + 'px';
  127. float_window.style.height = w_height + 'px';
  128. float_content.style.width = w_width - 8 + 'px';
  129. float_content.style.height = w_height - 8 + 'px';
  130. }else{
  131. clearInterval( timer );
  132. }
  133. },5)
  134. isopen = 'closed';
  135. }
  136. }
  137. function fadeout(){
  138. var opac = float_window.style.opacity >= 1 ? float_window.style.opacity * 1 : 1;
  139. var timer = setInterval( function(){
  140. if( opac > 0.4 ){
  141. opac -= 0.1;
  142. float_window.style.opacity = opac;
  143. }
  144. else{
  145. clearInterval( timer );
  146. }
  147. },30)
  148. }
  149. function fadein(){
  150. var opac = float_window.style.opacity * 1;
  151. var timer = setInterval( function(){
  152. if( opac < 1.0 ){
  153. opac += 0.1;
  154. float_window.style.opacity = opac;
  155. }
  156. else{
  157. clearInterval( timer );
  158. }
  159. },30)
  160. }
  161.  
  162. //评价函数
  163. hpbutton.addEventListener('click',haoping,false);
  164. cpbutton.addEventListener('click',chaping,false);
  165. sjbutton.addEventListener('click',suiji,false);
  166.  
  167. function haoping(){
  168. sum = 0;
  169. for ( var i = 1, l = a.length; i < l - 1; i++) {
  170. if( i == 1 ? 1 : ( a[i].value * 1 > a[i + 1].value * 1 ) && a[i].value * 1 > a[i - 1].value * 1){
  171. a[i].checked = 'checked';
  172. sum += a[i].value * 1;
  173. }
  174. }
  175. score.innerHTML = '总分:' + sum;
  176. }
  177.  
  178. function chaping(){
  179. sum = 0;
  180. for ( var i = 1, l = a.length; i < l ; i++){
  181. if( i == l - 1 ? 1 : (a[i].value * 1 < a[i + 1].value * 1) && a[i].value * 1 < a[i - 1].value * 1){
  182. a[i].checked = 'checked';
  183. sum += a[i].value * 1;
  184. }
  185. }
  186. score.innerHTML = '总分:' + sum;
  187. }
  188.  
  189. function suiji(){
  190. var upper = $('range_upper').value;
  191. var low = $('range_low').value;
  192. upper = parseInt( upper == '' ? 100 : upper );
  193. low = parseInt( low == '' ? 40 : low );
  194. if(!(upper <= 100 && upper >= 40 && low >= 40 && low <= 100)){
  195. warning( Math.floor(Math.random() * 2 + 1),0);
  196. $('range_upper').value = '';
  197. $('range_low').value = '';
  198. score.innerHTML = '分数在40到100之间';
  199. }
  200. else if( low > upper ){
  201. warning( Math.floor(Math.random() * 2 + 1),1);
  202. $('range_upper').value = '';
  203. $('range_low').value = '';
  204. score.innerHTML = '分数在40到100之间';
  205. }
  206. else if( upper - low < dif && dif > 1 ){
  207. warning( Math.floor(Math.random() * 2 + 1),2);
  208. $('range_upper').value = '';
  209. $('range_low').value = '';
  210. score.innerHTML = '分数在40到100之间';
  211. }
  212. else{
  213. random(upper,low);
  214. }
  215. }
  216.  
  217. function random(upper,low){
  218. sum = 0;
  219. for( var j = 0 , l = (a.length - 1) / 4; j < l; j++){
  220. var index = Math.floor( Math.random() * 4 + 1);
  221. a[4 * j + index].checked = true;
  222. sum += a[4 * j + index].value * 1;
  223. }
  224. var row;
  225. var line;
  226. while(sum < low || sum > upper){
  227. row = Math.floor( Math.random() * l );
  228. for(var i = 1; i < 5; i++){
  229. if(a[4 * row + i].checked == true) line = i;
  230. }
  231. if(sum < low){
  232. var min = a[4 * row + line].value * 1;
  233. line = line == 1 ? 1 : Math.floor( Math.random() * (line - 1) + 1 );
  234. a[4 * row + line].checked = true;
  235. sum += a[4 * row + line].value * 1 - min;
  236. }
  237. if(sum > upper){
  238. var max = a[4 * row + line].value * 1;
  239. line = line == 4 ? 4 : Math.floor( Math.random() * (4 - line) + line );
  240. a[4 * row + line].checked = true;
  241. sum -= max - a[4 * row + line].value * 1;
  242. }
  243. }
  244. score.innerHTML = '总分:' + sum;
  245. }
  246.  
  247. //警告
  248. function warning(style,id){
  249. switch(style){
  250. case 1 :
  251. switch(id){
  252. case 0 :
  253. alert('魂淡,都说了数字在40到100之间啊o( ̄ヘ ̄o#)');
  254. break;
  255. case 1 :
  256. alert('魂淡,给我分清大小啊喂Σ(っ °Д °;)っ ');
  257. break;
  258. case 2 :
  259. alert('魂淡,差值那么小算不了啦( ̄△ ̄;) ');
  260. break;
  261. }
  262. break;
  263. case 2 :
  264. switch(id){
  265. case 0 :
  266. alert('要填在40到100之间的数字哦(●ܫ●)');
  267. break;
  268. case 1 :
  269. alert('大小什么的搞错了哦(*▼︿▼)');
  270. break;
  271. case 2 :
  272. alert('差值不能那么小的啦╮( ̄▽ ̄")╭);
  273. break;
  274. }
  275. break;
  276. }
  277. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址