WebSQL浏览器高版本已经不支持了,IndexedDB又不好用,我重新考虑自己来对数组进行查询。
门槛更低,不需要数据库支持了。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CPU列表</title>
<style>
h1 { text-align:center; }
button { margin: 5px; }
table { margin:10px auto; border-collapse:collapse; }
th, td { text-align:center; padding:10px; border:1px solid black; }
</style>
</head>
<body>
<h1>CPU</h1>
<div align="center"><input type="text" id="input_search"> <button id="button_search">搜索</button></div>
<div align="center">支持 core|thread 搜索</div>
<div id="nav1" align="center"></div>
<div id="nav2" align="center"></div>
<table id="table"></table>
<p align="center">参考:
<a href="https://www.ijrsoftware.com/cpu-l/" target="_blank">CPU-L</a>
<a href="https://www.mydrivers.com/zhuanti/tianti/cpu/index.html" target="_blank">桌面CPU性能天梯图</a>
<a href="https://www.cnblogs.com/kissdodog/p/3297894.html" target="_blank">树形数据库设计</a>
<a href="https://www.intel.com/" target="_blank">intel</a>
<a href="https://www.amd.com/" target="_blank">AMD</a>
</p>
<p align="center">© Copyright 2024 海天鹰版权所有 sonichy@163.com</p>
<script>
var cpus = [['0/', 'CPU', '', '', '', '', '', '', '', ''],
['0/0', 'intel', '', '', '', '', '', '', '', ''],
['0/1', 'AMD', '', '', '', '', '', '', '', ''],
['0/0/0', 'Celeron', '', '', '', '', '', '', '', ''],
['0/0/1', 'Pentium', '', '', '', '', '', '', '', ''],
['0/0/2', 'i3', '', '', '', '', '', '', '', ''],
['0/0/3', 'i5', '', '', '', '', '', '', '', ''],
['0/0/4', 'i7', '', '', '', '', '', '', '', ''],
['0/0/5', 'i9', '', '', '', '', '', '', '', ''],
['0/0/6', 'XEON', '', '', '', '', '', '', '', ''],
['0/0/0/0', 'Celeron G530', 'Sandy Bridge', '2011', '32nm', '2', '2', 'HD Graphic', 'LGA1155', '65W'],
['0/0/0/0', 'Celeron G1610', 'Ivy Bridge', '2013 Q1', '22nm', '2', '2', 'HD Graphic', 'LGA1155', '55W'],
['0/0/1/0', 'Pentium G620', 'Sandy Bridge', '2011', '32nm', '2', '2', 'HD Graphic', 'LGA1155', '65W'],
['0/0/1/0', 'Pentium G2010', 'Ivy Bridge', '2013 Q1', '22nm', '2', '2', 'HD Graphic', 'LGA1155', '55W'],
['0/0/1/0', 'Pentium G3220', 'Haswell', '2013 Q3', '22nm', '2', '2', 'HD Graphic', 'LGA1150', '53W'],
['0/0/1/0', 'Pentium G4400', 'Skylake', '2015 Q3', '14nm', '2', '2', 'HD Graphic 510', 'LGA1151', '54W'],
['0/0/1/0', 'Pentium G4560', 'Kaby Lake', '2017 Q1', '14nm', '2', '4', 'HD Graphic 610', 'LGA1151', '54W'],
['0/0/2/0', 'i3 530', 'Westmere', '2009', '32nm', '2', '4', 'HD Graphic', 'LGA1156', '73W'],
['0/0/2/0', 'i3 2100', 'Sandy Bridge', '2011', '32nm', '2', '4', 'HD Graphic 2000', 'LGA1155', '65W'],
['0/0/2/0', 'i3 3210', 'Ivy Bridge', '2013 Q1', '22nm', '2', '4', 'HD Graphic 2500', 'LGA1155', '65W'],
['0/0/2/0', 'i3 4130', 'Haswell', '2013 Q3', '22nm', '2', '4', 'HD Graphic 4400', 'LGA1150', '54W'],
['0/0/2/0', 'i3 6100', 'Skylake', '2015 Q3', '14nm', '2', '4', 'HD Graphic 530', 'LGA1151', '51W'],
['0/0/3/0', 'i5 650', 'Westmere', '2010 Q1', '32nm', '2', '4', 'HD Graphic', 'LGA1156', '73W'],
['0/0/3/0', 'i5 750', 'Nehalem', '2010 Q1', '45nm', '4', '4', '-', 'LGA1156', '95W'],
['0/0/4/0', 'i7 860', 'Nehalem', '2009 Q3', '45nm', '4', '8', '-', 'LGA1156', '95W'],
['0/0/6/0', 'Xeon X3440', 'Nehalem', '2009 Q3', '45nm', '4', '8', '-', 'LGA1156', '95W'],
['0/0/6/0', 'Xeon E3-1260L', 'Sandy Bridge', '2011', '32nm', '4', '8', 'HD Graphic 2000', 'LGA1155', '45W'],
['0/1/0', 'Athlon', '', '', '', '', '', '', '', ''],
['0/1/1', 'A4', '', '', '', '', '', '', '', ''],
['0/1/2', 'A6', '', '', '', '', '', '', '', ''],
['0/1/3', 'A8', '', '', '', '', '', '', '', ''],
['0/1/4', 'A9', '', '', '', '', '', '', '', ''],
['0/1/5', 'A10', '', '', '', '', '', '', '', ''],
['0/1/6', 'A12', '', '', '', '', '', '', '', ''],
['0/1/0/0', 'Athlon II X4 600e', 'K10', '2009 Q4', '45nm', '4', '4', '-', 'AM3', '45W'],
['0/1/0/0', 'Athlon X4 740', 'Richland', '2012 Q4', '32nm', '4', '4', '-', 'Socket FM2', '65W'],
['0/1/0/0', 'Athlon 200GE', 'Zen', '2018/09/06', '14nm', '2', '4', 'Radeon Vega 3', 'AM4', '35W'],
['0/1/0/1', 'Athlon 3000G', 'Zen', '2019/11', '14nm', '2', '4', 'Radeon Vega 3', 'AM4', '35W'],
['0/1/0/1', 'Athlon Gold 3150G', 'Zen+', '2020 Q3', '12nm', '4', '4', 'Radeon Vega 3', 'AM4', '65W'],
['0/1/1/0', 'A4 5300', 'Trinity', '2013/06/05', '32nm', '2', '2', 'Radeon HD7480D', 'Socket FM2', '65W'],
['0/1/1/0', 'A4 6300', 'Richland', '2012 Q4', '32nm', '2', '2', 'Radeon HD8370D', 'Socket FM2', '65W'],
['0/1/3/0', 'A8 7500', 'Kaveri', '2016 Q2', '32nm', '4', '4', 'Radeon R7', 'Socket FM2+', '65W']];
button_search.onclick = function() { search(input_search.value); }
input_search.onkeypress = function(e) {
if (e.keyCode == 13)
search(input_search.value);
}
function class1() {
for (i = 0; i < cpus.length; i++) {
if (cpus[i][0].length == 3) {
var button = document.createElement('button');
button.className = "class1";
button.textContent = cpus[i][1];
button.value = cpus[i][0];
button.onclick = function () {
class2(this.value);
var class1 = document.getElementsByClassName("class1");
for (j = 0; j < class1.length; j++) {
class1[j].style.backgroundColor = "";
}
this.style.backgroundColor = "lightblue";
};
nav1.append(button);
}
}
}
class1();
function class2(path) {
nav2.innerHTML = '';
for (var i = 0; i < cpus.length; i++) {
if (cpus[i][0].length == 5 && cpus[i][0].startsWith(path)) {
var button = document.createElement('button');
button.className = "class2";
button.textContent = cpus[i][1];
button.value = cpus[i][0];
button.onclick = function () {
search(this.value);
var class2 = document.getElementsByClassName("class2");
for (var j = 0; j < class2.length; j++) {
class2[j].style.backgroundColor = "";
}
this.style.backgroundColor = "lightblue";
};
nav2.append(button);
}
}
}
function tableHead() {
var tr = document.createElement('tr');
var th = document.createElement('th');
th.textContent = 'id';
tr.append(th);
th = document.createElement('th');
th.textContent = 'path';
tr.append(th);
th = document.createElement('th');
th.textContent = 'model';
tr.append(th);
th = document.createElement('th');
th.textContent = 'architecture';
tr.append(th);
th = document.createElement('th');
th.textContent = 'release_date';
tr.append(th);
th = document.createElement('th');
th.textContent = 'lithography';
tr.append(th);
th = document.createElement('th');
th.textContent = 'core';
tr.append(th);
th = document.createElement('th');
tr.append(th);
th.textContent = 'thread';
tr.append(th);
th = document.createElement('th');
th.textContent = 'GPU';
tr.append(th);
th = document.createElement('th');
th.textContent = 'package';
tr.append(th);
th = document.createElement('th');
th.textContent = 'TDP';
tr.append(th);
table.append(tr);
}
function search(s) {
table.innerHTML = '';
tableHead();
var c = 1;
for (i = 0; i < cpus.length; i++) {
var tr = document.createElement('tr');
var td = document.createElement('td');
td.textContent = c;
tr.append(td);
var isAppend = false;
if (s.includes('|')) {
var ct = s.split('|');
if (cpus[i][5] == ct[0] && cpus[i][6] == ct[1])
isAppend = true;
} else if (s.includes('/')) {
if (cpus[i][0].length == 7 && cpus[i][0].startsWith(s))
isAppend = true;
}
for (j = 0; j < cpus[i].length; j++) {
td = document.createElement('td');
td.textContent = cpus[i][j];
tr.append(td);
if (j > 0 && cpus[i][j].toLowerCase().includes(s.toLowerCase())) {
isAppend = true;
}
}
if (isAppend) {
table.append(tr);
c++;
}
}
}
search('');
</script>
</body>
</html>