' + newMsg + '
';
toast.style.backgroundColor = "#AE0034";
launch_toast();
//toast.innerHTML = oldText;
//toast.style.backgroundColor = oldBgColor;
}
}
_AddGPU(GPUId, GPUName, GPUCount) {
GPUCount = typeof GPUCount !== 'undefined' ? parseInt(GPUCount) : 1;
GPUId = parseInt(GPUId);
for( var i = 0; i < this.GPUs.length; i++ )
if( this.GPUs[i].GPUId == GPUId && this.GPUs[i].GPUCount == GPUCount )
return true; // Already added
if( this.GPUs.length < MAX_COMPARE )
{
console.log( "Index: "+this.GPUs.length+", GPUId: "+GPUId+", GPUName: "+GPUName+", GPUCount: "+GPUCount);
this.GPUs.push(new GPU(GPUId, GPUName, GPUCount));
return true;
}
return false;
}
removeGPU(GPUId, GPUCount) {
if( this._RemoveGPU(GPUId, "", GPUCount) )
{
let _this = this;
$.ajax({
type: "POST",
url: "/compareAjax.php",
data: {
action: "remove",
gpuid: GPUId,
gpucount: GPUCount
},
success: function( data ) {
console.log(data);
_this.UpdateGUI();
},
});
}
}
_RemoveGPU(GPUId, GPUName, GPUCount) {
GPUCount = typeof GPUCount !== 'undefined' ? GPUCount : 1;
for( var i = 0; i < this.GPUs.length; i++ )
if( this.GPUs[i].GPUId == GPUId && this.GPUs[i].GPUCount == GPUCount )
{
this.GPUs.splice(i,1);
return true;
}
return false;
}
removeAll() {
this.GPUs.length = 0;
let _this = this;
$.ajax({
type: "POST",
url: "/compareAjax.php",
data: {
action: "removeAll"
},
success: function( data ) {
console.log(data);
_this.UpdateGUI();
},
});
}
_RemoveAll() {
this.GPUs.length = 0;
}
CompareGPUs(interactive) {
if( this.GPUs.length < 2 )
{
if(interactive) alert( "Minimum of 2 videocards are required for comparison.");
return;
}
// Build Param String
let paramString1 = "";
let paramString2 = "";
for( let i = 0; i < this.GPUs.length; i++ )
{
if( i )
{
paramString1 += " vs ";
paramString2 += "vs";
}
var name = this.GPUs[i].GPUName;
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.GPUs[i].GPUId;
if( typeof this.GPUs[i].GPUCount !== 'undefined' && Number.isInteger( this.GPUs[i].GPUCount ) && this.GPUs[i].GPUCount > 1 )
paramString2 += "." + this.GPUs[i].GPUCount.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.GPUs );
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.GPUs.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.GPUs.length; i++ )
{
row = document.createElement( "TR" );
row.setAttribute( "id", "" + myCmp.GPUs[i].GPUId );
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.GPUs[i].GPUName ));
col1 = row.insertCell( -1 );
col1.setAttribute( "class", "ta-center" );
let but = document.createElement( "button" );
but.appendChild( document.createTextNode("X") );
but.onclick = function(id, numGPUs) {
return function(){
myCmp.removeGPU(id, numGPUs );
anim();
};
}(myCmp.GPUs[i].GPUId, myCmp.GPUs[i].GPUCount > 1 ? myCmp.GPUs[i].GPUCount : 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: lookupGPUs,
serviceUrl: '/autocomplete/gpu/',
onSelect: function(suggestion){
myCmp.addGPU( 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(/^(AM|AMD)\b/i.test(params.query))
params.query = params.query.replace(/^(AM|AMD)\b/i, "AMD ");
if(/\b(Rad|Rade|Radeo|Radeon)\b/i.test(params.query))
params.query = params.query.replace(/\b(Rad|Rade|Radeo|Radeon)\b/i, "Radeon ");
if(/\b(Ryz|Ryze|Ryzen)\b/i.test(params.query))
params.query = params.query.replace(/\b(Ryz|Ryze|Ryzen)\b/i, "Ryzen ");
if(/^(NVi|NVid|NVidi|NVidia)\b/i.test(params.query))
params.query = params.query.replace(/^(NVi|NVid|NVidi|NVidia)\b/i, "NVidia ");
if(/\b(GeF|GeFo|GeFor|GeForc|GeForce)\b/i.test(params.query))
params.query = params.query.replace(/\b(GeF|GeFo|GeFor|GeForc|GeForce)\b/i, "GeForce ");
if(/\b(Qua|Quad|Quadr|Quadro)\b/i.test(params.query))
params.query = params.query.replace(/\b(Qua|Quad|Quadr|Quadro)\b/i, "Quadro ");
params.query = params.query.replace(/\s+/g, ' ');
//console.log("After: "+params.query);
},
showNoSuggestionNotice: true,
noSuggestionNotice: "
Failed to locate Videocard model. Try looking at mega list to see all names instead.",
width: 300,
minChars: 3,
lookupLimit: 10,
preventBadQueries: true,
deferRequestBy: 500,
params: {"compact": 1},
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.CompareGPUs(true);
});
function anim() {
var indexcmp = document.getElementById('indexcmp');
if(indexcmp.innerHTML < 3) {
$(".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);
}