Skip to content

Commit ebd85dc

Browse files
committed
Added options page with case sensitivity option
1 parent 770843c commit ebd85dc

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

Gruntfile.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module.exports = function(grunt) {
22
"use strict";
3-
3+
44
var bgSrc = ["src/background/*.ts"];
55
var popupSrc = ["src/popup/*.ts"];
6-
6+
var optionSrc = ["src/options/*.ts"];
7+
78
grunt.initConfig({
89
ts: {
910
options: {
@@ -17,14 +18,18 @@ module.exports = function(grunt) {
1718
popup: {
1819
src: popupSrc,
1920
out: "build/popup/popup.js"
20-
}
21+
},
22+
option: {
23+
src: optionSrc,
24+
out: "build/options/options.js"
25+
}
2126
},
2227
copy: {
2328
all: {
2429
files: [
2530
{
2631
expand: true,
27-
src: ["manifest.json", "content/*", "pages/*", "popup/popup.html"],
32+
src: ["manifest.json", "content/*", "pages/*", "popup/popup.html", "options/options.html"],
2833
cwd: "src/",
2934
dest: "build/"
3035
},
@@ -37,8 +42,8 @@ module.exports = function(grunt) {
3742
}
3843
}
3944
});
40-
45+
4146
grunt.loadNpmTasks("grunt-ts");
4247
grunt.loadNpmTasks("grunt-contrib-copy");
4348
grunt.registerTask("default", ["ts", "copy"]);
44-
};
49+
};

src/background/TabStateManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class TabStateManager {
1212
}
1313

1414
public resetState(tabId: number) {
15-
this.set(tabId, { query: "", searching: false, caseInsensitive: false });
15+
var caseInsensitiveVal = localStorage["caseInsensitive"] == "true";
16+
this.set(tabId, { query: "", searching: false, caseInsensitive: caseInsensitiveVal });
1617
}
1718

1819
public isSearching(tabId: number): boolean {
@@ -36,6 +37,7 @@ class TabStateManager {
3637
public get(tabId: number, propName: string): any;
3738
public get(tabId: number, propName?: string) {
3839
if (typeof propName === "undefined") {
40+
return this.tabStates[tabId];
3941
} else {
4042
return this.tabStates[tabId][propName];
4143
}

src/manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"scripts": ["background/background.js"]
2121
},
2222

23+
"options_page": "options/options.html",
24+
2325
"browser_action": {
2426
"default_icon": {
2527
"19": "images/icon19.png",

src/options/options.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<head>
3+
<title>Regex Search Options</title>
4+
</head>
5+
<body>
6+
<h1>Regex Search Options</h1>
7+
Case insensitive by default: <input id="case-insensitive" type="checkbox">
8+
<br><br>
9+
<div id="status" style="font-weight: bold"></div>
10+
</body>
11+
<script src="options.js"></script>
12+
</html>

src/options/options.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Options {
2+
3+
var caseInsensitiveKey = "caseInsensitive";
4+
var checkbox = <HTMLInputElement> document.getElementById("case-insensitive");
5+
restoreState();
6+
checkbox.onclick = saveState;
7+
8+
function restoreState() {
9+
if (localStorage[caseInsensitiveKey] !== undefined) {
10+
checkbox.checked = localStorage[caseInsensitiveKey] == "true";
11+
}
12+
}
13+
14+
function saveState() {
15+
if (checkbox.checked) {
16+
localStorage[caseInsensitiveKey] = true;
17+
} else {
18+
localStorage[caseInsensitiveKey] = false;
19+
}
20+
21+
// Display saved message
22+
var status = document.getElementById("status");
23+
status.innerHTML = "Options Saved.";
24+
setTimeout(function() {
25+
status.innerHTML = "";
26+
}, 1000);
27+
}
28+
}
29+

0 commit comments

Comments
 (0)