Permalink
Browse files

all features present, gui a bit rough

  • Loading branch information...
1 parent 8812e1b commit 90958f854d1c7abaa5bb85c42442dc72c70c212e @BenoitHiller committed May 23, 2012
Showing with 59 additions and 32 deletions.
  1. +2 −3 lib/button.js
  2. +14 −3 lib/matcher.js
  3. +42 −25 lib/options.html
  4. +1 −1 lib/util.js
View
@@ -5,9 +5,8 @@ check_window_close_tabs = function(win) {
manager.load_matchers();
// var matchers = localStorage["tab-closer-matchers"].split(",");
var window_setting = (localStorage["window-setting"] === "true");
- var regex_setting = (localStorage["regex-setting"] === "true");//XXX Change this
for (var i=0; i < manager.matchers.length; i++){
- if (regex_setting) {
+ if (manager.matchers[i]._regex) {
manager.matchers[i].find_all_tabs(window_setting,win.id);
}
else {
@@ -26,7 +25,7 @@ button_handler = function(tab) {
}
omnibox_handler = function(string) {
- var matcher = new Matcher(string);
+ var matcher = new Matcher({'string':string});
var callback = check_window_regex_tabs.bind(matcher);
chrome.windows.getCurrent(callback);
}
View
@@ -46,7 +46,7 @@ MatcherManager.prototype = {
}
},
- save_matchers: function(use_regex) {
+ save_matchers: function() {
var syntax_error = false;
var a = [];
for (var i=0; i < this.matchers.length; i++) {
@@ -66,7 +66,6 @@ MatcherManager.prototype = {
return false;
}
else {
- console.log(a);
localStorage["matchers"] = JSON.stringify(a);
return true;
}
@@ -90,7 +89,7 @@ Matcher.prototype = {
var params = {}
}
this.string = params["string"] || "";
- this._regex = params["_regex"] || true;
+ this._regex = params["_regex"];
this.on_page = false;
},
@@ -106,6 +105,7 @@ Matcher.prototype = {
update_fields: function() {
if (this.on_page) {
this.string = this._text_field.value;
+ this._regex = this._regex_input.checked;
}
},
@@ -132,6 +132,17 @@ Matcher.prototype = {
this.matcher_box.appendChild(this._text_field);
this.create_delete_button(manager);
this.matcher_box.appendChild(this._delete_button);
+ this.create_options_div();
+ this.matcher_box.appendChild(this._regex_box);
+ },
+
+ create_options_div: function() {
+ this._regex_box = document.createElement("div");
+ this._regex_input = document.createElement("input");
+ this._regex_input.setAttribute("type","checkbox");
+ this._regex_box.appendChild(this._regex_input);
+ this._regex_input.checked = this._regex;
+ this._regex_box.appendChild(document.createTextNode("Use Regex"));
},
create_box_div: function() {
View
@@ -66,13 +66,12 @@
var options = document.getElementById("matchers");
var window_setting = document.getElementById("windowSetting");
var regex_setting = document.getElementById("regexSetting");
- syntax_error = manager.save_matchers(regex_setting.checked);
+ syntax_error = manager.save_matchers();
if (!syntax_error) {
notify("Could not save settings! There are errors in your matchers.");
}
else {
localStorage["window-setting"] = window_setting.checked;
- localStorage["regex-setting"] = regex_setting.checked;
if (manager) {
notify("Settings saved successfully.");
}
@@ -97,43 +96,61 @@
load_matchers(manager);
}
+ function toggle_help(id) {
+ var divs = document.getElementById("switcher").children;
+ var open_after;
+ for (i=0;i< divs.length; i++) {
+ if (divs[i].id == id) {
+ open_after = i;
+ }
+ divs[i].style.display = "none";
+ }
+ divs[open_after].style.display = "";
+ }
+
</script>
<body onload="setup(pageManager)">
<div id="header"><h1>Tab Closer Settings</h1></div>
<div id="content">
<div id="help">
<h2>Help</h2>
- When you click on the garbage can icon the extension will close all of your open pages that match one of the URL matchers on the left.
- <br>
- <br>
- I am just using the tab api directly at the moment so your matchers must have to have the following form:
+ <div id="switcher">
+ <div id="test" style="display:none">
+ test
+ </div>
+ <div id="matcher-help">
+ When you click on the garbage can icon the extension will close all of your open pages that match one of the URL matchers on the left.
+ <br>
+ <br>
+ I am just using the tab api directly at the moment so your matchers must have to have the following form:
<pre>PROTOCOL://HOST/PATH</pre>
- Where PROTOCOL can be any of:
- <ul>
- <li>*</li>
- <li>http</li>
- <li>https</li>
- <li>file</li>
- <li>ftp</li>
- </ul>
+ Where PROTOCOL can be any of:
+ <ul>
+ <li>*</l>
+ <li>http</li>
+ <li>https</li>
+ <li>file</li>
+ <li>ftp</li>
+ </ul>
- The * is a wildcard and it will match any of the other options.
- <br>
- <br>
- HOST is any valid address. You can use a *. at the begining only to match anything string to the left of the period.
- <br>
- <br>
- PATH can be any string with wildcards anywhere within it.
- <br>
- <br>
- You can check out <a href="http://code.google.com/chrome/extensions/match_patterns.html">Google's page</a> on the topic for examples or a more thorough description.
+ The * is a wildcard and it will match any of the other options.
+ <br>
+ <br>
+ HOST is any valid address. You can use a *. at the begining only to match anything string to the left of the period.
+ <br>
+ <br>
+ PATH can be any string with wildcards anywhere within it.
+ <br>
+ <br>
+ You can check out <a href="http://code.google.com/chrome/extensions/match_patterns.html">Google's page</a> on the topic for examples or a more thorough description.
+ </div>
+ </div>
</div>
<div id="settings">
<div id="notifications"></div>
<h2>Settings:</h2>
<input type="checkbox" id="windowSetting" name="windowSetting" value="onlyThis"> Close tabs only in current window.<br>
- <input type="checkbox" id="regexSetting" name="regexSetting" value="onlyThis"> Use slower regex matching.<br>
<h2>Matchers:</h2>
<div id="matchers">
</div>
View
@@ -1,6 +1,6 @@
function init(){
if (!localStorage["init"]) {
- localStorage["matchers"] = "[]";
+ localStorage["matchers"] = '[{"string":"*://www.google.com/*","_regex":false},{"string":"*://www.google.ca/*","_regex":false}]';
localStorage["window-setting"] = "false";
localStorage["init"] = "true";
}

0 comments on commit 90958f8

Please sign in to comment.