Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
291 changes: 15 additions & 276 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
tabs = require("tabs"),
{unload} = require("unload+"),
urlFactory = require("url"),
winUtils = require("window-utils"),
_ = require("l10n").get;
{WindowTracker} = require("window-utils"),
{isBrowser} = require("api-utils/window/utils"),
_ = require("l10n").get,
{cheevos, PTS_PER_BASIC, PTS_PER_BRONZE, PTS_PER_SILVER, PTS_PER_GOLD} = require("./manager");

const brandShortName = BrandStringBundle.get("brandShortName");
const aboutCheevosUrl = "about:cheevos";
Expand All @@ -24,10 +26,6 @@
const debug = false;
log("cheevos loaded");

const PTS_PER_BASIC = 5,
PTS_PER_BRONZE = 5,
PTS_PER_SILVER = 10,
PTS_PER_GOLD = 25;
let totalAwards = 0,
acquiredAwards = 0,
acquiredPoints = 0,
Expand All @@ -49,270 +47,6 @@
"*.slashdot.org",
"*.stumbleupon.com"];

let cheevos = {
lwThemeChanged: {
id: "lightweight-theme-changed",
obs: "lightweight-theme-changed",
description: _("lwThemeChanged.description", brandShortName),
hint: _("lwThemeChanged.hint"),
learnMoreUrl: "http://www.getpersonas.com",
learnMoreLabel: _("lwThemeChanged.learnMoreLabel", brandShortName),
name: _("lwThemeChanged.name"),
subAwards: true,
bronzeId: "lightweight-theme-changed", /* migrated from generic award */
silverId: "lightweight-theme-changedSilver",
goldId: "lightweight-theme-changedGold"
},
dmRemoveDownload: {
id: "download-manager-remove-download",
obs: "download-manager-remove-download",
description: _("dmRemoveDownload.description"),
hint: _("dmRemoveDownload.hint"),
learnMoreUrl: "http://support.mozilla.com/kb/Downloads window",
learnMoreLabel: _("dmRemoveDownload.learnMoreLabel"),
name: _("dmRemoveDownload.name"),
subAwards: true,
bronzeId: "dmRemoveDownloadBronze",
silverId: "dmRemoveDownloadSilver",
goldId: "dmRemoveDownloadGold"
},
privateBrowsingEnter: {
id: "private-browsing",
obs: "private-browsing",
description: _("privateBrowsingEnter.description", brandShortName),
hint: _("privateBrowsingEnter.hint"),
learnMoreUrl: "http://support.mozilla.com/kb/Private Browsing",
learnMoreLabel: _("privateBrowsingEnter.learnMoreLabel"),
name: _("privateBrowsingEnter.name"),
subAwards: true,
bronzeId: "private-browsing", /* migrated from generic award */
silverId: "private-browsingSilver",
goldId: "private-browsingGold",
},
pmLoginAdded: {
id: "passwordmgr-storage-changed",
obs: "passwordmgr-storage-changed",
description: _("pmLoginAdded.description"),
hint: _("pmLoginAdded.hint"),
learnMoreUrl: "http://support.mozilla.com/kb/make-firefox-remember-usernames-and-passwords",
learnMoreLabel: _("pmLoginAdded.learnMoreLabel"),
name: _("pmLoginAdded.name"),
subAwards: true,
bronzeId: "passwordmgr-storage-changed", /* migrated from generic award */
silverId: "passwordmgr-storage-changedSilver",
goldId: "passwordmgr-storage-changedGold",
},
homepageChanged: {
id: "homepageChanged",
obs: "browser.startup.homepage",
description: _("homepageChanged.description", brandShortName),
hint: _("homepageChanged.hint"),
learnMoreUrl: "http://support.mozilla.com/kb/How to set the home page",
learnMoreLabel: _("homepageChanged.learnMoreLabel"),
name: _("homepageChanged.name"),
award: "bronze",
},
addOnsOpened: {
id: "Tools:Addons",
obs: "Tools:Addons",
description: _("addOnsOpened.description", brandShortName),
hint: _("addOnsOpened.hint"),
learnMoreUrl: "https://addons.mozilla.org",
learnMoreLabel: _("addOnsOpened.learnMoreLabel"),
name: _("addOnsOpened.name"),
url: "about:addons",
subAwards: true,
bronzeId: "addOnsBronze",
silverId: "addOnsSilver",
goldId: "addOnsGold",
},
aboutMisc: {
id: "aboutMisc",
obs: "aboutMisc",
description: _("aboutMisc.description"),
hint: _("aboutMisc.hint"),
learnMoreUrl: "http://www.mozilla.org",
learnMoreLabel: _("aboutMisc.learnMoreLabel"),
name: _("aboutMisc.name"),
subAwards: true,
bronzeId: "aboutPagesBronze",
silverId: "aboutPagesSilver",
goldId: "aboutPagesGold",
},
configOpened: {
id: "about:config",
obs: "about:config",
description: _("configOpened.description"),
hint: _("configOpened.hint"),
learnMoreUrl: "http://kb.mozillazine.org/About:config",
learnMoreLabel: _("configOpened.learnMoreLabel"),
name: _("configOpened.name"),
url: "about:config",
award: "silver", /* migrated from generic award */
subAwards: true,
bronzeId: "about:configBronze",
silverId: "about:config", /* migrated from generic award */
goldId: "about:configGold",
},
knowUrRights: {
id: "about:rights",
obs: "about:rights",
description: _("knowUrRights.description", brandShortName),
hint: _("knowUrRights.hint"),
learnMoreUrl: "http://www.mozilla.org/about/manifesto.html",
learnMoreLabel: _("knowUrRights.learnMoreLabel"),
name: _("knowUrRights.name"),
url: "about:rights",
award: "bronze",
},
frequentFlyer: {
id: "frequentFlyer",
obs: "frequentFlyer",
description: _("frequentFlyer.description"),
hint: _("frequentFlyer.hint"),
name: _("frequentFlyer.name"),
subAwards: true,
bronzeId: "frequentFlyerBronze",
silverId: "frequentFlyerSilver",
goldId: "frequentFlyerGold",
},
revolutionTelevised: {
id: "revolutionTelevised",
obs: "revolutionTelevised",
description: _("revolutionTelevised.description"),
hint: _("revolutionTelevised.hint"),
learnMoreUrl: "https://air.mozilla.org",
learnMoreLabel: _("revolutionTelevised.learnMoreLabel"),
name: _("revolutionTelevised.name"),
url: "*.air.mozilla.org",
award: "bronze",
},
yoDawg: {
id: "yoDawg",
obs: "chrome://browser/content/browser.xul",
description: _("yoDawg.description", brandShortName),
hint: _("yoDawg.hint"),
learnMoreUrl: "https://developer.mozilla.org/En/XUL",
learnMoreLabel: _("yoDawg.learnMoreLabel"),
name: _("yoDawg.name"),
url: "chrome://browser/content/browser.xul",
award: "bronze",
},
bookmarkAdded: {
id: "bookmarkAdded",
obs: "bookmarkAdded",
description: _("bookmarkAdded.description"),
learnMoreUrl: "http://support.mozilla.com/kb/how-do-i-use-bookmarks",
learnMoreLabel: _("bookmarkAdded.learnMoreLabel"),
hint: _("bookmarkAdded.hint"),
name: _("bookmarkAdded.name"),
subAwards: true,
bronzeId: "bookmarkAddedBronze",
silverId: "bookmarkAddedSilver",
goldId: "bookmarkAddedGold",
},
feedbackSubmitted: {
id: "feedbackSubmitted",
obs: "feedbackSubmitted",
description: _("feedbackSubmitted.description", brandShortName),
learnMoreUrl: "https://input.mozilla.org/feedback",
learnMoreLabel: _("feedbackSubmitted.learnMoreLabel"),
hint: _("feedbackSubmitted.hint"),
url: /https?:\/\/input.mozilla.(org|com)\/[^/]*\/thanks/,
name: _("feedbackSubmitted.name"),
award: "bronze",
},
releaseChannels: {
id: "releaseChannels",
obs: "releaseChannels",
description: _("releaseChannels.description", brandShortName),
learnMoreUrl: "http://www.mozilla.org/projects/firefox/prerelease.html",
learnMoreLabel: _("releaseChannels.learnMoreLabel", brandShortName),
hint: _("releaseChannels.hint"),
name: _("releaseChannels.name"),
subAwards: true,
bronzeId: "releaseChannelsBronze",
silverId: "releaseChannelsSilver",
goldId: "releaseChannelsGold",
hidden: true,
},
devTools: {
id: "devTools",
obs: "devTools",
description: _("devTools.description", brandShortName),
learnMoreUrl: "http://hacks.mozilla.org/category/developer-tools/",
learnMoreLabel: _("devTools.learnMoreLabel"),
hint: _("devTools.hint"),
name: _("devTools.name"),
subAwards: true,
bronzeId: "devToolsBronze",
silverId: "devToolsSilver",
goldId: "devToolsGold",
},
sociallyAwesomePenguin: {
id: "sociallyAwesomePenguin",
obs: "sociallyAwesomePenguin",
description: _("sociallyAwesomePenguin.description"),
hint: _("sociallyAwesomePenguin.hint"),
name: _("sociallyAwesomePenguin.name"),
subAwards: true,
bronzeId: "sociallyAwesomePenguinBronze",
silverId: "sociallyAwesomePenguinSilver",
goldId: "sociallyAwesomePenguinGold",
},
socialButterfly: {
id: "socialButterfly",
obs: "socialButterfly",
description: _("socialButterfly.description", brandShortName),
hint: _("socialButterfly.hint"),
name: _("socialButterfly.name"),
subAwards: true,
bronzeId: "socialButterflyBronze",
silverId: "socialButterflySilver",
goldId: "socialButterflyGold",
},
tabCandy: {
id: "tabCandy",
obs: "tabCandy",
description: _("tabCandy.description"),
hint: _("tabCandy.hint"),
name: _("tabCandy.name"),
subAwards: true,
bronzeId: "tabCandyBronze",
silverId: "tabCandySilver",
goldId: "tabCandyGold",
hidden: true,
},
concurrentTabs: {
id: "concurrentTabs",
obs: "concurrentTabs",
description: _("concurrentTabs.description"),
hint: _("concurrentTabs.hint"),
name: _("concurrentTabs.name"),
subAwards: true,
bronzeId: "concurrentTabsBronze",
silverId: "concurrentTabsSilver",
goldId: "concurrentTabsGold",
hidden: true,
},
geekCred: {
id: "geekCred",
obs: "geekCred",
description: _("geekCred.description"),
hint: _("geekCred.hint"),
name: _("geekCred.name"),
subAwards: true,
bronzeId: "geekCredBronze",
silverId: "geekCredSilver",
goldId: "geekCredGold",
}
};

