Untitled diff
6 removals
684 lines
7 additions
684 lines
"use strict";
"use strict";
var raidListUpdateInterval = 30000;
var raidListUpdateInterval = 30000;
var raidListUpdateBackoff = 1350;
var raidListUpdateBackoff = 1350;
var raidListUpdateCounter = 25;
var raidListUpdateCounter = 25;
var statusPanelUpdateIntervalSeconds = 30;
var statusPanelUpdateIntervalSeconds = 30;
var minimumBuffUpdateIntervalSeconds = 70;
var minimumBuffUpdateIntervalSeconds = 70;
var currentRaidListUpdateInterval = raidListUpdateInterval;
var currentRaidListUpdateInterval = raidListUpdateInterval;
var updateRaidsPanel = null, invalidateRaidList = null, doUpdateRaidsPanel = null, updateItemsPanel = null, invalidateItems = null, doUpdateItemsPanel = null;
var updateRaidsPanel = null, invalidateRaidList = null, doUpdateRaidsPanel = null, updateItemsPanel = null, invalidateItems = null, doUpdateItemsPanel = null;
var updateBuffsWhen = 0, isUpdatingBuffs = false;
var updateBuffsWhen = 0, isUpdatingBuffs = false;
var queuedRaidClick = null;
var queuedRaidClick = null;
var pendingRaidUpdate = null;
var pendingRaidUpdate = null;
var nextRaidUpdateWhen = null;
var nextRaidUpdateWhen = null;
var menuIconSize = 0;
var menuIconSize = 0;
var menuLeftEdge = 0;
var menuLeftEdge = 0;
var subpanelOffset = 0;
var subpanelOffset = 0;
var mostRecentItems = null;
var mostRecentItems = null;
var lastPlayerStatus = null;
var lastPlayerStatus = null;
var statusIntervalH, raidTimerIntervalH;
var statusIntervalH, raidTimerIntervalH;
var allBookmarks = {};
var allBookmarks = {};
function bookmarkNavigate(target, evt) {
function bookmarkNavigate(target, evt) {
var inNewWindow = false;
var inNewWindow = false;
if (evt) {
if (evt) {
inNewWindow = (evt.button === 1) ||
inNewWindow = (evt.button === 1) ||
!!evt.shiftKey;
!!evt.shiftKey;
}
}
if (inNewWindow) {
if (inNewWindow) {
// HACK: Fully resolve the URL
// HACK: Fully resolve the URL
var elt = document.createElement("a");
var elt = document.createElement("a");
elt.href = target;
elt.href = target;
chrome.runtime.sendMessage({ type: "openNewTab", url: elt.href });
chrome.runtime.sendMessage({ type: "openNewTab", url: elt.href });
}
}
else {
else {
chrome.runtime.sendMessage({ type: "setLastLocation", url: target });
chrome.runtime.sendMessage({ type: "setLastLocation", url: target });
window.location.href = target;
window.location.href = target;
}
}
}
}
;
;
function repeatLastQuest(evt, callback) {
function repeatLastQuest(evt, callback) {
chrome.runtime.sendMessage({ type: "getRecentQuest" }, function (recentQuestJson) {
chrome.runtime.sendMessage({ type: "getRecentQuest" }, function (recentQuestJson) {
if (!recentQuestJson) {
if (!recentQuestJson) {
if (callback)
if (callback)
callback(false, "No recent quest to attempt");
callback(false, "No recent quest to attempt");
else
else
return showBookmarkError("No recent quest to attempt.");
return showBookmarkError("No recent quest to attempt.");
}
}
var recentQuest;
var recentQuest;
try {
try {
recentQuest = JSON.parse(recentQuestJson);
recentQuest = JSON.parse(recentQuestJson);
}
}
catch (exc) {
catch (exc) {
if (callback)
if (callback)
callback(false, "No recent quest to attempt");
callback(false, "No recent quest to attempt");
else
else
return showBookmarkError("No recent quest to attempt.");
return showBookmarkError("No recent quest to attempt.");
}
}
var parts = splitQuestId(recentQuest.quest_id);
var parts = splitQuestId(recentQuest.quest_id);
var chapterId = parts[0];
var chapterId = parts[0];
var suffix = parts[1];
var suffix = parts[1];
var itemId = recentQuest.use_item_id;
var itemId = recentQuest.use_item_id;
if (itemId)
if (itemId)
itemId = parseInt(itemId);
itemId = parseInt(itemId);
else
else
itemId = undefined;
itemId = undefined;
var data = makeBookmarkCore(chapterId, suffix, recentQuest.quest_type, itemId, recentQuest.prefix);
var data = makeBookmarkCore(chapterId, suffix, recentQuest.quest_type, itemId, recentQuest.prefix);
checkQuestStart(data, function (ok, result, reason) {
checkQuestStart(data, function (ok, result, reason) {
if (ok) {
if (ok) {
bookmarkNavigate(data.targetUrl, evt);
bookmarkNavigate(data.targetUrl, evt);
setTimeout(function () {
setTimeout(function () {
if (callback)
if (callback)
callback(true);
callback(true);
window.location.reload();
window.location.reload();
}, 50);
}, 50);
}
}
else {
else {
if (callback)
if (callback)
callback(false, reason);
callback(false, reason);
else
else
return showBookmarkError(reason);
return showBookmarkError(reason);
}
}
});
});
});
});
}
}
;
;
function makeBookmarkCore(chapterId, questSuffix, questType, useItemId, urlPrefix) {
function makeBookmarkCore(chapterId, questSuffix, questType, useItemId, urlPrefix) {
var questId = String(chapterId) + String(questSuffix);
var questId = String(chapterId) + String(questSuffix);
if (!urlPrefix) {
if (!urlPrefix) {
urlPrefix = "/#quest";
urlPrefix = "/#quest";
}
}
var targetUrl = urlPrefix + "/supporter/" + questId + "/" + questType;
var targetUrl = urlPrefix + "/supporter/" + questId + "/" + questType;
if (useItemId)
if (useItemId)
targetUrl += "/0/" + useItemId;
targetUrl += "/0/" + useItemId;
var infoUrl = "/quest/treasure_raid/" + chapterId + "/" + questId;
var infoUrl = "/quest/treasure_raid/" + chapterId + "/" + questId;
// FIXME: The /1/ here is the raid type
// FIXME: The /1/ here is the raid type
var checkStartUrl = "/quest/check_quest_start/" + chapterId + "/1/" + questId;
var checkStartUrl = "/quest/check_quest_start/" + chapterId + "/1/" + questId;
return {
return {
chapterId: chapterId,
chapterId: chapterId,
questId: questId,
questId: questId,
targetUrl: targetUrl,
targetUrl: targetUrl,
infoUrl: infoUrl,
infoUrl: infoUrl,
checkStartUrl: checkStartUrl
checkStartUrl: checkStartUrl
};
};
}
}
;
;
function showBookmarkError(message, extra) {
function showBookmarkError(message, extra) {
showGamePopup({
showGamePopup({
title: "Bookmark",
title: "Bookmark",
body: message + (extra ? "<br>" + String(extra) : "")
body: message + (extra ? "<br>" + String(extra) : "")
});
});
}
}
;
;
function startRaid(data, evt) {
function startRaid(data, evt) {
log("Starting raid", data.targetUrl);
log("Starting raid", data.targetUrl);
bookmarkNavigate(data.targetUrl, evt);
bookmarkNavigate(data.targetUrl, evt);
}
}
;
;
function checkQuestStart_old(data, onSuccess) {
function checkQuestStart_old(data, onSuccess) {
checkQuestStart(data, function (ok, eligibility, reason) {
checkQuestStart(data, function (ok, eligibility, reason) {
if (ok)
if (ok)
onSuccess(data, eligibility);
onSuccess(data, eligibility);
else
else
showBookmarkError(reason);
showBookmarkError(reason);
});
});
}
}
function checkQuestStart(data, callback) {
function checkQuestStart(data, callback) {
log("Checking eligibility", data.checkStartUrl);
log("Checking eligibility", data.checkStartUrl);
doClientAjax(data.checkStartUrl, function (eligibility, error) {
doClientAjax(data.checkStartUrl, function (eligibility, error) {
if (!eligibility)
if (!eligibility)
return showBookmarkError("Failed to get information from server", error);
return showBookmarkError("Failed to get information from server", error);
switch (eligibility.result) {
switch (eligibility.result) {
case "ok":
case "ok":
callback(true, eligibility);
callback(true, eligibility);
return;
return;
case "error_cnt":
case "error_cnt":
callback(false, eligibility, "You have already attempted this raid the maximum number of times today.");
callback(false, eligibility, "You have already attempted this raid the maximum number of times today.");
return;
return;
case "other_quest_progress":
case "other_quest_progress":
callback(false, eligibility, "You cannot start this raid because another quest is in progress.");
callback(false, eligibility, "You cannot start this raid because another quest is in progress.");
return;
return;
case "error_level":
case "error_level":
callback(false, eligibility, "Your rank is too low to start this raid.");
callback(false, eligibility, "Your rank is too low to start this raid.");
return;
return;
default:
default:
try {
try {
var blob = JSON.parse(eligibility);
var blob = JSON.parse(eligibility);
if (blob.popup && blob.popup.body) {
if (blob.popup && blob.popup.body) {
callback(false, eligibility, blob.popup.body);
callback(false, eligibility, blob.popup.body);
return;
return;
}
}
}
}
catch (exc) {
catch (exc) {
callback(false, eligibility, "Unknown error");
callback(false, eligibility, "Unknown error");
}
}
}
}
});
});
}
}
;
;
function makeRaidBookmark(chapterId, questSuffix) {
function makeRaidBookmark(chapterId, questSuffix) {
var data = makeBookmarkCore(chapterId, questSuffix, 1);
var data = makeBookmarkCore(chapterId, questSuffix, 1);
return function (evt) {
return function (evt) {
checkQuestStart_old(data, function (data, eligibility) {
checkQuestStart_old(data, function (data, eligibility) {
startRaid(data, evt);
startRaid(data, evt);
});
});
};
};
}
}
;
;
function getRaidInfo(data, onSuccess) {
function getRaidInfo(data, onSuccess) {
log("Requesting raid info", data.infoUrl);
log("Requesting raid info", data.infoUrl);
doClientAjax(data.infoUrl, function (raidInfo, error) {
doClientAjax(data.infoUrl, function (raidInfo, error) {
if (!raidInfo)
if (!raidInfo)
return showBookmarkError("Failed to get information from server", error);
return showBookmarkError("Failed to get information from server", error);
onSuccess(data, raidInfo);
onSuccess(data, raidInfo);
});
});
}
}
;
;
function makeTreasureRaidBookmark(chapterId, questSuffix, itemId) {
function makeTreasureRaidBookmark(chapterId, questSuffix, itemId) {
var data = makeBookmarkCore(chapterId, questSuffix, 1, itemId);
var data = makeBookmarkCore(chapterId, questSuffix, 1, itemId);
return function (evt) {
return function (evt) {
getRaidInfo(data, function (data, raidInfo) {
getRaidInfo(data, function (data, raidInfo) {
var treasureIndex = raidInfo.treasure_id.indexOf(String(itemId));
var treasureIndex = raidInfo.treasure_id.indexOf(String(itemId));
if (treasureIndex < 0)
if (treasureIndex < 0)
return showBookmarkError("Item not found in raid info");
return showBookmarkError("Item not found in raid info");
var itemsNeeded = parseInt(raidInfo.consume[treasureIndex]);
var itemsNeeded = parseInt(raidInfo.consume[treasureIndex]);
var itemsHeld = raidInfo.num[treasureIndex];
var itemsHeld = raidInfo.num[treasureIndex];
if (itemsHeld < itemsNeeded)
if (itemsHeld < itemsNeeded)
return showBookmarkError(raidInfo.chapter_name + " requires " +
return showBookmarkError(raidInfo.chapter_name + " requires " +
itemsNeeded + " of " +
itemsNeeded + " of " +
raidInfo.treasure_name[treasureIndex] +
raidInfo.treasure_name[treasureIndex] +
", but you only have " + itemsHeld);
", but you only have " + itemsHeld);
checkQuestStart_old(data, function (data, eligibility) {
checkQuestStart_old(data, function (data, eligibility) {
startRaid(data, evt);
startRaid(data, evt);
});
});
});
});
};
};
/*
/*
{
{
"chapter_id":"30005",
"chapter_id":"30005",
"quest_id":"300051",
"quest_id":"300051",
"type":"1",
"type":"1",
"action_point":"50",
"action_point":"50",
"chapter_name":"Tiamat Omega Showdown",
"chapter_name":"Tiamat Omega Showdown",
"consume":["3"],
"consume":["3"],
"level":30,
"level":30,
"treasure_id":["18"],
"treasure_id":["18"],
"treasure_image_id":["18"],
"treasure_image_id":["18"],
"treasure_name":["Tiamat Omega Anima"],
"treasure_name":["Tiamat Omega Anima"],
"num":[26],
"num":[26],
"raid_name":"Lvl 50 Tiamat Omega",
"raid_name":"Lvl 50 Tiamat Omega",
"limit":90
"limit":90
}
}
*/
*/
}
}
;
;
function visitCurrentEvent(evt, tail) {
function visitCurrentEvent(evt, tail) {
chrome.runtime.sendMessage({ type: "getCurrentEvent" }, function (currentEvent) {
chrome.runtime.sendMessage({ type: "getCurrentEvent" }, function (currentEvent) {
if (!currentEvent)
if (!currentEvent)
showGamePopup({
showGamePopup({
title: "Error",
title: "Error",
body: "No event stored. Try visiting the main page."
body: "No event stored. Try visiting the main page."
});
});
else if (tail)
else if (tail)
bookmarkNavigate("/#" + currentEvent + tail, evt);
bookmarkNavigate("/#" + currentEvent + tail, evt);
else
else
bookmarkNavigate("/#" + currentEvent, evt);
bookmarkNavigate("/#" + currentEvent, evt);
});
});
}
}
;
;
function makeGuildWarBookmark(tail) {
function makeGuildWarBookmark(tail) {
return function (evt) {
return function (evt) {
bookmarkNavigate("/#event/" + guildWarName + (tail || ""), evt);
bookmarkNavigate("/#event/" + guildWarName + (tail || ""), evt);
};
};
}
}
;
;
function makeGuildWarRaidBookmark(chapterId, questSuffix, checkItem) {
function makeGuildWarRaidBookmark(chapterId, questSuffix, checkItem) {
var data = makeBookmarkCore(chapterId, questSuffix, 1);
var data = makeBookmarkCore(chapterId, questSuffix, 1);
var checkItemFn, checkStartFn, visitSupporterPageFn, checkMultiStart;
var checkItemFn, checkStartFn, visitSupporterPageFn, checkMultiStart;
checkItemFn = function (evt, onComplete) {
checkItemFn = function (evt, onComplete) {
if (window.location.href.indexOf("event/" + guildWarName) < 0) {
if (window.location.href.indexOf("event/" + guildWarName) < 0) {
if (onComplete)
if (onComplete)
onComplete(false);
onComplete(false);
return bookmarkNavigate("#event/" + guildWarName, evt);
return bookmarkNavigate("#event/" + guildWarName, evt);
}
}
data.targetUrl = data.targetUrl.replace("#quest/", "#event/" + guildWarName + "/") + "/0";
data.targetUrl = data.targetUrl.replace("#quest/", "#event/" + guildWarName + "/") + "/0";
var checkUrl = "/" + guildWarName + "/rest/top/check_item/" + data.questId;
var checkUrl = "/" + guildWarName + "/rest/top/check_item/" + data.questId;
doClientAjax(checkUrl, function (checkResult) {
doClientAjax(checkUrl, function (checkResult) {
if (checkResult && checkResult.result)
if (checkResult && checkResult.result)
return checkStartFn(evt, onComplete);
return checkStartFn(evt, onComplete);
else {
else {
if (onComplete)
if (onComplete)
onComplete(false);
onComplete(false);
return showBookmarkError("You do not have the necessary items to start this quest.");
return showBookmarkError("You do not have the necessary items to start this quest.");
}
}
});
});
};
};
checkStartFn = function (evt, onComplete) {
checkStartFn = function (evt, onComplete) {
checkQuestStart_old(data, function (data, eligibility) {
checkQuestStart_old(data, function (data, eligibility) {
if (eligibility.result === "ok")
if (eligibility.result === "ok")
checkMultiStart(evt, onComplete);
checkMultiStart(evt, onComplete);
else {
else {
if (onComplete)
if (onComplete)
onComplete(false);
onComplete(false);
return showBookmarkError("You are not eligible to start this quest. " + eligibility.result);
return showBookmarkError("You are not eligible to start this quest. " + eligibility.result);
}
}
});
});
};
};
checkMultiStart = function (evt, onComplete) {
checkMultiStart = function (evt, onComplete) {
var checkUrl = "/quest/check_multi_start";
var checkUrl = "/quest/check_multi_start";
doClientAjax(checkUrl, JSON.stringify({ quest_id: parseInt(data.questId) }), function (checkResult) {
doClientAjax(checkUrl, JSON.stringify({ quest_id: parseInt(data.questId) }), function (checkResult) {
if (checkResult && checkResult.result === "ok")
if (checkResult && checkResult.result === "ok")
return visitSupporterPageFn(evt, onComplete);
return visitSupporterPageFn(evt, onComplete);
else {
else {
if (onComplete)
if (onComplete)
onComplete(false);
onComplete(false);
return showBookmarkError("You cannot start a raid.");
return showBookmarkError("You cannot start a raid.");
}
}
});
});
};
};
visitSupporterPageFn = function (evt, onComplete) {
visitSupporterPageFn = function (evt, onComplete) {
if (window.location.href.indexOf("event/" + guildWarName) < 0) {
if (window.location.href.indexOf("event/" + guildWarName) < 0) {
if (onComplete)
if (onComplete)
onComplete(false);
onComplete(false);
return bookmarkNavigate("#event/" + guildWarName, evt);
return bookmarkNavigate("#event/" + guildWarName, evt);
}
}
else {
else {
if (onComplete)
if (onComplete)
onComplete(true);
onComplete(true);
startRaid(data, evt);
startRaid(data, evt);
}
}
};
};
if (!checkItem)
if (!checkItem)
return visitSupporterPageFn;
return visitSupporterPageFn;
return checkItemFn;
return checkItemFn;
}
}
;
;
function makeEventTreasureRaidBookmark(chapterId, questSuffix) {
function makeEventTreasureRaidBookmark(chapterId, questSuffix) {
return function (evt) {
return function (evt) {
chrome.runtime.sendMessage({ type: "getCurrentEvent" }, function (currentEvent) {
chrome.runtime.sendMessage({ type: "getCurrentEvent" }, function (currentEvent) {
if (!currentEvent)
if (!currentEvent)
showGamePopup({
showGamePopup({
title: "Error",
title: "Error",
body: "No event stored. Try visiting the main page."
body: "No event stored. Try visiting the main page."
});
});
var data = makeBookmarkCore(chapterId, questSuffix, 1);
var data = makeBookmarkCore(chapterId, questSuffix, 1);
data.targetUrl = data.targetUrl.replace("#quest/", "#" + currentEvent + "/");
data.targetUrl = data.targetUrl.replace("#quest/", "#" + currentEvent + "/");
checkQuestStart_old(data, function (data, eligibility) {
checkQuestStart_old(data, function (data, eligibility) {
startRaid(data, evt);
startRaid(data, evt);
});
});
});
});
};
};
}
}
;
;
var guildWarName = null;
var guildWarName = null;
var guildWarSubmenu = {
var guildWarSubmenu = {
"guild-war-home": makeGuildWarBookmark(),
"guild-war-home": makeGuildWarBookmark(),
"guild-war-gacha": makeGuildWarBookmark("/gacha/index"),
"guild-war-gacha": makeGuildWarBookmark("/gacha/index"),
"guild-war-reward": makeGuildWarBookmark("/reward"),
"guild-war-reward": makeGuildWarBookmark("/reward"),
//"guild-war-eye-vh": makeGuildWarRaidBookmark(71863, 1, false),
//"guild-war-eye-vh": makeGuildWarRaidBookmark(71863, 1, false),
"guild-war-dog-vh": makeGuildWarRaidBookmark(72314, 1, false),
"guild-war-dog-vh": makeGuildWarRaidBookmark(72214, 1, false),
"guild-war-dog-ex": makeGuildWarRaidBookmark(72315, 1, false),
"guild-war-dog-ex": makeGuildWarRaidBookmark(72215, 1, false),
"guild-war-dog-ex-plus": makeGuildWarRaidBookmark(72316, 1, false),
"guild-war-dog-ex-plus": makeGuildWarRaidBookmark(72216, 1, false),
"guild-war-hell-90": makeGuildWarRaidBookmark(72317, 1, true),
"guild-war-hell-90": makeGuildWarRaidBookmark(72217, 1, true),
"guild-war-hell-95": makeGuildWarRaidBookmark(72318, 1, true),
"guild-war-hell-95": makeGuildWarRaidBookmark(72218, 1, true),
};
};
var menuItems = {
var menuItems = {
"home": "/#mypage",
"home": "/#mypage",
"party": "/#party/index/0/npc/0",
"party": "/#party/index/0/npc/0",
"mystuff": {
"mystuff": {
"inventory": "/#list",
"inventory": "/#list",
"stash": "/#container",
"stash": "/#container",
"crate": "/#present",
"crate": "/#present",
"supplies": "/#item",
"supplies": "/#item",
},
},
"quest": {
"quest": {
"quest-all": "/#quest/index",
"quest-all": "/#quest/index",
"quest-special": "/#quest/extra",
"quest-special": "/#quest/extra",
"join-raid": "/#quest/assist",
"join-raid": "/#quest/assist",
"event": visitCurrentEvent,
"event": visitCurrentEvent,
"trial-battles": "/#trial_battle",
"trial-battles": "/#trial_battle",
"pending-raids": "/#quest/assist/unclaimed",
"pending-raids": "/#quest/assist/unclaimed",
},
},
"quest-repeat": repeatLastQuest,
"quest-repeat": repeatLastQuest,
"guild-war": guildWarSubmenu,
// "guild-war": guildWarSubmenu,
"hard-raids": {
"hard-raids": {
"hard-tia": makeRaidBookmark(30004, 1),
"hard-tia": makeRaidBookmark(30004, 1),
"hard-colo": makeRaidBookmark(30009, 1),
"hard-colo": makeRaidBookmark(30009, 1),
"hard-levi": makeRaidBookmark(30015, 1),
"hard-levi": makeRaidBookmark(30015, 1),
"hard-yugu": makeRaidBookmark(30019, 1),
"hard-yugu": makeRaidBookmark(30019, 1),
"hard-chev": makeRaidBookmark(30022, 1),
"hard-chev": makeRaidBookmark(30022, 1),
"hard-cel": makeRaidBookmark(30025, 1)
"hard-cel": makeRaidBookmark(30025, 1)
},
},
"magna-raids": {
"magna-raids": {
"magna-tia": makeTreasureRaidBookmark(30005, 1, 18),
"magna-tia": makeTreasureRaidBookmark(30005, 1, 18),
"magna-colo": makeTreasureRaidBookmark(30010, 1, 19),
"magna-colo": makeTreasureRaidBookmark(30010, 1, 19),
"magna-levi": makeTreasureRaidBookmark(30016, 1, 20),
"magna-levi": makeTreasureRaidBookmark(30016, 1, 20),
"magna-yugu": makeTreasureRaidBookmark(30026, 1, 21),
"magna-yugu": makeTreasureRaidBookmark(30026, 1, 21),
"magna-chev": makeTreasureRaidBookmark(30027, 1, 26),
"magna-chev": makeTreasureRaidBookmark(30027, 1, 26),
"magna-cel": makeTreasureRaidBookmark(30028, 1, 31)
"magna-cel": makeTreasureRaidBookmark(30028, 1, 31)
},
},
"hl-raids": {
"hl-raids": {
"hl-tia": makeTreasureRaidBookmark(30044, 1, 32),
"hl-tia": makeTreasureRaidBookmark(30044, 1, 32),
"hl-colo": makeTreasureRaidBookmark(30049, 1, 47),
"hl-colo": makeTreasureRaidBookmark(30049, 1, 47),
"hl-levi": makeTreasureRaidBookmark(30051, 1, 48),
"hl-levi": makeTreasureRaidBookmark(30051, 1, 48),
"hl-yugu": makeTreasureRaidBookmark(30053, 1, 49),
"hl-yugu": makeTreasureRaidBookmark(30053, 1, 49),
"hl-chev": makeTreasureRaidBookmark(30056, 1, 50),
"hl-chev": makeTreasureRaidBookmark(30056, 1, 50),
"hl-cel": makeTreasureRaidBookmark(30058, 1, 51),
"hl-cel": makeTreasureRaidBookmark(30058, 1, 51),
"hl-rosequeen": makeTreasureRaidBookmark(30047, 1, 1204),
"hl-rosequeen": makeTreasureRaidBookmark(30047, 1, 1204),
},
},
"primal-raids": {
"primal-raids": {
"nataku": makeTreasureRaidBookmark(30042, 1, 1343),
"nataku": makeTreasureRaidBookmark(30042, 1, 1343),
"flame-glass": makeTreasureRaidBookmark(30041, 1, 1313),
"flame-glass": makeTreasureRaidBookmark(30041, 1, 1313),
"macula-marius": makeTreasureRaidBookmark(30038, 1, 1323),
"macula-marius": makeTreasureRaidBookmark(30038, 1, 1323),
"athena": makeTreasureRaidBookmark(30107, 1, 1313),
"athena": makeTreasureRaidBookmark(30107, 1, 1313),
"medusa": makeTreasureRaidBookmark(30039, 1, 1333),
"medusa": makeTreasureRaidBookmark(30039, 1, 1333),
"apollo": makeTreasureRaidBookmark(30043, 1, 1353),
"apollo": makeTreasureRaidBookmark(30043, 1, 1353),
"olivia": makeTreasureRaidBookmark(30040, 1, 1363),
"olivia": makeTreasureRaidBookmark(30040, 1, 1363),
"odin": makeTreasureRaidBookmark(30046, 1, 1353),
"odin": makeTreasureRaidBookmark(30046, 1, 1353),
},
},
"coop": {
"coop": {
"coop": "/#coopraid",
"coop": "/#coopraid",
// This makes it impossible to return to an existing room
// This makes it impossible to return to an existing room
// "coop-host": "/#coopraid/room/entry",
// "coop-host": "/#coopraid/room/entry",
"coop-join": "/#coopraid/offer",
"coop-join": "/#coopraid/offer",
"coop-shop": "/#coopraid/lineup"
"coop-shop": "/#coopraid/lineup"
},
},
"me": {
"me": {
"profile": "/#profile",
"profile": "/#profile",
"crew": "/#guild",
"crew": "/#guild",
"friends": "/#friend",
"friends": "/#friend",
"trophies": "/#title"
"trophies": "/#title"
},
},
"shop": {
"shop": {
"shop-mobacoins": "#shop/moba/0",
"shop-mobacoins": "#shop/moba/0",
"shop-crystals": "#shop/lupi/0",
"shop-crystals": "#shop/lupi/0",
"shop-points": "/#shop/exchange/points",
"shop-points": "/#shop/exchange/points",
"shop-trajectory": "#shop/exchange/trajectory",
"shop-trajectory": "#shop/exchange/trajectory",
"shop-moon": "#shop/exchange/moon",
"shop-moon": "#shop/exchange/moon",
"shop-treasure": "#shop/exchange/list",
"shop-treasure": "#shop/exchange/list",
"shop-whale-tears": "#shop/exchange/ceiling",
"shop-whale-tears": "#shop/exchange/ceiling",
"shop-weapon-series": "#archaic",
"shop-weapon-series": "#archaic",
},
},
"casino": {
"casino": {
"poker": "/#casino/list/poker",
"poker": "/#casino/list/poker",
"bingo": "/#casino/list/bingo",
"bingo": "/#casino/list/bingo",
"casino-shop": "/#casino/exchange"
"casino-shop": "/#casino/exchange"
},
},
};
};
var viramateMenuItems = {
var viramateMenuItems = {
"settings": function () {
"settings": function () {
var loc = chrome.extension.getURL("src/options_custom/index.html");
var loc = chrome.extension.getURL("src/options_custom/index.html");
var w = window.open(loc);
var w = window.open(loc);
},
},
"update-notes": function () {
"update-notes": function () {
var loc = chrome.extension.getURL("content/changelog.html");
var loc = chrome.extension.getURL("content/changelog.html");
var w = window.open(loc);
var w = window.open(loc);
}
}
};
};
function isHorizontalLayout() {
function isHorizontalLayout() {
return (isMobileSite() ||
return (isMobileSite() ||
!!currentSettings.horizontalBookmarks ||
!!currentSettings.horizontalBookmarks ||
!!document.getElementById("gree-game-container"));
!!document.getElementById("gree-game-container"));
}
}
;
;
function makeMenuHandler(name, value, tryCloseMenu) {
function makeMenuHandler(name, value, tryCloseMenu) {
var result;
var result;
if (typeof (value) === "string")
if (typeof (value) === "string")
result = function (evt) {
result = function (evt) {
if (evt) {
if (evt) {
evt.preventDefault();
evt.preventDefault();
evt.stopPropagation();
evt.stopPropagation();
}
}
tryCloseMenu();
tryCloseMenu();
bookmarkNavigate(value, evt);
bookmarkNavigate(value, evt);
};
};
else if (value && value.call && value.apply)
else if (value && value.call && value.apply)
result = function (evt) {
result = function (evt) {
if (evt) {
if (evt) {
evt.preventDefault();
evt.preventDefault();
evt.stopPropagation();
evt.stopPropagation();
}
}
tryCloseMenu();
tryCloseMenu();
value(evt);
value(evt);
};
};
else
else
return null;
return null;
allBookmarks[name] = result;
allBookmarks[name] = result;
return result;
return result;
}
}
;
;
function _updateIconSize(menuIcon) {
function _updateIconSize(menuIcon) {
if (isHorizontalLayout())
if (isHorizontalLayout())
menuIcon.style.left = menuLeftEdge.toFixed(0) + "px";
menuIcon.style.left = menuLeftEdge.toFixed(0) + "px";
else
else
menuIcon.style.left = "-6px";
menuIcon.style.left = "-6px";
var iconRect = menuIcon.getBoundingClientRect();
var iconRect = menuIcon.getBoundingClientRect();
if (isHorizontalLayout())
if (isHorizontalLayout())
menuIconSize = iconRect.width * getEffectiveZoom(menuIcon) * getEffectiveZoom(document.documentElement);
menuIconSize = iconRect.width * getEffectiveZoom(menuIcon) * getEffectiveZoom(document.documentElement);
else
else
menuIconSize = iconRect.height * getEffectiveZoom(menuIcon);
menuIconSize = iconRect.height * getEffectiveZoom(menuIcon);
}
}
;
;
function getColorForMenuItem(key) {
function getColorForMenuItem(key) {
switch (key) {
switch (key) {
case "hard-raids":
case "hard-raids":
return "#efc0ba";
return "#efc0ba";
case "magna-raids":
case "magna-raids":
return "#e8e8f1";
return "#e8e8f1";
case "hl-raids":
case "hl-raids":
return "#efe0ba";
return "#efe0ba";
}
}
var dashPos = key.lastIndexOf("-");
var dashPos = key.lastIndexOf("-");
var suffix = key.substr(dashPos + 1);
var suffix = key.substr(dashPos + 1);
switch (suffix) {
switch (suffix) {
case "tia":
case "tia":
return "#bfefbf";
return "#bfefbf";
case "yugu":
case "yugu":
return "#efdfa0";
return "#efdfa0";
case "colo":
case "colo":
return "#efbfbf";
return "#efbfbf";
case "levi":
case "levi":
return "#bfcfef";
return "#bfcfef";
case "cel":
case "cel":
return "#d890df";
return "#d890df";
}
}
return null;
return null;
}
}
;
;
function showViraButton() {
function showViraButton() {
if (isShutdown)
if (isShutdown)
return;
return;
injectStylesheet("sidebar-shadow.css", getUiContainer());
injectStylesheet("sidebar-shadow.css", getUiContainer());
var outImg = getResourceUrl('vira-small-smile.png');
var outImg = getResourceUrl('vira-small-smile.png');
var overImg = getResourceUrl('vira-small.png');
var overImg = getResourceUrl('vira-small.png');
var isCustomIcon = false;
var isCustomIcon = false;
try {
try {
if (currentSettings.bookmarksInactiveIcon)
if (currentSettings.bookmarksInactiveIcon)
outImg = encoding.Base64.stringToImageURL(currentSettings.bookmarksInactiveIcon);
outImg = encoding.Base64.stringToImageURL(currentSettings.bookmarksInactiveIcon);
if (currentSettings.bookmarksActiveIcon)
if (currentSettings.bookmarksActiveIcon)
overImg = encoding.Base64.stringToImageURL(currentSettings.bookmarksActiveIcon);
overImg = encoding.Base64.stringToImageURL(currentSettings.bookmarksActiveIcon);
isCustomIcon = (currentSettings.bookmarksActiveIcon || currentSettings.bookmarksInactiveIcon);
isCustomIcon = (currentSettings.bookmarksActiveIcon || currentSettings.bookmarksInactiveIcon);
}
}
catch (exc) {
catch (exc) {
log("Error decoding custom bookmarks icons", exc);
log("Error decoding custom bookmarks icons", exc);
}
}
var menuIcon = document.createElement("div");
var menuIcon = document.createElement("div");
var mainMenu = document.createElement("div");
var mainMenu = document.createElement("div");
menuIcon.className = "viramate-menu-icon";
menuIcon.className = "viramate-menu-icon";
// HACK: Why is this necessary?
// HACK: Why is this necessary?
menuIcon.style.backgroundRepeat = "no-repeat";
menuIcon.style.backgroundRepeat = "no-repeat";
menuIcon.style.backgroundImage = "url(" + outImg + ")";
menuIcon.style.backgroundImage = "url(" + outImg + ")";
menuIcon.setAttribute("title", "Viramate");
menuIcon.setAttribute("title", "Viramate");
var maxIconWidth = isCustomIcon ? 64 : 56;
var maxIconWidth = isCustomIcon ? 64 : 56;
// HACK: :after selectors don't work on img. html sucks.
// HACK: :after selectors don't work on img. html sucks.
var tempImage = document.createElement("img");
var tempImage = document.createElement("img");
tempImage.style.opacity = "0.0";
tempImage.style.opacity = "0.0";
tempImage.onload = function () {
tempImage.onload = function () {
var scale = 1.0;
var scale = 1.0;
if (tempImage.naturalWidth > maxIconWidth)
if (tempImage.naturalWidth > maxIconWidth)
scale = maxIconWidth / tempImage.naturalWidth;
scale = maxIconWidth / tempImage.naturalWidth;
menuIcon.style.width = (tempImage.naturalWidth * scale).toFixed(0) + "px";
menuIcon.style.width = (tempImage.naturalWidth * scale).toFixed(0) + "px";
menuIcon.style.height = (tempImage.naturalHeight * scale).toFixed(0) + "px";
menuIcon.style.height = (tempImage.naturalHeight * scale).toFixed(0) + "px";
uninjectElement(getUiContainer(), tempImage);
uninjectElement(getUiContainer(), tempImage);
_updateIconSize(menuIcon);
_updateIconSize(menuIcon);
_layoutPanels();
_layoutPanels();
};
};
tempImage.src = outImg;
tempImage.src = outImg;
injectElement(getUiContainer(), tempImage);
injectElement(getUiContainer(), tempImage);
var paddingSize = 100;
var paddingSize = 100;
if (typeof (currentSettings.bookmarksIconPadding) === "number")
if (typeof (currentSettings.bookmarksIconPadding) === "number")
paddingSize = currentSettings.bookmarksIconPadding;
paddingSize = currentSettings.bookmarksIconPadding;
if (isHorizontalLayout()) {
if (isHorizontalLayout()) {
menuIcon.style.paddingRight = Math.max(paddingSize - 12, 0).toFixed(0) + "px";
menuIcon.style.paddingRight = Math.max(paddingSize - 12, 0).toFixed(0) + "px";
}
}
else {
else {
menuIcon.style.paddingBottom = Math.max(paddingSize - 12, 0).toFixed(0) + "px";
menuIcon.style.paddingBottom = Math.max(paddingSize - 12, 0).toFixed(0) + "px";
}
}
mainMenu.className = "viramate-menu";
mainMenu.className = "viramate-menu";
if (typeof (currentSettings.bookmarksSize) === "number")
if (typeof (currentSettings.bookmarksSize) === "number")
menuIcon.style.transform = "scale(" + currentSettings.bookmarksSize.toFixed(1) + ")";
menuIcon.style.transform = "scale(" + currentSettings.bookmarksSize.toFixed(1) + ")";
if (typeof (currentSettings.bookmarksMenuSize) === "number")
if (typeof (currentSettings.bookmarksMenuSize) === "number")
mainMenu.style.transform = "scale(" + currentSettings.bookmarksMenuSize.toFixed(1) + ")";
mainMenu.style.transform = "scale(" + currentSettings.bookmarksMenuSize.toFixed(1) + ")";
// mainMenu.style.zoom = menuIcon.style.zoom = (1 / getEffectiveZoom(document.documentElement)).toFixed(2);
// mainMenu.style.zoom = menuIcon.style.zoom = (1 / getEffectiveZoom(document.documentElement)).toFixed(2);
var mouseIsOverIcon = false;
var mouseIsOverIcon = false;
var mouseIsOverMenu = 0;
var mouseIsOverMenu = 0;
var mouseIsOverSubmenu = 0;
var mouseIsOverSubmenu = 0;
var menuIsVisible = false;
var menuIsVisible = false;
var allMenus = [mainMenu];
var allMenus = [mainMenu];
var updateTimeout = 0;
var updateTimeout = 0;
var autoOpenDelay = isHorizontalLayout() ? 260 : 160;
var autoOpenDelay = isHorizontalLayout() ? 260 : 160;
var autoCloseDelay = currentSettings.openBookmarksOnClick ? 500 : 250;
var autoCloseDelay = currentSettings.openBookmarksOnClick ? 500 : 250;
var pamrklamr = function () {
var pamrklamr = function () {
return 5 * 1000 + (Math.random() * 1600 * 1000);
return 5 * 1000 + (Math.random() * 1600 * 1000);
};
};
var fmajrlialmsk;
var fmajrlialmsk;
fmajrlialmsk = function () {
fmajrlialmsk = function () {
if (isShutdown)
if (isShutdown)
return;
return;
if (isCustomIcon)
if (isCustomIcon)
return;
return;
if (!menuIsVisible) {
if (!menuIsVisible) {
menuIcon.style.backgroundImage = "url(" + getResourceUrl('hfgk/askpmr/vxgkql.png') + ")";
menuIcon.style.backgroundImage = "url(" + getResourceUrl('hfgk/askpmr/vxgkql.png') + ")";
window.setTimeout(function () {
window.setTimeout(function () {
menuIcon.style.backgroundImage = "url(" + getResourceUrl('hfgk/qw3mkl/vqprlm.png') + ")";
menuIcon.style.backgroundImage = "url(" + getResourceUrl('hfgk/qw3mkl/vqprlm.png') + ")";
}, 60);
}, 60);
window.setTimeout(function () {
window.setTimeout(function () {
menuIcon.style.backgroundImage = "url(" + getResourceUrl('hfgk/askpmr/vxgkql.png') + ")";
menuIcon.style.backgroundImage = "url(" + getResourceUrl('hfgk/askpmr/vxgkql.png') + ")";
}, 950);
}, 950);
window.setTimeout(function () {
window.setTimeout(function () {
menuIcon.style.backgroundImage = "url(" + outImg + ")";
menuIcon.style.backgroundImage = "url(" + outImg + ")";
}, 1060);
}, 1060);
}
}
window.setTimeout(fmajrlialmsk, pamrklamr());
window.setTimeout(fmajrlialmsk, pamrklamr());
};
};
window.setTimeout(fmajrlialmsk, pamrklamr());
window.setTimeout(fmajrlialmsk, pamrklamr());
var showMenu = function (menu) {
var showMenu = function (menu) {
if (menu.className.indexOf("viramate-menu") === 0)
if (menu.className.indexOf("viramate-menu") === 0)
menu.style.left = menuLeftEdge.toFixed(0) + "px";
menu.style.left = menuLeftEdge.toFixed(0) + "px";
else
else
menu.style.left = "0px";
menu.style.left = "0px";
menu.style.opacity = "1.0";
menu.style.opacity = "1.0";
menu.style.pointerEvents = "all";
menu.style.pointerEvents = "all";
menuIsVisible = true;
menuIsVisible = true;
};
};
var showMenus = function () {
var showMenus = function () {
menuIcon.style.backgroundImage = "url(" + overImg + ")";
menuIcon.style.backgroundImage = "url(" + overImg + ")";
if (menuIcon.className.indexOf("open") < 0)
if (menuIcon.className.indexOf("open") < 0)
menuIcon.className += " open";
menuIcon.className += " open";
for (var i = 0; i < allMenus.length; i++) {
for (var i = 0; i < allMenus.length; i++) {
var elt = allMenus[i];
var elt = allMenus[i];
showMenu(elt);
showMenu(elt);
}
}
};
};
var hideMenu = function (menu) {
var hideMenu = function (menu) {
if (!isMobileSite()) {
if (!isMobileSite()) {
if (menu.className.indexOf("viramate-menu") === 0)
if (menu.className.indexOf("viramate-menu") === 0)
menu.style.left = (menuLeftEdge - 32).toFixed(0) + "px";
menu.style.left = (menuLeftEdge - 32).toFixed(0) + "px";
else
else
menu.style.left = "-32px";
menu.style.left = "-32px";
}
}
menu.style.opacity = "0.0";
menu.style.opacity = "0.0";
menu.style.pointerEvents = "none";
menu.style.pointerEvents = "none";
menuIsVisible = false;
menuIsVisible = false;
};
};
var hideMenus = function () {
var hideMenus = function () {
menuIcon.style.backgroundImage = "url(" + outImg + ")";
menuIcon.style.backgroundImage = "url(" + outImg + ")";
menuIcon.className = menuIcon.className.replace(" open", "");
menuIcon.className = menuIcon.className.replace(" open", "");
closeSubmenus();
closeSubmenus();
hideMenu(allMenus[0]);
hideMenu(allMenus[0]);
};
};
var closeSubmenus = function () {
var closeSubmenus = function () {
// Hide any other open submenus
// Hide any other open submenus
for (var i = 1; i < allMenus.length; i++) {
for (var i = 1; i < allMenus.length; i++) {
var submenu = allMenus[i];
var submenu = allMenus[i];
if (submenu.owner)
if (submenu.owner)
submenu.owner.className = submenu.owner.className.replace(" open", "");
submenu.owner.className = submenu.owner.className.replace(" open", "");
hideMenu(submenu);
hideMenu(submenu);
}
}
// Pop them off the list
// Pop them off the list
allMenus.length = 1;
allMenus.length = 1;
};
};
var openSubmenu = function (owner, submenu) {
var openSubmenu = function (owner, submenu) {
owner.className += " open";
owner.className += " open";
submenu.owner = owner;
submenu.owner = owner;
closeSubmenus();
closeSubmenus();
allMenus.push(submenu);
allMenus.push(submenu);
showMenus();
showMenus();
};
};
var updateMenu = function () {
var updateMenu = function () {
if (isShutdown)
if (isShutdown)
return;
return;
if (mouseIsOverIcon || (mouseIsOverMenu > 0)) {
if (mouseIsOverIcon || (mouseIsOverMenu > 0)) {
if (mouseIsOverSubmenu <= 0)
if (mouseIsOverSubmenu <= 0)
closeSubmenus();
closeSubmenus();
showMenus();
showMenus();
}
}
else
else
hideMenus();
hideMenus();
};
};
var scheduleUpdate = function (fast) {
var scheduleUpdate = function (fast) {
if (updateTimeout)
if (updateTimeout)
window.clearTimeout(updateTimeout);
window.clearTimeout(updateTimeout);
updateTimeout = window.setTimeout(updateMenu, fast ? autoOpenDelay : autoCloseDelay);
updateTimeout = window.setTimeout(updateMenu, fast ? autoOpenDelay : autoCloseDelay);
};
};
var makeSubmenuOverHandler = function (item, submenu) {
var makeSubmenuOverHandler = function (item, submenu) {
return function (evt) {
return function (evt) {
mouseIsOverSubmenu += 1;
mouseIsOverSubmenu += 1;
openSubmenu(item, submenu);
openSubmenu(item, submenu);
};
};
};
};
var makeSubmenuOutHandler = function (item, submenu) {
var makeSubmenuOutHandler = function (item, submenu) {
return function (evt) {
return function (evt) {
mouseIsOverSubmenu -= 1;
mouseIsOverSubmenu -= 1;
// TODO: Anything?
// TODO: Anything?
scheduleUpdate();
scheduleUpdate();
};
};
};
};
var tryCloseMenu = function () {
var tryCloseMenu = function () {
hideMenus();
hideMenus();
window.clearTimeout(updateTimeout);
window.clearTimeout(updateTimeout);
};
};
menuIcon.addEventListener("click", function () {
menuIcon.addEventListener("click", function () {
showMenus();
showMenus();
}, false);
}, false);
menuIcon.addEventListener("mouseover", function () {
menuIcon.addEventListener("mouseover", function () {
mouseIsOverIcon = true;
mouseIsOverIcon = true;
if (!isMobileSite() &&
if (!isMobileSite() &&
(currentSettings.openBookmarksOnClick !== true))
(currentSettings.openBookmarksOnClick !== true))
scheduleUpdate(true);
scheduleUpdate(true);
}, false);
}, false);
menuIcon.addEventListener("mouseout", function () {
menuIcon.addEventListener("mouseout", function () {
mouseIsOverIcon = false;
mouseIsOverIcon = false;
scheduleUpdate();
scheduleUpdate();
}, false);
}, false);
mainMenu.addEventListener("mouseover", function () {
mainMenu.addEventListener("mouseover", function () {
mouseIsOverMenu += 1;
mouseIsOverMenu += 1;
}, false);
}, false);
mainMenu.addEventListener("mouseout", function () {
mainMenu.addEventListener("mouseout", function () {
mouseIsOverMenu -= 1;
mouseIsOverMenu -= 1;
scheduleUpdate();
scheduleUpdate();
}, false);
}, false);
var isGuildWar = currentSettings.currentGuildWar &&
var isGuildWar = currentSettings.currentGuildWar &&
(currentSettings.currentGuildWar.indexOf("event/teamraid") === 0);
(currentSettings.currentGuildWar.indexOf("event/teamraid") === 0);
if (isGuildWar)
if (isGuildWar)
guildWarName = currentSettings.currentGuildWar.replace("event/", "");
guildWarName = currentSettings.currentGuildWar.replace("event/", "");
allBookmarks = {};
allBookmarks = {};
var
v