more fixes for #105

This commit is contained in:
gorhill 2015-01-21 11:13:32 -05:00
parent fcb65e6002
commit 7b8392ca48
3 changed files with 27 additions and 20 deletions

View file

@ -308,19 +308,23 @@ var tabsProgressListener = {
var tabId = vAPI.tabs.getTabId(browser);
// LOCATION_CHANGE_SAME_DOCUMENT = "did not load a new document"
if ( flags & 1 ) {
vAPI.tabs.onUpdated(tabId, {url: location.asciiSpec}, {
frameId: 0,
tabId: tabId,
url: browser.currentURI.asciiSpec
});
} else if ( location.schemeIs('http') || location.schemeIs('https') ) {
vAPI.tabs.onNavigation({
frameId: 0,
tabId: tabId,
url: location.asciiSpec
});
return;
}
// https://github.com/gorhill/uBlock/issues/105
// Allow any kind of pages
vAPI.tabs.onNavigation({
frameId: 0,
tabId: tabId,
url: location.asciiSpec
});
}
};
@ -1359,6 +1363,8 @@ vAPI.contextMenu.displayMenuItem = function(e) {
var menuitem = doc.getElementById(vAPI.contextMenu.menuItemId);
var currentURI = gContextMenu.browser.currentURI;
// https://github.com/gorhill/uBlock/issues/105
// TODO: Should the element picker works on any kind of pages?
if ( !currentURI.schemeIs('http') && !currentURI.schemeIs('https') ) {
menuitem.hidden = true;
return;

View file

@ -197,6 +197,8 @@ var getStats = function(tabId) {
r.hostnameDict = getHostnameDict(pageStore.hostnameToCountMap);
r.contentLastModified = pageStore.contentLastModified;
r.dynamicFilterRules = getDynamicFilterRules(pageStore.pageHostname, r.hostnameDict);
r.canElementPicker = r.pageHostname.indexOf('.') !== -1;
r.canRequestLog = canRequestLog;
} else {
r.hostnameDict = {};
r.dynamicFilterRules = getDynamicFilterRules();
@ -204,9 +206,15 @@ var getStats = function(tabId) {
return r;
};
// Not the most elegant approach, but it does keep everything simple:
// This will be set by getTargetTabId() and used by getStats().
var canRequestLog = true;
/******************************************************************************/
var getTargetTabId = function(tab) {
canRequestLog = true;
if ( !tab ) {
return '';
}
@ -220,11 +228,14 @@ var getTargetTabId = function(tab) {
// This allows a user to actually modify filtering profile for
// behind-the-scene requests.
canRequestLog = false;
// Extract the target tab id from the URL
var matches = tab.url.match(/[\?&]tabId=([^&]+)/);
if ( matches && matches.length === 2 ) {
return matches[1];
}
return tab.id;
};

View file

@ -298,23 +298,13 @@ var buildAllDynamicFilters = function() {
var renderPopup = function() {
uDom('#appname').text(popupData.appName);
uDom('#version').text(popupData.appVersion);
var isHTTP = /^https?:\/\/[0-9a-z]/.test(popupData.pageURL);
// Condition for dynamic filtering toggler:
// - Advanced user
uDom('body').toggleClass('advancedUser', popupData.advancedUserEnabled);
uDom('#switch').toggleClass('off', popupData.pageURL === '' || !popupData.netFilteringSwitch);
// Conditions for request log:
// - `http` or `https` scheme
uDom('#gotoLog').toggleClass('enabled', isHTTP);
uDom('#gotoLog').attr('href', 'devtools.html?tabId=' + popupData.tabId);
// Conditions for element picker:
// - `http` or `https` scheme
uDom('#gotoPick').toggleClass('enabled', isHTTP);
// If you think the `=== true` is pointless, you are mistaken
uDom('#gotoLog').toggleClass('enabled', popupData.canRequestLog === true)
.attr('href', 'devtools.html?tabId=' + popupData.tabId);
uDom('#gotoPick').toggleClass('enabled', popupData.canElementPicker === true);
var or = vAPI.i18n('popupOr');
var blocked = popupData.pageBlockedRequestCount;