Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemorroj committed Jul 19, 2012
2 parents 798675c + ca81d33 commit 8d09935
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 90 deletions.
2 changes: 1 addition & 1 deletion config.xml
Expand Up @@ -89,4 +89,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.</license>
</widget>
</widget>
152 changes: 90 additions & 62 deletions includes/noads-options.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion includes/noads-service.js
Expand Up @@ -762,4 +762,4 @@ var run = {
delElement(overlay);
}
}
};
};
9 changes: 5 additions & 4 deletions includes/noads.js
Expand Up @@ -79,8 +79,8 @@ function onPopupMessageHandler(e) {
case 'show_preferences':
options.showPreferences(domain);
break;
case 'ask_menu_status':
e.source.postMessage(encodeMessage({type: 'menu_status_enable'}));
case 'ask_status':
e.source.postMessage(encodeMessage({type: 'status_enabled'}));
break;
}
}
Expand Down Expand Up @@ -245,15 +245,16 @@ window.addEventListener('DOMContentLoaded', function () {
// Create menu messaging channel and parse background messages
opera.extension.onmessage = onMessageHandler;


if (options.checkEnabled('noads_button_state')) {
log('Button is enabled...');
addStyle(quickButtonCSS, 'qbCSS');
window.addEventListener('mousemove', showQuickButton, false);
}

sendMessage({type: 'status_enabled'});
}
}
}, false);
}, true);

// Main body
(function () {
Expand Down
56 changes: 38 additions & 18 deletions scripts/noads-background.js
@@ -1,8 +1,9 @@
var button, notification_text = '', debug = false, lng = {}, menu_resized = false, actual_font = 0;
var button, notification_text = '', debug = false, lng = {}, menu_resized = false, actual_font = 0;

window.addEventListener('load', function () {
debug = options.checkEnabled('noads_debug_enabled_state');
lng = new TRANSLATION();
var debug = options.checkEnabled('noads_debug_enabled_state'),
lng = new TRANSLATION (),
v12 = (typeof opera.extension.tabGroups !== 'undefined');

if (options.checkEnabled('noads_tb_enabled_state')) {
button = opera.contexts.toolbar.createItem({
Expand All @@ -14,7 +15,7 @@ window.addEventListener('load', function () {
width: lng.baseMenuWidth || 180,
height: lng.baseMenuHeight || 155
},
badge : {
badge: {
display: 'none',
textContent: '0',
color: 'white',
Expand All @@ -23,26 +24,43 @@ window.addEventListener('load', function () {
});
opera.contexts.toolbar.addItem(button);
} else {
button = { disabled: true };
button = {
disabled: true
};
}

function enableButton () {
button.disabled = !opera.extension.tabs.getFocused();
function toggleButton (e) {
var atab = opera.extension.tabs.getFocused();
button.disabled = v12 ? !atab.port : !atab;
}

function setButtonState (port, state) {
if (v12) {
// in case source tab is active
if (port === opera.extension.tabs.getFocused().port) {
button.disabled = !state;
}
}
}

function onConnectHandler (e) {
var tab = opera.extension.tabs.getFocused();
if (!tab) return;
var atab = opera.extension.tabs.getFocused();
if (!atab || !e) return;
// if we got a message fom the menu
if (e && e.origin && ~e.origin.indexOf('menu.html') && ~e.origin.indexOf('widget://')) {
tab.postMessage(encodeMessage({ type: 'noads_bg_port' }), [e.source]);
if (e.origin && ~e.origin.indexOf('menu.html') && ~e.origin.indexOf('widget://')) {
atab.postMessage(encodeMessage({ type: 'noads_bg_port' }), [e.source]);
} else {
// if we got a message fom a page
if (notification_text !== '') {
tab.postMessage(encodeMessage({ type: 'noadsadvanced_autoupdate', text: notification_text}));
atab.postMessage(encodeMessage({
type: 'noadsadvanced_autoupdate',
text: notification_text
}));
notification_text = '';
}
enableButton();

// button will be disabled for new tabs
setButtonState(e.source, false);
}
}

Expand All @@ -54,6 +72,9 @@ window.addEventListener('load', function () {
// button.badge.textContent = message.blocked || '0';
// button.badge.color = "white";
// break;
case 'status_enabled':
setButtonState(e.source, true);
break;
case 'get_filters':
if (!e.source) return;

Expand All @@ -67,8 +88,7 @@ window.addEventListener('load', function () {
return;
}

var message_rules = 0, message_success = [], message_error = [], message_fileerror = [],
importerCallback = function (rulesN) {
var message_rules = 0, message_success = [], message_error = [], message_fileerror = [], importerCallback = function (rulesN) {
if (rulesN) {
message_success.push(message.url[subsc]);
message_rules = rulesN;
Expand Down Expand Up @@ -145,7 +165,7 @@ window.addEventListener('load', function () {
if (options.checkEnabled('noads_autoupdate_state')) {
var next_update = Number(getValue('noads_last_update')) + Number(getValue('noads_autoupdate_interval'));
if (next_update < Date.now()) {
var url = options.getSubscriptions(), allRules = options.checkEnabled('noads_allrules_state'), importerCallback = function(rulesN) {
var url = options.getSubscriptions(), allRules = options.checkEnabled('noads_allrules_state'), importerCallback = function (rulesN) {
notification_text = lng.pAutoUpdateComplete || 'NoAds Advanced autoupdated';
};
for (var subsc = 0, l = url.length; subsc < l; subsc++) {
Expand All @@ -164,7 +184,7 @@ window.addEventListener('load', function () {

// Enable the button when a tab is ready.
opera.extension.onconnect = onConnectHandler;
opera.extension.tabs.onfocus = enableButton;
opera.extension.tabs.onblur = enableButton;
opera.extension.tabs.onfocus = toggleButton;
//opera.extension.tabs.onblur = toggleButton;
opera.extension.onmessage = onMessageHandler;
}, false);
6 changes: 3 additions & 3 deletions scripts/noads-menu.js
Expand Up @@ -7,7 +7,7 @@ html.setAttribute('xml:lang', window.navigator.language);
function onMessageHandler (e) {
if (!e || !e.data) return;
// if we want to interact with the menu from injected script
if (decodeMessage(e.data).type === 'menu_status_enable') {
if (decodeMessage(e.data).type === 'status_enabled') {
if (document && document.body) {
document.body.style.color = 'black';
}
Expand All @@ -21,7 +21,7 @@ function sendCommand (message) {
theport.postMessage(encodeMessage(message));
} catch(e) {}
}
self.close();
window.close();
}


Expand Down Expand Up @@ -72,7 +72,7 @@ window.addEventListener('DOMContentLoaded', function () {

if (theport) {
try {
theport.postMessage(encodeMessage({type: 'ask_menu_status'}));
theport.postMessage(encodeMessage({type: 'ask_status'}));
} catch(e) {}
}

Expand Down
2 changes: 1 addition & 1 deletion styles/noads-menu.css
Expand Up @@ -4,7 +4,7 @@ body {
margin: 0;
padding-left: 0;
padding-right: 0;
background-color: white;
background-color: #f4f4f5;
color: black;
font-family: Tahoma, Sans-serif;
font-size: 12px !important;
Expand Down

0 comments on commit 8d09935

Please sign in to comment.