diff --git a/_locales/en/messages.json b/_locales/en/messages.json index d244cdd..f5c8ee4 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -7,7 +7,7 @@ "message": "Enforces a 25min/5min workflow: 25 minutes of distraction-free work, followed by 5 minutes of break. Repeat as necessary.", "description": "Description of the extension" }, - + "work": { "message": "work", "description": "The name of the work timer" @@ -20,7 +20,7 @@ "message": "minutes", "description": "The name of the time interval representing 60 seconds" }, - + "site_blocked_info": { "message": "Page blocked until a break timer starts.", "description": "Text for the blocked-site overlay, explaining that the site is blocked and when it will become unblocked" @@ -29,7 +29,7 @@ "message": "Back to work!", "description": "Text for the blocked-site overlay, motivating the user to get back to work" }, - + "options_title": { "message": "Strict Workflow Options", "description": "The title of the options page" @@ -86,7 +86,7 @@ "message": "Save successful", "description": "On the options page, message to indicate that the options have been saved" }, - + "timer_end_notification_header": { "message": "Time's up!", "description": "Bold header of pop-up notification when a timer ends" @@ -100,5 +100,23 @@ "example": "work" } } + }, + "contextmenu_volume_label": { + "message": "Volume: $volume$% (Click to test)", + "description": "Volume value that appears in context menu.", + "placeholders": { + "volume": { + "content": "$1", + "example": "80" + } + } + }, + "contextmenu_volume_up_label": { + "message": "Volume Up", + "description": "Label that appears in context menu for \"Volume Up\"." + }, + "contextmenu_volume_down_label": { + "message": "Volume Down", + "description": "Label that appears in context menu for \"Volume Down\"." } } diff --git a/background.js b/background.js index 75062fe..641075f 100644 --- a/background.js +++ b/background.js @@ -36,6 +36,7 @@ function defaultPrefs() { break: 5 * 60 }, shouldRing: true, + volume: 1, clickRestarts: false, whitelist: false } @@ -54,17 +55,17 @@ function updatePrefsFormat(prefs) { // say, adding boolean flags with false as the default, there's no // compatibility issue. However, in more complicated situations, we need // to modify an old PREFS module's structure for compatibility. - + if(prefs.hasOwnProperty('domainBlacklist')) { // Upon adding the whitelist feature, the domainBlacklist property was // renamed to siteList for clarity. - + prefs.siteList = prefs.domainBlacklist; delete prefs.domainBlacklist; savePrefs(prefs); console.log("Renamed PREFS.domainBlacklist to PREFS.siteList"); } - + if(!prefs.hasOwnProperty('showNotifications')) { // Upon adding the option to disable notifications, added the // showNotifications property, which defaults to true. @@ -72,7 +73,7 @@ function updatePrefsFormat(prefs) { savePrefs(prefs); console.log("Added PREFS.showNotifications"); } - + return prefs; } @@ -91,9 +92,11 @@ function loadRingIfNecessary() { console.log('is ring necessary?'); if(PREFS.shouldRing && !ringLoaded) { console.log('ring is necessary'); + RING.volume = PREFS.volume; RING.onload = function () { console.log('ring loaded'); ringLoaded = true; + RING.volume = PREFS.volume; } RING.load(); } @@ -143,7 +146,7 @@ function Pomodoro(options) { this.currentTimer = new Pomodoro.Timer(this, timerOptions); this.currentTimer.start(); } - + this.restart = function () { if(this.currentTimer) { this.currentTimer.restart(); @@ -162,7 +165,7 @@ Pomodoro.Timer = function Timer(pomodoro, options) { options.onStart(timer); options.onTick(timer); } - + this.restart = function() { this.timeRemaining = options.duration; options.onTick(timer); @@ -260,7 +263,7 @@ function isLocationBlocked(location) { return !PREFS.whitelist; } } - + // If we're in a whitelist, an unmatched location is blocked => true // If we're in a blacklist, an unmatched location is not blocked => false return PREFS.whitelist; @@ -270,7 +273,7 @@ function executeInTabIfBlocked(action, tab) { var file = "content_scripts/" + action + ".js", location; location = tab.url.split('://'); location = parseLocation(location[1]); - + if(isLocationBlocked(location)) { chrome.tabs.executeScript(tab.id, {file: file}); } @@ -296,7 +299,7 @@ var notification, mainPomodoro = new Pomodoro({ path: ICONS.ACTION.PENDING[timer.pomodoro.nextMode] }); chrome.browserAction.setBadgeText({text: ''}); - + if(PREFS.showNotifications) { var nextModeName = chrome.i18n.getMessage(timer.pomodoro.nextMode); chrome.notifications.create("", { @@ -308,7 +311,7 @@ var notification, mainPomodoro = new Pomodoro({ iconUrl: ICONS.FULL[timer.type] }, function() {}); } - + if(PREFS.shouldRing) { console.log("playing ring", RING); RING.play(); @@ -342,7 +345,7 @@ var notification, mainPomodoro = new Pomodoro({ }); chrome.browserAction.onClicked.addListener(function (tab) { - if(mainPomodoro.running) { + if(mainPomodoro.running) { if(PREFS.clickRestarts) { mainPomodoro.restart(); } @@ -364,3 +367,52 @@ chrome.notifications.onClicked.addListener(function (id) { chrome.windows.update(window.id, {focused: true}); }); }); + +/* + Context menu + */ + +chrome.contextMenus.create({ + contexts: ["browser_action"], + "title": chrome.i18n.getMessage("contextmenu_volume_up_label"), + "onclick": volumeUp +}); + +chrome.contextMenus.create({ + contexts: ["browser_action"], + "title": chrome.i18n.getMessage("contextmenu_volume_down_label"), + "onclick": volumeDown +}); + +var volumeLabel = chrome.contextMenus.create({ + contexts: ["browser_action"], + "title": getVolumeStatusLabel(), + "onclick": volumeTest +}); + +function volumeUp() { + adjustVolume(1); +} + +function volumeDown() { + adjustVolume(-1); +} + +function adjustVolume(adjustBy) { + RING.volume = (RING.volume * 10 + adjustBy) / 10; + updateVolumeLabel(); + PREFS.volume = RING.volume; + savePrefs(PREFS); +} + +function volumeTest() { + RING.play(); +} + +function updateVolumeLabel() { + chrome.contextMenus.update(volumeLabel, {title: getVolumeStatusLabel() }) +} + +function getVolumeStatusLabel() { + return chrome.i18n.getMessage("contextmenu_volume_label", [RING.volume * 100]); +} diff --git a/manifest.json b/manifest.json index a14614e..4fee43d 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "manifest_version": 2, "name": "__MSG_ext_name__", "options_page": "options.html", - "permissions": [ "notifications", "tabs", "" ], + "permissions": [ "notifications", "tabs", "", "contextMenus" ], "version": "1.7.0", "web_accessible_resources": [ "icons/work_full.png",