let totalCheevos = [];
for (let index in cheevos) {
totalCheevos[totalCheevos.length] = cheevos[index];
totalAwards += cheevos[index].subAwards ? 3 : 1;
}

if (!ss.cheevosAcquired)
ss.cheevosAcquired = {};
Expand Down Expand Up @@ -370,6 +104,13 @@
ss.viewSourceOpenings = 0;
if (!ss.geekCredVisits)
ss.geekCredVisits = 0;

let totalCheevos = [];
for (let index in cheevos) {
totalCheevos[totalCheevos.length] = cheevos[index];
totalAwards += cheevos[index].subAwards ? 3 : 1;
}

addObs(cheevos.lwThemeChanged.obs, onLightweightThemeChanged, this);
addObs(cheevos.dmRemoveDownload.obs, onDownloadManagerRemoveDownload, this);
addObs(cheevos.privateBrowsingEnter.obs, onPrivateBrowsingEnter, this);
Expand Down Expand Up @@ -768,11 +509,10 @@
onObservation(cheevos.concurrentTabs, true, "gold");
}

var windowDelegate = {
WindowTracker({
onTrack: function (window) {
function addMenuItem(window) {
if (window.location != "chrome://browser/content/browser.xul")
return;
if (isBrowser(window)) return;

log("adding menu item");
const NS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
Expand Down Expand Up @@ -882,7 +622,7 @@
updateToolbarButtonLabel(acquiredPoints);
},
onUntrack: function (window) {
if (window.location == "chrome://browser/content/browser.xul") {
if (isBrowser(window)) {
log("removing menu item");
const fileMenuitemID = "menu_CheevoItem";
var $ = function(id) window.document.getElementById(id);
Expand All @@ -900,8 +640,7 @@
unloaders.forEach(function(f) f());
unloaders.length = 0;
}
};
var tracker = new winUtils.WindowTracker(windowDelegate);
});

var myPrefObserver = {
register: function() {
Expand Down
Loading