Skip to content

Commit

Permalink
Converted pageAction to browserAction to use badges in the future; up…
Browse files Browse the repository at this point in the history
…dated icons
  • Loading branch information
amrod committed Apr 21, 2015
1 parent 64867a3 commit 88bb614
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 80 deletions.
Binary file modified icons/fast-redmine-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/fast-redmine-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/fast-redmine-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/fast-redmine-38.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/fast-redmine-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/fast-redmine-bw-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/fast-redmine-bw-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/fast-redmine-bw-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/fast-redmine-bw-38.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/fast-redmine-bw-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 4 additions & 14 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@
"persistent": false
},

"page_action": {
"default_icon": {
"19": "icons/fast-redmine-bw-19.png",
"38": "icons/fast-redmine-bw-38.png"
},
"default_title": "Faster Redmine",
"default_popup": "popup.html"
},

"options_ui": {
"page": "options.html",
"chrome_style": true,
Expand All @@ -47,10 +38,9 @@

"browser_action": {
"default_icon": {
"19": "icons/fast-redmine-16.png",
"38": "icons/fast-redmine-48.png"
"19": "icons/fast-redmine-19.png",
"38": "icons/fast-redmine-38.png"
},
"default_title": "Faster Redmine"
},

}
}
}
36 changes: 19 additions & 17 deletions scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {

} else if (request.removePermission && request.origins) {
removePermission(request.origins, sendResponse);

} else if (request.hasPermission && request.origin) {
hasPermission(request.origin, sendResponse );

} else if (request.requestRefreshPageActionAllTabs) {
refreshPageActionIconAllTabs();
} else if (request.requestRefreshBrowserActionAllTabs) {
refreshBrowserActionIconAllTabs();

} else if (request.getContentVariables) {
getContentVariables(sendResponse);
Expand All @@ -39,7 +39,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {

if (changeInfo.status === 'complete') {
refreshPageActionIcon(tab);
refreshBrowserActionIcon(tab);
}
});

Expand Down Expand Up @@ -98,17 +98,17 @@ function getContentVariables(callback) {
});
}

