' + newMsg + '
';
toast.style.backgroundColor = "#AE0034";
launch_toast();
//toast.innerHTML = oldText;
//toast.style.backgroundColor = oldBgColor;
}
}
_AddCPU(CPUId, CPUName, CPUCount) {
CPUCount = typeof CPUCount !== 'undefined' ? parseInt(CPUCount) : 1;
CPUId = parseInt(CPUId);
for( var i = 0; i < this.CPUs.length; i++ )
if( this.CPUs[i].CPUId == CPUId && this.CPUs[i].CPUCount == CPUCount )
return true; // Already added
if( this.CPUs.length < MAX_COMPARE )
{
console.log( "Index: "+this.CPUs.length+", CPUId: "+CPUId+", CPUName: "+CPUName+", CPUCount: "+CPUCount);
this.CPUs.push(new CPU(CPUId, CPUName, CPUCount));
return true;
}
return false;
}
removeCPU(CPUId, CPUCount) {
if( this._RemoveCPU(CPUId, "", CPUCount) )
{
let _this = this;
$.ajax({
type: "POST",
url: "/compareAjax.php",
data: {
action: "remove",
cpuid: CPUId,
cpucount: CPUCount
},
success: function( data ) {
console.log(data);
_this.UpdateGUI();
},
});
}
}
_RemoveCPU(CPUId, CPUName, CPUCount) {
CPUCount = typeof CPUCount !== 'undefined' ? CPUCount : 1;
for( var i = 0; i < this.CPUs.length; i++ )
if( this.CPUs[i].CPUId == CPUId && this.CPUs[i].CPUCount == CPUCount )
{
this.CPUs.splice(i,1);
return true;
}
return false;
}
removeAll() {
this.CPUs.length = 0;
let _this = this;
$.ajax({
type: "POST",
url: "/compareAjax.php",
data: {
action: "removeAll"
},
success: function( data ) {
console.log(data);
_this.UpdateGUI();
},
});
}
_RemoveAll() {
this.CPUs.length = 0;
}
CompareCPUs(interactive) {
if( this.CPUs.length < 2 )
{
if(interactive) alert( "Minimum of 2 CPUs are required for comparison");
return;
}
// Build Param String
let paramString1 = "";
let paramString2 = "";
for( let i = 0; i < this.CPUs.length; i++ )
{
if( i )
{
paramString1 += " vs ";
paramString2 += "vs";
}
var name = this.CPUs[i].CPUName;
var n = name.indexOf("@");
if( n > 0 )
{
name = name.substr( 0, n-1 );
}
name = name.replace( /\//g, "", name );
name = name.replace( /Intel\sCore\b/i, "Intel " );
name = name.replace( /\s+/g, " ", name );
paramString1 += name;
paramString2 += "" + this.CPUs[i].CPUId;
if( typeof this.CPUs[i].CPUCount !== 'undefined' && Number.isInteger( this.CPUs[i].CPUCount ) && this.CPUs[i].CPUCount > 1 )
paramString2 += "." + this.CPUs[i].CPUCount.toString();
}
// Redirect to comparison page
let locationHref = "/compare";
window.location.href = encodeURI(locationHref +
"/" + paramString2 +
"/" + paramString1.replace(/\s/g, "-"));
}
}
function updateSidebar()
{
let objSidebar = document.getElementById("sidebar");
if( !objSidebar )
{
console.log( "Error: Object 'sidebar' not found!" );
return;
}
console.log( "UpdateSideBar() Max Compare: " + MAX_COMPARE );
console.log( myCmp.CPUs );
let pSidebar = document.getElementById("sidebar_default_text");
let tableSidebar = document.getElementById( "sidebar_table" );
let buttonSidebar = document.getElementById( "sidebar_button" );
let divTableSidebar = document.getElementById( "div_sidebar_table" );
pSidebar.style.display = (myCmp.CPUs.length < 2) ? "block":"none";
divTableSidebar.style.display = "block";
buttonSidebar.style.display = "block";
// Remove all CPUs
const tbody = document.getElementById('compbody');
if (tbody) {
// Get all tr elements inside the tbody
const rows = tbody.querySelectorAll('tr');
// Iterate over each row
rows.forEach(row => {
// If the row's id doesn't match the one to keep, remove it
if (row.id !== 'selectCPU') {
row.remove();
}
});
}
let i;
for( i = 0; i < myCmp.CPUs.length; i++ )
{
row = document.createElement( "TR" );
row.setAttribute( "id", "" + myCmp.CPUs[i].CPUId );
if( i % 2 ) row.setAttribute( "class", "alt" );
tableSidebar.tBodies[0].insertBefore(row, document.getElementById('selectCPU'));
col2 = row.insertCell();
col2.appendChild( document.createTextNode( "" + (i+1) + ": " + myCmp.CPUs[i].CPUName ));
col1 = row.insertCell( -1 );
col1.setAttribute( "class", "ta-center" );
let but = document.createElement( "button" );
but.appendChild( document.createTextNode("X") );
but.onclick = function(id, numCPUs) {
return function(){
myCmp.removeCPU(id, numCPUs );
anim();
};
}(myCmp.CPUs[i].CPUId, myCmp.CPUs[i].CPUCount > 1 ? myCmp.CPUs[i].CPUCount : 1);
col1.appendChild( but );
}
if( i < MAX_COMPARE )
{
$('#selectCPU').show();
if( i % 2 )
$('#selectCPU').addClass('alt');
else
$('#selectCPU').removeClass('alt');
}
else
{
$('#selectCPU').hide();
}
}
var myCmp = new MyCompare();
$(document).ready( function($) {
// Floating sidebar
$('#sidebar').portamento();
myCmp.UpdateGUI();
});
$('#autocomplete').autocomplete({
//lookup: lookupCPUs,
serviceUrl: '/autocomplete/cpu/',
onSelect: function(suggestion){
myCmp.addCPU( suggestion.data, suggestion.value, 1 );
},
noCache: false,
transformResult: function(response) {
let jsonObj = JSON.parse(response);
let abc = jsonObj.suggestions.slice(0,10);
return {suggestions: abc};
},
onSearchStart: function(params) {
//console.log("Before: "+params.query);
params.query = params.query.trim();
params.query = params.query.substring(0,40);
params.query = params.query.replace(/\(TM\)/i, "");
params.query = params.query.replace(/\(R\)/i, "");
if(/^(int|inte|intel)\b/i.test(params.query))
params.query = params.query.replace(/^(int|inte|intel)\b/i, "Intel ");
if(/\b(Xe|Xeo|Xeon)\b/i.test(params.query))
params.query = params.query.replace(/\b(Xe|Xeo|Xeon)\b/i, "Xeon ");
if(/\b(Ryz|Ryze|Ryzen)\b/i.test(params.query))
params.query = params.query.replace(/\b(Ryz|Ryze|Ryzen)\b/i, "Ryzen ");
if(/^(AM|AMD)\b/i.test(params.query))
params.query = params.query.replace(/^(AM|AMD)\b/i, "AMD ");
if(/^(Qua|Qual|Qualc)\b/i.test(params.query))
params.query = params.query.replace(/^(Qua|Qual|Qualc)\b/i, "Qualcomm ");
if(/\b(Pen|Pent)\b/i.test(params.query))
params.query = params.query.replace(/\b(Pen|Pent)\b/i, "Pentium ");
if(/^(App|Appl)\b/i.test(params.query))
params.query = params.query.replace(/^(App|Appl)\b/i, "Apple ");
params.query = params.query.replace(/\s+/g, ' ');
//console.log("After: "+params.query);
},
showNoSuggestionNotice: true,
noSuggestionNotice: "
Failed to locate CPU model. Try looking at mega list to see all names instead.",
width: 300,
minChars: 3,
lookupLimit: 10,
preventBadQueries: true,
params: {"compact": 1},
deferRequestBy: 500,
preserveInput: true
});
$("#sidebar_minimize, #sidebar_restore").click( function(event) {
event.preventDefault();
jQuery('#portamento_container').toggle( );
jQuery('#sb_restore').toggle();
});
$("#sidebar_button").on( "click", function() {
myCmp.CompareCPUs(true);
});
function anim() {
var indexcmp = document.getElementById('indexcmp');
if(indexcmp.innerHTML < MAX_COMPARE) {
$(".cmp-header a svg").addClass("anim-class");
$(".cmp-header .number-cmp").addClass("anim-bounce-class");
setTimeout(function () {
$(".cmp-header a svg").removeClass('anim-class');
}, 1500); }
}
function anim2() {
$(".cmp-header a svg").addClass("anim-class");
setTimeout(function () {
$(".cmp-header a svg").removeClass('anim-class');
}, 1500);
}
function launch_toast(toastID) {
//var indexcmp = document.getElementById("indexcmp");
var toast = document.getElementById("toast");
//toast.top = indexcmp.top+30;
toast.className = "show";
toast.style.display = "block";
setTimeout(function(){ toast.className = toast.className.replace("show", ""); }, 5000);
}