Cpubenckmark.net FIlter

Adds ability to filter CPU by name, price range and score range on cpubenchmark.net

当前为 2016-07-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Cpubenckmark.net FIlter
  3. // @namespace condorianocpubenchmark.net
  4. // @description Adds ability to filter CPU by name, price range and score range on cpubenchmark.net
  5. // @version 0.1
  6. // @author condoriano
  7. // @include http://www.cpubenchmark.net/high_end_cpus.html*
  8. // @include http://www.cpubenchmark.net/mid_range_cpus.html*
  9. // @include http://www.cpubenchmark.net/midlow_range_cpus.html*
  10. // @include http://www.cpubenchmark.net/low_end_cpus.html*
  11. // @include http://www.cpubenchmark.net/common_cpus.html*
  12. // @include http://www.cpubenchmark.net/overclocked_cpus.html
  13. // @include http://www.cpubenchmark.net/multi_cpu.html*
  14. // @include http://www.cpubenchmark.net/singleThread.html
  15. // @include http://www.cpubenchmark.net/socketType.html
  16. // @include http://www.cpubenchmark.net/laptop.html
  17. // @include http://www.cpubenchmark.net/power_performance.html
  18. // @grant none
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. var i = 0;
  25. var style = document.createElement('style');
  26. style.innerHTML = '#filterDiv input[type="number"] { width: 60px; } #filterDiv .filter { display: inline-block; min-width: 33%; margin: 3px 0px; } #filterDiv .full { width: 100%; text-align: center; }';
  27. document.head.appendChild(style);
  28.  
  29. var filterDiv = document.createElement('div');
  30. filterDiv.id = 'filterDiv';
  31. filterDiv.style = 'background-color: #FFFF77; width: 700px; margin: 10px auto 30px; border: 1px dashed #FF7777; padding: 6px 12px; font-family: Tahoma; color: #222; font-size: 13px;';
  32. filterDiv.innerHTML += '<div style="font-size: 18px; font-family: Georgia; padding: 3px 0px; text-align: center; margin-bottom: 8px; background-color: #FFAA33;">Filters</div>\
  33. <form name="tablefilter"><div class="filter full">Name: <select name="namemode"><option value="show">Show</option><option value="hide">Hide</option> </select> <input name="name" type="text" placeholder="Accepts multiple values (separate each with a comma)" style="width: 500px;"></div>\
  34. <div class="filter">Price: <input name="pricemin" type="number" placeholder="min"> to <input name="pricemax" type="number" placeholder="max"></div>\
  35. <div class="filter">Score: <input name="scoremin" type="number" placeholder="min"> to <input name="scoremax" type="number" placeholder="max"></div>\
  36. <div class="filter" style="text-align: right;"><input style="background-color: #7F7; border: 1px solid #080; cursor: pointer;" type="submit" value="Apply Filter"> <input style="background-color: transparent; border: none; box-shadow: none; color: #F00; cursor: pointer;" type="reset" name="reset" value="Reset Filter"></div></form>';
  37. document.getElementsByClassName('chart')[0].parentElement.parentElement.insertBefore(filterDiv, document.getElementsByClassName('chart')[0].parentElement);
  38.  
  39. document.forms.tablefilter.onsubmit = function(e) {
  40. document.activeElement.blur();
  41. e.preventDefault();
  42. var tables = document.querySelectorAll('table.chart'), filterNames = [];
  43. for(i = 0; i < tables.length; i++) {
  44. var row = tables[i].tBodies[0].rows;
  45. for(var j = 1; j < row.length; j++) {
  46. row[j].style.display = '';
  47. filterNames = document.forms.tablefilter.elements.name.value.replace(/[ , ]+/g, ',').split(',');
  48. if(filterNames.length && document.forms.tablefilter.elements.name.value) {
  49. if(document.forms.tablefilter.elements.namemode.value == 'show') row[j].style.display = 'none';
  50. else row[j].style.display = '';
  51. for(var k = 0; k < filterNames.length; k++) {
  52. if(filterNames[k] === '') continue;
  53. if(document.forms.tablefilter.elements.namemode.value == 'show') { if(row[j].cells[0].children[0].innerHTML.toLowerCase().indexOf(filterNames[k].toLowerCase()) != -1) row[j].style.display = ''; }
  54. else { if(row[j].cells[0].children[0].innerHTML.toLowerCase().indexOf(filterNames[k].toLowerCase()) != -1) row[j].style.display = 'none'; }
  55. }
  56. }
  57. var pMin, pMax;
  58. if(document.forms.tablefilter.elements.pricemin.value && document.forms.tablefilter.elements.pricemax.value) {
  59. pMin = document.forms.tablefilter.elements.pricemin.value;
  60. pMax = document.forms.tablefilter.elements.pricemax.value;
  61. var price = parseFloat(row[j].cells[2].children[0].innerHTML.replace(/[^0-9.]/g, ''));
  62. if(price < pMin || price > pMax || !price) row[j].style.display = 'none';
  63. }
  64. var sMin, sMax;
  65. if(document.forms.tablefilter.elements.scoremin.value && document.forms.tablefilter.elements.scoremax.value) {
  66. sMin = document.forms.tablefilter.elements.scoremin.value;
  67. sMax = document.forms.tablefilter.elements.scoremax.value;
  68. var score = parseFloat(row[j].cells[1].children[0].textContent.replace(/[^0-9.]/g, ''));
  69. if(j < 10) console.log(sMin + ', ' + sMax);
  70. if(score < sMin || score > sMax) row[j].style.display = 'none';
  71. }
  72. }
  73. }
  74. };
  75.  
  76. })();