Passmark CPU/GPU Filter

Passmark CPU/GPU Filter by Brand, Model or Inputed Text

当前为 2020-03-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @namespace ATGT
  3. // @name Passmark CPU/GPU Filter
  4. // @version 2
  5. // @description Passmark CPU/GPU Filter by Brand, Model or Inputed Text
  6. // @author StrongOpx
  7. // @match https://www.cpubenchmark.net/cpu_lookup.php*
  8. // @match https://www.cpubenchmark.net/*_cpus.html*
  9. // @match https://www.videocardbenchmark.net/video_lookup.php*
  10. // @match https://www.videocardbenchmark.net/*_gpus.html
  11. // @grant none
  12. // @icon https://www.cpubenchmark.net/favicon.ico
  13. // @run-at document-end
  14. // ==/UserScript==
  15.  
  16.  
  17. console.log(`=== cpu benchmark filter on '${location.href}' ===`);
  18.  
  19. const active_bg_color = '#FFFFFF80';
  20. const inactive_bg_color = 'slategray';
  21. const active_fg_color = 'black';
  22. const inactive_fg_color = 'lightgray';
  23.  
  24. function gen_filter_keyword(kw_regex, prod_map) {
  25. let regex = new RegExp(kw_regex, 'i');
  26. let products = document.querySelectorAll('ul.chartlist .prdname');
  27. for (let prod of products) {
  28. let m = prod.innerText.match(regex);
  29. if (m && m.length >= 2) {
  30. let kw = m[1];
  31. kw = kw.replace(/(AMD|Intel)\s+/i, '').replace('-', '').replace(/\s+/, '\\s+');
  32. //console.log(`gen filter m ${m} kw ${kw}`);
  33. if (!(kw in prod_map))
  34. prod_map[kw] = {};
  35. }
  36. }
  37. return prod_map;
  38. }
  39.  
  40. function gen_filter_map(filter_map) {
  41. let products = document.querySelectorAll('ul.chartlist .prdname');
  42. for (let k of Object.keys(filter_map)) {
  43. let regex = filter_map['regex'];
  44. if (!regex) {
  45. regex = filter_map[k]['regex'] = new RegExp(k);
  46. }
  47. filter_map[k]['products'] = [];
  48. for (let prod of products) {
  49. //console.log('prod', prod.innerText);
  50. if (regex.test(prod.innerText)) {
  51. //console.log('Add prod', prod.innerText);
  52. filter_map[k]['products'].push(prod.parentNode.parentNode);
  53. }
  54. }
  55. }
  56. }
  57.  
  58. function gen_filter_toolbar(toolbar, filter_map) {
  59. function filter_action(event) {
  60. let tool = event.target;
  61. if (tool.className.indexOf('filter_tool') < 0) {
  62. tool = tool.parentNode;
  63. if (tool.className.indexOf('filter_tool') < 0) {
  64. return;
  65. }
  66. }
  67.  
  68. let active = tool.attributes['active'];
  69. //console.log('event on ', event.target, 'active', active);
  70. active = !active;
  71. tool.attributes['active'] = active;
  72. let display = active ? 'block' : 'none';
  73. for (let node of tool.attributes['map']) {
  74. //console.log('node of map ', node);
  75. node.style.display = display;
  76. }
  77. tool.style.backgroundColor = active ? active_bg_color : inactive_bg_color;
  78. tool.style.color = active ? active_fg_color : inactive_fg_color;
  79. if (node.className.indexOf('filter_all') >= 0) {
  80. for (let node of document.querySelectorAll('.filter_tool.filter_part')) {
  81. //console.log('alter', node);
  82. node.attributes['active'] = active;
  83. node.style.background = active ? active_bg_color : inactive_bg_color;
  84. node.style.color = active ? active_fg_color : inactive_fg_color;
  85. }
  86. }
  87. }
  88.  
  89. let container = document.createElement('DIV');
  90. container.className = 'filter_container';
  91. container.style.borderTop = 'dotted 6px white';
  92. container.style.textAlign = 'left';
  93. toolbar.appendChild(container);
  94.  
  95. let node;
  96. for (let k of Object.keys(filter_map).sort()) {
  97. node = document.createElement('DIV');
  98. let name = k.replace(/(\\\w\+?|\.)+/i, ' ');
  99. let prod_cnt = filter_map[k]['products'].length;
  100. if (prod_cnt == 0)
  101. continue;
  102. name += ` <span style='color: aliceblue;'>(${prod_cnt})</span>`
  103. node.innerHTML = name;
  104. node.style.border = '1px black solid';
  105. node.style.borderRadius = '4px';
  106. node.style.padding = '2px 4px';
  107. node.style.margin = '4px';
  108. node.style.cursor = 'pointer';
  109. node.style.textAlign = 'left';
  110. node.style.background = active_bg_color;
  111. node.style.color = active_fg_color;
  112. //node.style.float = 'left';
  113. node.addEventListener('click', filter_action, { capture: true });
  114. node.attributes['active'] = true;
  115. node.attributes['map'] = filter_map[k]['products'];
  116. if (name.search(/^\s*\.?\*\s*/) < 0)
  117. node.className = 'filter_tool filter_part';
  118. else
  119. node.className = 'filter_tool filter_all';
  120. container.appendChild(node);
  121. }
  122. return container;
  123. }
  124.  
  125. function gen_input_filter(header, all_cpu_map) {
  126. function update_filter(e) {
  127. let flt = e.target.value;
  128. try {
  129. flt = flt.replace(/\s+/, '.*');
  130. let regex = new RegExp(flt, 'i');
  131. let products = all_cpu_map[Object.keys(all_cpu_map)[0]]['products'];
  132. for (let node of products) {
  133. node.style.display = regex.test(node.innerText) ? 'block' : 'none';
  134. }
  135. } catch (e) {
  136. console.log('update filter for input error', e);
  137. }
  138. }
  139. let input = document.createElement('INPUT');
  140. input.type = 'text';
  141. input.style.margin = '2px 4px 6px 4px';
  142. input.style.width = '90%';
  143. input.addEventListener('input', update_filter);
  144. header.appendChild(input);
  145. }
  146.  
  147. function create_filter_toolbar() {
  148. let toolbar = document.createElement('DIV');
  149. //toolbar.innerText = 'Filter: ';
  150. toolbar.style.borderRadius = '4px';
  151. toolbar.style.lineHeight = '1em';
  152. toolbar.style.position = 'fixed';
  153. toolbar.style.right = '2px';
  154. toolbar.style.top = '120px';
  155. toolbar.style.backgroundColor = inactive_bg_color;
  156. toolbar.style.color = active_fg_color;
  157. toolbar.style.zIndex = '10000';
  158. toolbar.style.fontSize = 'small';
  159. toolbar.style.padding = '4px';
  160. toolbar.style.maxWidth = '10rem';
  161. toolbar.style.maxHeight = '80%';
  162. //toolbar.style.overflowY = 'scroll';
  163.  
  164. function fold_filters(event) {
  165. console.log('Fold Filters');
  166. let target = event.target;
  167. target.attributes['fold'] = !target.attributes['fold'];
  168. for (let node of document.querySelectorAll('.filter_container')) {
  169. node.style.display = target.attributes['fold'] ? 'none' : 'block';
  170. }
  171. }
  172.  
  173. let header_sub_div = document.createElement('DIV');
  174. toolbar.appendChild(header_sub_div);
  175.  
  176. let label = document.createElement('DIV');
  177. label.innerHTML = 'FILTERS';
  178. label.style.borderRadius = '4px';
  179. label.style.textAlign = 'center';
  180. label.style.padding = '2px';
  181. label.style.margin = '2px 2px 10px';
  182. label.style.cursor = 'pointer';
  183. label.style.fontWeight = 'bold';
  184. label.style.background = 'white';
  185. label.attributes['fold'] = false;
  186. label.onclick = fold_filters;
  187. header_sub_div.appendChild(label);
  188.  
  189. let tool_sub_div = document.createElement('DIV');
  190. tool_sub_div.className = 'filter_container';
  191. tool_sub_div.style.maxWidth = '100%';
  192. tool_sub_div.style.maxHeight = '30rem';
  193. tool_sub_div.style.overflowY = 'scroll';
  194. toolbar.appendChild(tool_sub_div);
  195.  
  196. document.body.appendChild(toolbar);
  197.  
  198. return [header_sub_div, tool_sub_div];
  199. }
  200.  
  201. function filter_cpus() {
  202. if (!/cpu/i.test(location.href)) {
  203. return;
  204. }
  205.  
  206. let [header, tools] = create_filter_toolbar();
  207.  
  208. let all_cpu_map = {
  209. '.*': {}
  210. };
  211.  
  212. let intel_cpu_map = {
  213. 'Intel': {},
  214. };
  215.  
  216. let amd_cpu_map = {
  217. 'AMD': {},
  218. };
  219.  
  220. gen_filter_map(all_cpu_map);
  221. let container = gen_filter_toolbar(header, all_cpu_map);
  222. gen_input_filter(container, all_cpu_map);
  223.  
  224. gen_filter_keyword('(Intel\\s+(?:[a-zA-Z]+\\s+)(?:[a-zA-Z][\\d-]|\\d|[a-zA-Z]{2,}))', intel_cpu_map);
  225. gen_filter_map(intel_cpu_map);
  226. gen_filter_toolbar(tools, intel_cpu_map);
  227.  
  228. gen_filter_keyword('(AMD\\s+(?:[a-zA-Z]+\\s+)(?:[a-zA-Z][\\d-]|\\d|[a-zA-Z]{2,}))', amd_cpu_map);
  229. gen_filter_map(amd_cpu_map);
  230. gen_filter_toolbar(tools, amd_cpu_map);
  231.  
  232. /*
  233. for (let k of Object.keys(cpu_map)) {
  234. console.log('k', k, cpu_map[k]);
  235. }
  236. */
  237.  
  238. }
  239.  
  240. function filter_gpus() {
  241. if (!/gpu/i.test(location.href)) {
  242. return;
  243. }
  244.  
  245. let [header, tools] = create_filter_toolbar();
  246.  
  247. let all_gpu_map = {
  248. '.*': {}
  249. };
  250.  
  251. let intel_gpu_map = {
  252. };
  253.  
  254. let nvidia_gpu_map = {
  255. };
  256.  
  257. let amd_gpu_map = {
  258. };
  259.  
  260. gen_filter_map(all_gpu_map);
  261. let container = gen_filter_toolbar(header, all_gpu_map);
  262. gen_input_filter(container, all_gpu_map);
  263.  
  264. gen_filter_keyword('((?:Intel)\\s+(?:[a-zA-Z]+\\s+)?(?:[a-zA-Z][\\d-]|\\d|[a-zA-Z]{2,}))', intel_gpu_map);
  265. gen_filter_map(intel_gpu_map);
  266. gen_filter_toolbar(tools, intel_gpu_map);
  267.  
  268. gen_filter_keyword('((?:Nvidia|Geforce|TITAN|Quadro|Tesla)\\s+(?:[a-zA-Z]+\\s+)?(?:[a-zA-Z][\\d-]|\\d+(?=\\d\\d\\s)|[a-zA-Z]{2,}))', nvidia_gpu_map);
  269. gen_filter_map(nvidia_gpu_map);
  270. gen_filter_toolbar(tools, nvidia_gpu_map);
  271.  
  272. gen_filter_keyword('((?:AMD|Radeon|FirePro)\\s+(?:[a-zA-Z]+\\s+)?(?:[a-zA-Z][\\d-]|\\d|[a-zA-Z]{2,}))', amd_gpu_map);
  273. gen_filter_map(amd_gpu_map);
  274. gen_filter_toolbar(tools, amd_gpu_map);
  275.  
  276. /*
  277. for (let k of Object.keys(gpu_map)) {
  278. console.log('k', k, gpu_map[k]);
  279. }
  280. */
  281.  
  282. }
  283.  
  284. filter_cpus();
  285.  
  286. filter_gpus();
  287.  
  288. console.log(`=== /cpu benchmark filter on '${location.href}' ===`);
  289.  
  290.  
  291. /*
  292. let intel_cpu_map = {
  293. 'Atom': {},
  294. 'Celeron': {},
  295. 'Core\\s+i3': {},
  296. 'Core\\s+i5': {},
  297. //'Core\\s+i7': {},
  298. //'Core\\s+i9': {},
  299. 'Core': {},
  300. 'Pentium': {},
  301.  
  302. //'Xeon\\s+X': {},
  303. 'Xeon\\s+D': {},
  304. 'Xeon\\s+E3': {},
  305. 'Xeon\\s+E5': {},
  306. 'Xeon\\s+W': {},
  307. 'Xeon\\s+Silver': {},
  308. 'Xeon\\s+Gold': {},
  309. //'Xeon\\s+Platinum': {},
  310.  
  311. 'Xeon': {},
  312. };
  313.  
  314. let amd_cpu_map = {
  315. 'Athlon': {},
  316.  
  317. 'FX': {},
  318.  
  319. 'Opteron': {},
  320.  
  321. 'Ryzen\\s+3': {},
  322. 'Ryzen\\s+5': {},
  323. 'Ryzen\\s+7': {},
  324.  
  325. 'EPYC\\s+3': {},
  326. 'EPYC\\s+7': {},
  327. 'Threadripper': {},
  328. };
  329. */