function refreshPageActionIconAllTabs() {
function refreshBrowserActionIconAllTabs() {
chrome.tabs.query({}, function(arrayOfTabs) {
for (var i = 0; i < arrayOfTabs.length; i++) {
if (arrayOfTabs[i].status == "complete") {
refreshPageActionIcon(arrayOfTabs[i]);
refreshBrowserActionIcon(arrayOfTabs[i]);
}
}
});
}

function refreshPageActionIcon (tab) {
function refreshBrowserActionIcon (tab) {

var url = tab.url.split('#')[0]; // Exclude URL fragments

Expand All @@ -120,22 +120,24 @@ function refreshPageActionIcon (tab) {
re = RegExp(items.redmineUrl);

if (!(re.test(url) && url !== "chrome://extensions")) {
return;
}
var paths = {"38": "icons/fast-redmine-bw-38.png"};

if (granted) {
var paths = {"19": "icons/fast-redmine-bw-19.png", "38": "icons/fast-redmine-bw-38.png"};
chrome.browserAction.setIcon({tabId: tab.id, path: paths});

chrome.pageAction.setIcon({tabId: tab.id, path: paths});
chrome.pageAction.show(tab.id);
}else if (granted) {
var paths = {"38": "icons/fast-redmine-38.png"};

chrome.browserAction.setIcon({tabId: tab.id, path: paths});
injectScripts(tab.id);

} else {
var paths = {"19": "icons/fast-redmine-bw-blocked-19.png", "38": "icons/fast-redmine-bw-blocked-38.png"};

chrome.pageAction.setIcon({tabId: tab.id, path: paths});
chrome.pageAction.show(tab.id);
}
chrome.browserAction.setIcon({tabId: tab.id, path: paths});
}

//chrome.browserAction.show(tab.id);

});
});
}
Expand Down Expand Up @@ -222,4 +224,4 @@ function injectScripts(tabId) {
runAt: "document_end"
});
});
}
}
99 changes: 50 additions & 49 deletions scripts/options.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
// Saves options to chrome.storage.sync.
function saveOptions() {

var key = document.getElementById('key').value;
var redmineUrl = document.getElementById('redmineUrl').value;
var propagate = document.getElementById('propagate').checked;
var reload = document.getElementById('reload').checked;

if ( redmineUrl.slice(-1) !== "/" ) {
redmineUrl = redmineUrl + "/";
}

var re = /^https?:\/\/(www\.)?[-a-zA-Z0-9:%._\+~#=]{2,256}\.[a-z]{2,4}\b(\/)$/g;
var key = document.getElementById('key').value;
var redmineUrl = document.getElementById('redmineUrl').value;
var propagate = document.getElementById('propagate').checked;
var reload = document.getElementById('reload').checked;

if ( redmineUrl.slice(-1) !== "/" ) {
redmineUrl = redmineUrl + "/";
}

if (!isValidURL(redmineUrl)) {
notifyUser('Invalid URL. Please enter the root domain only. e.g. https://redmine.mycompany.com/');
return;
}

if (!re.test(redmineUrl)) {
notifyUser('Invalid URL. Please enter the root domain only. e.g. https://regmine.mycompany.com/');
return;
}

chrome.storage.sync.set({
propagate: propagate,
redmineUrl: redmineUrl,
reload: reload
}, function() {
// Store key locally
chrome.storage.local.set({
key: key
}, notifyUser);
});

chrome.runtime.sendMessage({requestPermission: true, origins: [redmineUrl]}, function(response) {
if (response.granted) {
notifyUser('Access to ' + redmineUrl + ' granted.');
refreshPageActionIconAllTabs();
} else {
notifyUser('Permission not granted. Extension WILL NOT function on these domains.');
}
});
/** Remove permissions to any current Redmine URL */
chrome.runtime.sendMessage({getContentVariables: true}, function(contentVars) {
if (isValidURL(contentVars.redmineURL))
{
chrome.runtime.sendMessage({removePermission: true, origins: contentVars.redmineURL}, function(response) {});
}
});

chrome.storage.sync.set({
propagate: propagate,
redmineUrl: redmineUrl,
reload: reload
}, function() {
// Store key locally
chrome.storage.local.set({key: key}, notifyUser);
});

chrome.runtime.sendMessage({requestPermission: true, origins: [redmineUrl]}, function(response) {
if (response.granted) {
notifyUser('Access to ' + redmineUrl + ' granted.');
refreshBrowserActionIconAllTabs();
} else {
notifyUser('Permission not granted. Extension WILL NOT function on these domains.');
}
});
}

function refreshPageActionIconAllTabs() {
chrome.runtime.sendMessage({requestRefreshPageActionAllTabs: true}, function(response) {
// Do nothing else
});
function isValidURL(url) {
var re = /^https?:\/\/((www\.)?[-a-zA-Z0-9:%._\+~#=]{2,256}\.[a-z]{2,4}\b(\/)$|localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\,\d{1,3})/gi;

if (!re.test(url))
return false;
else
return true;

}

function hasPermission(url){
chrome.permissions.contains({
permissions: ['contentSettings'],
origins: [url]
}, function(result) {
if (result) {
//console.log("hasPermission(" + url +"): true");
} else {
//console.log("hasPermission(" + url +"): false");
}
function refreshBrowserActionIconAllTabs() {
chrome.runtime.sendMessage({requestRefreshBrowserActionAllTabs: true}, function(response) {
// Do nothing else
});
}

Expand Down Expand Up @@ -130,4 +131,4 @@ function clearPermissions() {

document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);
document.getElementById('clear').addEventListener('click', clearPermissions);
document.getElementById('clear').addEventListener('click', clearPermissions);

0 comments on commit 88bb614

Please sign in to comment.