Skip to content

Commit

Permalink
Added max length validation support
Browse files Browse the repository at this point in the history
  • Loading branch information
evadi committed Sep 20, 2014
1 parent 463b7dc commit e00d82c
Show file tree
Hide file tree
Showing 4 changed files with 458 additions and 208 deletions.
66 changes: 34 additions & 32 deletions js/background.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* Extensions that are used in this script */

if (typeof String.prototype.startsWith != 'function') {

String.prototype.startsWith = function (str){
return this.slice(0, str.length) == str;
};

}


Expand All @@ -23,55 +23,55 @@ var displayTypes = Object.freeze({

//controls the operation of the extension
var Controller = (function () {

//constructor
function Controller () {

//Tab we are currently controlling
this.activeTargetId = 0;

//Where is the data being displayed
this.displayTarget = displayTypes.CONSOLE;

//load the users settings
this.loadSettings();
}

//send request to regenerate field data
Controller.prototype.update = function () {
Controller.prototype.update = function (userCommand) {
if (this.activeTargetId !== 0) {
chrome.tabs.sendMessage(this.activeTargetId, { action: actions.RELOAD, target: this.displayTarget });
chrome.tabs.sendMessage(this.activeTargetId, { action: actions.RELOAD, target: this.displayTarget, command: userCommand });
}
};

//checks that a given url is in the approved list managed by the user
Controller.prototype.isApprovedUrl = function (urlToApprove) {
return (urlToApprove.startsWith("http://") || urlToApprove.startsWith("https://"));
return true; //(urlToApprove.startsWith("http://") || urlToApprove.startsWith("https://"));
};

//clears the active tab
Controller.prototype.clearActiveTab = function () {
this.activeTargetId = 0;
};

//reads the latest settings
Controller.prototype.updateSettings = function (newSettings) {
if (newSettings) {
this.displayTarget = newSettings.display;
console.log(this.displayTarget);
}
};

//load user settings and apply them
Controller.prototype.loadSettings = function () {
var _this = this;
evadi.blabr.data.getSettings(function (settings) {
_this.updateSettings(settings);
});
};

return Controller;

})();

//create the main controller instance
Expand All @@ -82,29 +82,29 @@ var controller = new Controller();

//Capture requests from other areas of the extension
chrome.extension.onMessage.addListener(function (request, sender, sendRequest) {

if (request.action == actions.FORCERELOAD) {
controller.activeTargetId = sender.tab.id;
controller.update();
}

});

//when a tab is updated, and only when it is complete then check it's url
//if it matches the approved list then hold on to it's id
chrome.tabs.onUpdated.addListener(function (tabId, change, tab) {

if (change.status == "complete") {

//check it's url to see if it is in the approved list
if(controller.isApprovedUrl(tab.url)) {
//make this the currently active tab
controller.activeTargetId = tabId;
console.log("target tab changed ", controller.activeTargetId);
}

}

});

//when a tab becomes active, then check it's url
Expand All @@ -113,28 +113,30 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {

//get information about this tab
chrome.tabs.query({ active: true, status: "complete" }, function (tabs) {

//we may have more than one result if the tab has dev tools open
tabs.forEach(function (tab) {

//now check the tabs url
if (controller.isApprovedUrl(tab.url)) {
//make this the currently active tab
controller.activeTargetId = tab.id;
console.log("target tab changed ", controller.activeTargetId);
}

});

});

});

//Listen for keyboard shortcut presses
chrome.commands.onCommand.addListener(function (command) {

if (command === "refresh_data") {
controller.update();
}

switch (command) {
case "hidden_fields":
case "max_lengths":
controller.update(command);
break;
}

});
Loading

0 comments on commit e00d82c

Please sign in to comment.