Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: background.js

Issue 5589897452716032: Implemented ext.contextMenus for Safari (Closed)
Patch Set: Created Jan. 18, 2014, 10:29 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | block.js » ('j') | safari/background.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -73,22 +73,8 @@
});
}
-// Sets options to defaults, upgrading old options from previous versions as necessary
-function setDefaultOptions()
-{
- function defaultOptionValue(opt, val)
- {
- if(!(opt in localStorage))
- localStorage[opt] = val;
- }
-
- defaultOptionValue("shouldShowBlockElementMenu", "true");
-
- removeDeprecatedOptions();
-}
-
-// Upgrade options before we do anything else.
-setDefaultOptions();
+// Remove deprecated options before we do anything else.
+removeDeprecatedOptions();
/**
* Checks whether a page is whitelisted.
@@ -133,11 +119,10 @@
iconAnimation.registerTab(tab, iconFilename);
- // Set context menu status according to whether current tab has whitelisted domain
if (excluded)
- chrome.contextMenus.removeAll();
+ ext.contextMenus.hideMenuItems();
else
- showContextMenu();
+ ext.contextMenus.showMenuItems();
}
/**
@@ -255,22 +240,28 @@
notifyUser();
}
-// Set up context menu for user selection of elements to block
-function showContextMenu()
+function setContextMenu()
{
- ext.contextMenus.removeAll(function()
+ if (Prefs.shouldShowBlockElementMenu)
{
- if(typeof localStorage["shouldShowBlockElementMenu"] == "string" && localStorage["shouldShowBlockElementMenu"] == "true")
+ // Register context menu item
+ ext.contextMenus.addMenuItem(ext.i18n.getMessage("block_element"), ["image", "video", "audio"], function(srcUrl, tab)
{
- ext.contextMenus.create(ext.i18n.getMessage("block_element"), ["image", "video", "audio"], function(srcUrl, tab)
- {
- if(srcUrl)
- tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl});
- });
- }
- });
+ if (srcUrl)
+ tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl});
+ });
+ }
+ else
+ ext.contextMenus.removeMenuItems();
}
+Prefs.addListener(function(name)
+{
+ if (name == "shouldShowBlockElementMenu")
+ setContextMenu();
+});
+setContextMenu();
+
/**
* Opens options tab or focuses an existing one, within the last focused window.
* @param {Function} callback function to be called with the
@@ -393,7 +384,7 @@
{
var collapse = filter.collapse;
if (collapse == null)
- collapse = (localStorage.hidePlaceholders != "false");
+ collapse = Prefs.hidePlaceholders;
sendResponse(collapse);
}
else
« no previous file with comments | « no previous file | block.js » ('j') | safari/background.js » ('J')

Powered by Google App Engine
This is Rietveld