import add from '../support/task';
import displayUpgradeMsg from './displayUpgradeMsg';
import getValue from '../system/getValue';
import {now} from '../support/dataObj';
import parseGoldUpgrades from './parseGoldUpgrades';
import retryAjax from '../ajax/retryAjax';

function checkLastUpgrade() {
  var lastUpgradeCheck = getValue('lastUpgradeCheck');
  if (lastUpgradeCheck && now < lastUpgradeCheck) {return;}
  retryAjax('index.php?no_mobile=1&cmd=points&type=1').done(function(data) {
    add(3, parseGoldUpgrades, [data]);
  });
}

function notUpgradesPage() {
  if (getValue('needToDoUpgrade')) {
    displayUpgradeMsg();
    return;
  }
  checkLastUpgrade();
}

export default function injectUpgradeAlert() { // jQuery
  if (location.search.indexOf('cmd=points&type=1') === -1) {notUpgradesPage();}
}

@@ -726,16 +726,21 @@
 y%0A  if (
+$ && 
 location
@@ -785,16 +785,21 @@
 == -1) %7B
+%0A    
 notUpgra
@@ -808,12 +808,15 @@
 sPage();
+%0A  
 %7D%0A%7D%0A

test for jQuery in injectUpgradeAlert