Integrated Fancy Settings and got Fresh Content working

This commit is contained in:
Kerrick Long
2011-06-22 15:37:45 -05:00
parent d0a80df64d
commit 1ac9fd67e4
22 changed files with 7565 additions and 47 deletions
+1
View File
@@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<title>Background Processes</title>
<script src="fancy-settings/lib/store.js" type="text/javascript"></script>
<script src="background.js" type="text/javascript"></script>
</head>
<body>
+29 -29
View File
@@ -1,6 +1,8 @@
var db = openDatabase('mhdb', '1.0', 'Mostly Harmless Database', 5 * 1024 * 1024);
var cacheTime;
var over18;
var settings = new Store("settings", {
"cacheTime": 1,
"freshCutoff": 90
}).toObject();
var commentsMatchPattern = /https?:\/\/www\.reddit\.com(\/r\/(.+?))?\/comments\/(.+?)\/.*/;
init();
@@ -11,14 +13,6 @@ function init() {
installDefaults();
}
db.transaction(function(tx){
// Load preferences
tx.executeSql('SELECT * FROM prefs WHERE pref=?', ['cacheTime'], function(tx, results) {
cacheTime = results.rows.item(0).choice;
});
tx.executeSql('SELECT * FROM prefs WHERE pref=?', ['over18'], function(tx, results) {
over18 = results.rows.item(0).choice;
});
// Clear cache and post data
tx.executeSql('DELETE FROM cache');
tx.executeSql('DELETE FROM posts');
@@ -28,11 +22,8 @@ function init() {
function installDefaults(tx) {
window.localStorage.setItem('installed','true');
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS cache (pageUrl unique, cacheTime, howManyPosts)');
tx.executeSql('CREATE TABLE IF NOT EXISTS cache (pageUrl unique, cacheDate, howManyPosts)');
tx.executeSql('CREATE TABLE IF NOT EXISTS posts (id unique, name, likes, domain, subreddit, author, score, over_18, hidden, thumbnail, downs, permalink, created_utc, url, title, num_comments, ups, modhash)')
tx.executeSql('CREATE TABLE IF NOT EXISTS prefs (pref unique, choice)');
tx.executeSql('INSERT INTO prefs (pref, choice) VALUES (?, ?)', ['cacheTime','1']);
tx.executeSql('INSERT INTO prefs (pref, choice) VALUES (?, ?)', ['over18','false']);
});
}
@@ -77,7 +68,7 @@ function grabData(url,tabId) {
tx.executeSql('SELECT * FROM cache WHERE pageUrl=?', [url], function(tx, results) {
var cache = results.rows;
var isCommentsPage = commentsMatchPattern.test(url);
if(cache.length === 0 || -(cache.item(0).cacheTime - epoch()) > 60 * cacheTime ) { // cacheTime in minutes
if(cache.length === 0 || -(cache.item(0).cacheDate - epoch()) > 60 * settings.cacheTime ) {
console.log('Loading from reddit api...');
var reqUrl = new String();
if(isCommentsPage) {
@@ -108,28 +99,37 @@ function epoch() {
}
function cacheData(response,pageUrl,tabId,isCommentsPage) {
// add response to cache to reduce API calls
if(response.data.children.length === 0) {
var wasCached = false;
var freshPosts = [];
for(var i = 0; i < response.data.children.length; i++) {
var data = response.data.children[i].data;
var isFreshEnough = data.created_utc >= epoch() - settings.freshCutoff * 24 * 60 * 60;
if(isFreshEnough) {
wasCached = true;
freshPosts.push(data);
}
}
if(wasCached === true) {
db.transaction(function(tx) {
tx.executeSql('INSERT OR REPLACE INTO cache (pageUrl, cacheTime, howManyPosts) VALUES (?, ?, ?)',[pageUrl, epoch(), '0',]);
});
} else {
db.transaction(function(tx) {
for(var i = 0; i < response.data.children.length; i++) {
var data = response.data.children[i].data;
var insertUrl = isCommentsPage ? 'http://www.reddit.com' + data.permalink : data.url;
var insertNum = isCommentsPage ? '...' : response.data.children.length;
var insertNum = isCommentsPage ? '...' : freshPosts.length;
tx.executeSql('INSERT OR REPLACE INTO cache (pageUrl, cacheDate, howManyPosts) VALUES (?, ?, ?)',[pageUrl, epoch(), freshPosts.length]);
for(var j = freshPosts.length - 1; j >= 0; j--) {
var insertUrl = isCommentsPage ? 'http://www.reddit.com' + freshPosts[j].permalink : freshPosts[j].url.split('#')[0];
tx.executeSql(
'INSERT OR REPLACE INTO posts' +
'(id, name, likes, domain, subreddit, author, score, over_18, hidden, thumbnail, downs, permalink, created_utc, url, title, num_comments, ups, modhash)' +
'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[data.id, data.name, data.likes, data.domain, data.subreddit, data.author, data.score, data.over_18, data.hidden, data.thumbnail, data.downs, data.permalink, data.created_utc, insertUrl, data.title, data.num_comments, data.ups, response.data.modhash],
function(tx) {
tx.executeSql('INSERT OR REPLACE INTO cache (pageUrl, cacheTime, howManyPosts) VALUES (?, ?, ?)',[pageUrl, epoch(), insertNum]);
});
[freshPosts[j].id, freshPosts[j].name, freshPosts[j].likes, freshPosts[j].domain, freshPosts[j].subreddit, freshPosts[j].author, freshPosts[j].score, freshPosts[j].over_18, freshPosts[j].hidden, freshPosts[j].thumbnail, freshPosts[j].downs, freshPosts[j].permalink, freshPosts[j].created_utc, insertUrl, freshPosts[j].title, freshPosts[j].num_comments, freshPosts[j].ups, response.data.modhash]
);
}
});
} else {
db.transaction(function(tx) {
tx.executeSql('INSERT OR REPLACE INTO cache (pageUrl, cacheDate, howManyPosts) VALUES (?, ?, ?)',[pageUrl, epoch(), '0',]);
});
}
console.log(freshPosts);
preparePopup(pageUrl,tabId);
}
+132
View File
@@ -0,0 +1,132 @@
/*
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/fancy-settings
// License: LGPL v2.1
*/
.fancy {
text-shadow: #F5F5F5 0 1px 0;
}
#sidebar {
position: absolute;
background-color: #EDEDED;
background-image: linear-gradient(top, #EDEDED, #F5F5F5);
background-image: -webkit-gradient(
linear,
left top,
left 500,
color-stop(0, #EDEDED),
color-stop(1, #F5F5F5)
);
background-image: -moz-linear-gradient(
center top,
#EDEDED 0%,
#F5F5F5 100%
);
background-image: -o-linear-gradient(top, #EDEDED, #F5F5F5);
width: 219px;
top: 0;
left: 0;
bottom: 0;
border-right: 1px solid #C2C2C2;
box-shadow: inset -8px 0 30px -30px black;
}
#icon {
position: absolute;
width: 30px;
height: 30px;
top: 12px;
left: 12px;
}
#sidebar h1 {
position: absolute;
top: 13px;
right: 25px;
font-size: 26px;
color: #707070;
}
#tab-container {
position: absolute;
top: 50px;
left: 0;
right: 0;
bottom: 0;
overflow-y: auto;
overflow-x: hidden;
text-align: right;
}
#tab-container .tab {
height: 28px;
padding-right: 25px;
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
font-size: 12px;
line-height: 28px;
color: #808080;
cursor: pointer;
}
#search-container {
margin-top: 5px;
margin-bottom: 5px;
padding-right: 23px !important;
cursor: default !important;
}
#search-container input {
width: 130px;
}
#tab-container .tab.active, body.searching #search-container {
background-color: #D4D4D4;
border-color: #BFBFBF;
color: black;
text-shadow: #DBDBDB 0 1px 0;
box-shadow: inset -12px 0 30px -30px black;
}
body.searching #tab-container .tab.active {
background-color: transparent;
border-color: transparent;
color: #808080;
text-shadow: inherit;
box-shadow: none;
}
#content {
position: absolute;
top: 0;
left: 220px;
right: 0;
bottom: 0;
overflow: auto;
}
.tab-content {
display: none;
position: absolute;
width: 840px;
top: 0;
left: 0;
bottom: 0;
padding: 20px;
padding-top: 15px;
}
body.searching .tab-content {
display: none !important;
}
body.searching #search-result-container {
display: block !important;
}
body.measuring .tab-content, body.measuring #search-result-container {
display: block !important;
opacity: 0;
overflow: hidden;
}
+81
View File
@@ -0,0 +1,81 @@
/*
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/fancy-settings
// License: LGPL v2.1
*/
.tab-content h2 {
margin: 0;
padding-bottom: 5px;
font-size: 26px;
color: #707070;
line-height: 1;
}
.setting.group {
border-top: 1px solid #EEEEEE;
margin-top: 10px;
padding-top: 5px;
padding-left: 2px;
}
.setting.group-name {
width: 140px;
padding: 0;
font-size: 14px;
font-weight: bold;
vertical-align: top;
}
.setting.bundle {
max-width: 600px;
margin-bottom: 5px;
}
.setting.bundle.list-box {
margin-bottom: 10px;
}
.setting.label.radio-buttons + .setting.container.radio-buttons {
margin-top: 3px;
}
.setting.label, .setting.element-label {
margin-right: 15px;
font-size: 13px;
font-weight: normal;
}
.setting.label.checkbox, .setting.element-label {
margin-left: 5px;
margin-right: 0;
}
.setting.label.checkbox {
position: relative;
top: 1px;
}
.setting.element.slider {
position: relative;
width: 150px;
top: 4px;
}
.setting.element.list-box {
display: block;
height: 100px;
width: 100%;
}
.setting.display.slider {
margin-left: 5px;
color: #666666;
}
#nothing-found {
display: none;
margin-top: 10px;
font-size: 18px;
font-weight: lighter;
color: #999999;
}
+13
View File
@@ -0,0 +1,13 @@
/*
// Add your own style rules here, not in css/main.css
// or css/setting.css for easy updating reasons.
*/
#icon {
width: 19px;
height: 19px;
top: 15px;
left: 17px;
}
textarea {
font-family: Consolas, "Lucida Console", Monaco, monospace
}
+71
View File
@@ -0,0 +1,71 @@
// SAMPLE
this.i18n = {
"settings": {
"en": "Settings",
"de": "Optionen"
},
"search": {
"en": "Search",
"de": "Suche"
},
"nothing-found": {
"en": "No matches were found.",
"de": "Keine Übereinstimmungen gefunden."
},
"information": {
"en": "Information",
"de": "Information"
},
"login": {
"en": "Login",
"de": "Anmeldung"
},
"username": {
"en": "Username:",
"de": "Benutzername:"
},
"password": {
"en": "Password:",
"de": "Passwort:"
},
"x-characters": {
"en": "6 - 12 characters",
"de": "6 - 12 Zeichen"
},
"x-characters-pw": {
"en": "10 - 18 characters",
"de": "10 - 18 Zeichen"
},
"description": {
"en": "This is a description. You can write any text inside of this.<br>\
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut\
labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores\
et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem\
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et\
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.\
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
"de": "Das ist eine Beschreibung. Du kannst hier beliebigen Text einfügen.<br>\
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut\
labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores\
et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem\
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et\
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.\
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
},
"logout": {
"en": "Logout",
"de": "Abmeldung"
},
"enable": {
"en": "Enable",
"de": "Aktivieren"
},
"disconnect": {
"en": "Disconnect:",
"de": "Trennen:"
}
};
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

+46
View File
@@ -0,0 +1,46 @@
<!--
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/fancy-settings
// License: LGPL v2.1
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title id="title"></title>
<!-- Stylesheets -->
<link id="favicon" rel="icon" href="">
<link rel="stylesheet" href="lib/default.css" media="screen">
<link rel="stylesheet" href="css/main.css" media="screen">
<link rel="stylesheet" href="css/setting.css" media="screen">
<link rel="stylesheet" href="custom.css" media="screen">
<!-- JavaScripts -->
<script src="lib/mootools-core.js"></script>
<script src="lib/store.js"></script>
<script src="js/classes/tab.js"></script>
<script src="js/classes/setting.js"></script>
<script src="js/classes/search.js"></script>
<script src="js/classes/fancy-settings.js"></script>
<script src="i18n.js"></script>
<script src="js/i18n.js"></script>
<script src="manifest.js"></script>
<script src="settings.js"></script>
</head>
<body class="no-select">
<div id="sidebar" class="fancy">
<img id="icon" src="" alt=""><h1 id="settings-label"></h1>
<div id="tab-container">
<div id="search-container" class="tab">
<input id="search" type="search" placeholder="">
</div>
</div>
</div>
<div id="content">
<div id="search-result-container" class="tab-content">
<h2 id="search-label"></h2>
</div>
</div>
</body>
</html>
+152
View File
@@ -0,0 +1,152 @@
//
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/fancy-settings
// License: LGPL v2.1
//
(function () {
var FancySettings = this.FancySettings = new Class({
"tabs": {},
"initialize": function (name, icon) {
// Set title and icon
$("title").set("text", name);
$("favicon").set("href", icon);
$("icon").set("src", icon);
$("settings-label").set("text", (i18n.get("settings") || "Settings"));
$("search-label").set("text", (i18n.get("search") || "Search"));
$("search").set("placeholder", (i18n.get("search") || "Search") + "...");
this.tab = new Tab($("tab-container"), $("content"));
this.search = new Search($("search"), $("search-result-container"));
},
"create": function (params) {
var tab,
group,
row,
content,
bundle;
// Create tab if it doesn't exist already
if (this.tabs[params.tab] === undefined) {
this.tabs[params.tab] = {"groups":{}};
tab = this.tabs[params.tab];
tab.content = this.tab.create();
tab.content.tab.set("text", params.tab);
this.search.bind(tab.content.tab);
tab.content = tab.content.content;
(new Element("h2", {
"text": params.tab
})).inject(tab.content);
} else {
tab = this.tabs[params.tab];
}
// Create group if it doesn't exist already
if (tab.groups[params.group] === undefined) {
tab.groups[params.group] = {};
group = tab.groups[params.group];
group.content = (new Element("table", {
"class": "setting group"
})).inject(tab.content);
row = (new Element("tr")).inject(group.content);
(new Element("td", {
"class": "setting group-name",
"text": params.group
})).inject(row);
content = (new Element("td", {
"class": "setting group-content"
})).inject(row);
group.setting = new Setting(content);
} else {
group = tab.groups[params.group];
}
// Create and index the setting
bundle = group.setting.create(params);
this.search.add(bundle);
return bundle;
},
"align": function (settings) {
var types,
type,
maxWidth;
types = [
"text",
"button",
"slider",
"popupButton"
];
type = settings[0].params.type;
maxWidth = 0;
if (!types.contains(type)) {
throw "invalidType";
}
settings.each(function (setting) {
if (setting.params.type !== type) {
throw "multipleTypes";
}
var width = setting.label.offsetWidth;
if (width > maxWidth) {
maxWidth = width;
}
});
settings.each(function (setting) {
var width = setting.label.offsetWidth;
if (width < maxWidth) {
if (type === "button" || type === "slider") {
setting.element.setStyle("margin-left", (maxWidth - width + 2) + "px");
setting.search.element.setStyle("margin-left", (maxWidth - width + 2) + "px");
} else {
setting.element.setStyle("margin-left", (maxWidth - width) + "px");
setting.search.element.setStyle("margin-left", (maxWidth - width) + "px");
}
}
});
}
});
FancySettings.__proto__.initWithManifest = function (callback) {
var settings,
output;
settings = new FancySettings(manifest.name, manifest.icon);
settings.manifest = {};
manifest.settings.each(function (params) {
output = settings.create(params);
if (params.name !== undefined) {
settings.manifest[params.name] = output;
}
});
if (manifest.alignment !== undefined) {
document.body.addClass("measuring");
manifest.alignment.each(function (group) {
group = group.map(function (name) {
return settings.manifest[name];
});
settings.align(group);
});
document.body.removeClass("measuring");
}
if (callback !== undefined) {
callback(settings);
}
};
}());
+126
View File
@@ -0,0 +1,126 @@
//
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/fancy-settings
// License: LGPL v2.1
//
(function () {
this.Search = new Class({
"index": [],
"groups": {},
"initialize": function (search, searchResultContainer) {
var setting,
find;
this.search = search;
this.searchResultContainer = searchResultContainer;
this.setting = new Setting(new Element("div"));
// Create setting for message "nothing found"
setting = new Setting(this.searchResultContainer);
this.nothingFound = setting.create({
"type": "description",
"text": (i18n.get("nothing-found") || "No matches were found.")
});
this.nothingFound.bundle.set("id", "nothing-found");
// Create event handlers
find = (function (event) {
this.find(event.target.get("value"));
}).bind(this);
this.search.addEvent("keyup", (function (event) {
if (event.key === "esc") {
this.reset();
} else {
find(event);
}
}).bind(this));
this.search.addEventListener("search", find, false);
},
"bind": function (tab) {
tab.addEvent("click", this.reset.bind(this));
},
"add": function (setting) {
var searchSetting = this.setting.create(setting.params);
setting.search = searchSetting;
searchSetting.original = setting;
this.index.push(searchSetting);
setting.addEvent("action", function (value, stopPropagation) {
if (searchSetting.set !== undefined && stopPropagation !== true) {
searchSetting.set(value, true);
}
});
searchSetting.addEvent("action", function (value) {
if (setting.set !== undefined) {
setting.set(value, true);
}
setting.fireEvent("action", [value, true]);
});
},
"find": function (searchString) {
// Exit search mode
if (searchString.trim() === "") {
document.body.removeClass("searching");
return;
}
// Or enter search mode
this.index.each(function (setting) { setting.bundle.dispose(); });
Object.each(this.groups, function (group) { group.dispose(); });
document.body.addClass("searching");
// Filter settings
var result = this.index.filter(function (setting) {
if (setting.params.searchString.contains(searchString.trim().toLowerCase())) {
return true;
}
});
// Display settings
result.each((function (setting) {
var group,
row;
// Create group if it doesn't exist already
if (this.groups[setting.params.group] === undefined) {
this.groups[setting.params.group] = (new Element("table", {
"class": "setting group"
})).inject(this.searchResultContainer);
group = this.groups[setting.params.group];
row = (new Element("tr")).inject(group);
(new Element("td", {
"class": "setting group-name",
"text": setting.params.group
})).inject(row);
group.content = (new Element("td", {
"class": "setting group-content"
})).inject(row);
} else {
group = this.groups[setting.params.group].inject(this.searchResultContainer);
}
setting.bundle.inject(group.content);
}).bind(this));
if (result.length === 0) {
this.nothingFound.bundle.addClass("show");
} else {
this.nothingFound.bundle.removeClass("show");
}
},
"reset": function () {
this.search.set("value", "");
this.search.blur();
this.find("");
}
});
}());
+593
View File
@@ -0,0 +1,593 @@
//
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/fancy-settings
// License: LGPL v2.1
//
(function () {
var settings,
Bundle;
settings = new Store("settings");
Bundle = new Class({
// Attributes:
// - tab
// - group
// - name
// - type
//
// Methods:
// - initialize
// - createDOM
// - setupDOM
// - addEvents
// - get
// - set
"Implements": Events,
"initialize": function (params) {
this.params = params;
this.params.searchString = "•" + this.params.tab + "•" + this.params.group + "•";
this.createDOM();
this.setupDOM();
this.addEvents();
if (this.params.name !== undefined) {
this.set(settings.get(this.params.name), true);
}
this.params.searchString = this.params.searchString.toLowerCase();
},
"addEvents": function () {
this.element.addEvent("change", (function (event) {
if (this.params.name !== undefined) {
settings.set(this.params.name, this.get());
}
this.fireEvent("action", this.get());
}).bind(this));
},
"get": function () {
return this.element.get("value");
},
"set": function (value, noChangeEvent) {
this.element.set("value", value);
if (noChangeEvent !== true) {
this.element.fireEvent("change");
}
return this;
}
});
Bundle.Description = new Class({
// text
"Extends": Bundle,
"addEvents": undefined,
"get": undefined,
"set": undefined,
"initialize": function (params) {
this.params = params;
this.params.searchString = "";
this.createDOM();
this.setupDOM();
},
"createDOM": function () {
this.bundle = new Element("div", {
"class": "setting bundle description"
});
this.container = new Element("div", {
"class": "setting container description"
});
this.element = new Element("p", {
"class": "setting element description"
});
},
"setupDOM": function () {
if (this.params.text !== undefined) {
this.element.set("html", this.params.text);
}
this.element.inject(this.container);
this.container.inject(this.bundle);
}
});
Bundle.Button = new Class({
// label, text
// action -> click
"Extends": Bundle,
"get": undefined,
"set": undefined,
"initialize": function (params) {
this.params = params;
this.params.searchString = "•" + this.params.tab + "•" + this.params.group + "•";
this.createDOM();
this.setupDOM();
this.addEvents();
this.params.searchString = this.params.searchString.toLowerCase();
},
"createDOM": function () {
this.bundle = new Element("div", {
"class": "setting bundle button"
});
this.container = new Element("div", {
"class": "setting container button"
});
this.element = new Element("input", {
"class": "setting element button",
"type": "button"
});
this.label = new Element("label", {
"class": "setting label button"
});
},
"setupDOM": function () {
if (this.params.label !== undefined) {
this.label.set("html", this.params.label);
this.label.inject(this.container);
this.params.searchString += this.params.label + "•";
}
if (this.params.text !== undefined) {
this.element.set("value", this.params.text);
this.params.searchString += this.params.text + "•";
}
this.element.inject(this.container);
this.container.inject(this.bundle);
},
"addEvents": function () {
this.element.addEvent("click", (function () {
this.fireEvent("action");
}).bind(this));
}
});
Bundle.Text = new Class({
// label, text, masked
// action -> change & keyup
"Extends": Bundle,
"createDOM": function () {
this.bundle = new Element("div", {
"class": "setting bundle text"
});
this.container = new Element("div", {
"class": "setting container text"
});
this.element = new Element("input", {
"class": "setting element text",
"type": "text"
});
this.label = new Element("label", {
"class": "setting label text"
});
},
"setupDOM": function () {
if (this.params.label !== undefined) {
this.label.set("html", this.params.label);
this.label.inject(this.container);
this.params.searchString += this.params.label + "•";
}
if (this.params.text !== undefined) {
this.element.set("placeholder", this.params.text);
this.params.searchString += this.params.text + "•";
}
if (this.params.masked === true) {
this.element.set("type", "password");
this.params.searchString += "password" + "•";
}
this.element.inject(this.container);
this.container.inject(this.bundle);
},
"addEvents": function () {
var change = (function (event) {
if (this.params.name !== undefined) {
settings.set(this.params.name, this.get());
}
this.fireEvent("action", this.get());
}).bind(this);
this.element.addEvent("change", change);
this.element.addEvent("keyup", change);
}
});
Bundle.Checkbox = new Class({
// label
// action -> change
"Extends": Bundle,
"createDOM": function () {
this.bundle = new Element("div", {
"class": "setting bundle checkbox"
});
this.container = new Element("div", {
"class": "setting container checkbox"
});
this.element = new Element("input", {
"id": String.uniqueID(),
"class": "setting element checkbox",
"type": "checkbox",
"value": "true"
});
this.label = new Element("label", {
"class": "setting label checkbox",
"for": this.element.get("id")
});
},
"setupDOM": function () {
this.element.inject(this.container);
this.container.inject(this.bundle);
if (this.params.label !== undefined) {
this.label.set("html", this.params.label);
this.label.inject(this.container);
this.params.searchString += this.params.label + "•";
}
},
"get": function () {
return this.element.get("checked");
},
"set": function (value, noChangeEvent) {
this.element.set("checked", value);
if (noChangeEvent !== true) {
this.element.fireEvent("change");
}
return this;
}
});
Bundle.Slider = new Class({
// label, max, min, step, display, displayModifier
// action -> change
"Extends": Bundle,
"initialize": function (params) {
this.params = params;
this.params.searchString = "•" + this.params.tab + "•" + this.params.group + "•";
this.createDOM();
this.setupDOM();
this.addEvents();
if (this.params.name !== undefined) {
this.set((settings.get(this.params.name) || 0), true);
} else {
this.set(0, true);
}
this.params.searchString = this.params.searchString.toLowerCase();
},
"createDOM": function () {
this.bundle = new Element("div", {
"class": "setting bundle slider"
});
this.container = new Element("div", {
"class": "setting container slider"
});
this.element = new Element("input", {
"class": "setting element slider",
"type": "range"
});
this.label = new Element("label", {
"class": "setting label slider"
});
this.display = new Element("span", {
"class": "setting display slider"
});
},
"setupDOM": function () {
if (this.params.label !== undefined) {
this.label.set("html", this.params.label);
this.label.inject(this.container);
this.params.searchString += this.params.label + "•";
}
if (this.params.max !== undefined) {
this.element.set("max", this.params.max);
}
if (this.params.min !== undefined) {
this.element.set("min", this.params.min);
}
if (this.params.step !== undefined) {
this.element.set("step", this.params.step);
}
this.element.inject(this.container);
if (this.params.display === true) {
if (this.params.displayModifier !== undefined) {
this.display.set("text", this.params.displayModifier(0));
} else {
this.display.set("text", 0);
}
this.display.inject(this.container);
}
this.container.inject(this.bundle);
},
"addEvents": function () {
this.element.addEvent("change", (function (event) {
if (this.params.name !== undefined) {
settings.set(this.params.name, this.get());
}
if (this.params.displayModifier !== undefined) {
this.display.set("text", this.params.displayModifier(this.get()));
} else {
this.display.set("text", this.get());
}
this.fireEvent("action", this.get());
}).bind(this));
},
"get": function () {
return Number.from(this.element.get("value"));
},
"set": function (value, noChangeEvent) {
this.element.set("value", value);
if (noChangeEvent !== true) {
this.element.fireEvent("change");
} else {
if (this.params.displayModifier !== undefined) {
this.display.set("text", this.params.displayModifier(Number.from(value)));
} else {
this.display.set("text", Number.from(value));
}
}
return this;
}
});
Bundle.PopupButton = new Class({
// label, options[{value, text}]
// action -> change
"Extends": Bundle,
"createDOM": function () {
this.bundle = new Element("div", {
"class": "setting bundle popup-button"
});
this.container = new Element("div", {
"class": "setting container popup-button"
});
this.element = new Element("select", {
"class": "setting element popup-button"
});
this.label = new Element("label", {
"class": "setting label popup-button"
});
if (this.params.options === undefined) { return; }
this.params.options.each((function (option) {
this.params.searchString += (option[1] || option[0]) + "•";
(new Element("option", {
"value": option[0],
"text": option[1] || option[0]
})).inject(this.element);
}).bind(this));
},
"setupDOM": function () {
if (this.params.label !== undefined) {
this.label.set("html", this.params.label);
this.label.inject(this.container);
this.params.searchString += this.params.label + "•";
}
this.element.inject(this.container);
this.container.inject(this.bundle);
}
});
Bundle.ListBox = new Class({
// label, options[{value, text}]
// action -> change
"Extends": Bundle.PopupButton,
"createDOM": function () {
this.bundle = new Element("div", {
"class": "setting bundle list-box"
});
this.container = new Element("div", {
"class": "setting container list-box"
});
this.element = new Element("select", {
"class": "setting element list-box",
"size": "2"
});
this.label = new Element("label", {
"class": "setting label list-box"
});
if (this.params.options === undefined) { return; }
this.params.options.each((function (option) {
this.params.searchString += (option[1] || option[0]) + "•";
(new Element("option", {
"value": option[0],
"text": option[1] || option[0]
})).inject(this.element);
}).bind(this));
},
"get": function () {
return (this.element.get("value") || undefined);
}
});
Bundle.RadioButtons = new Class({
// label, options[{value, text}]
// action -> change
"Extends": Bundle,
"createDOM": function () {
var settingID = String.uniqueID();
this.bundle = new Element("div", {
"class": "setting bundle radio-buttons"
});
this.label = new Element("label", {
"class": "setting label radio-buttons"
});
this.containers = [];
this.elements = [];
this.labels = [];
if (this.params.options === undefined) { return; }
this.params.options.each((function (option) {
var optionID,
container;
this.params.searchString += (option[1] || option[0]) + "•";
optionID = String.uniqueID();
container = (new Element("div", {
"class": "setting container radio-buttons"
})).inject(this.bundle);
this.containers.push(container);
this.elements.push((new Element("input", {
"id": optionID,
"name": settingID,
"class": "setting element radio-buttons",
"type": "radio",
"value": option[0]
})).inject(container));
this.labels.push((new Element("label", {
"class": "setting element-label radio-buttons",
"for": optionID,
"text": option[1] || option[0]
})).inject(container));
}).bind(this));
},
"setupDOM": function () {
if (this.params.label !== undefined) {
this.label.set("html", this.params.label);
this.label.inject(this.bundle, "top");
this.params.searchString += this.params.label + "•";
}
},
"addEvents": function () {
this.bundle.addEvent("change", (function (event) {
if (this.params.name !== undefined) {
settings.set(this.params.name, this.get());
}
this.fireEvent("action", this.get());
}).bind(this));
},
"get": function () {
var checkedEl = this.elements.filter((function (el) {
return el.get("checked");
}).bind(this));
return (checkedEl[0] && checkedEl[0].get("value"));
},
"set": function (value, noChangeEvent) {
var desiredEl = this.elements.filter((function (el) {
return (el.get("value") === value);
}).bind(this));
desiredEl[0] && desiredEl[0].set("checked", true);
if (noChangeEvent !== true) {
this.bundle.fireEvent("change");
}
return this;
}
});
this.Setting = new Class({
"initialize": function (container) {
this.container = container;
},
"create": function (params) {
var types,
bundle;
// Available types
types = {
"description": "Description",
"button": "Button",
"text": "Text",
"checkbox": "Checkbox",
"slider": "Slider",
"popupButton": "PopupButton",
"listBox": "ListBox",
"radioButtons": "RadioButtons"
};
if (types.hasOwnProperty(params.type)) {
bundle = new Bundle[types[params.type]](params);
bundle.bundleContainer = this.container;
bundle.bundle.inject(this.container);
return bundle;
} else {
throw "invalidType";
}
}
});
}());
+51
View File
@@ -0,0 +1,51 @@
//
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/fancy-settings
// License: LGPL v2.1
//
(function () {
var Bundle = new Class({
"initialize": function (creator) {
this.creator = creator;
// Create DOM elements
this.tab = new Element("div", {"class": "tab"});
this.content = new Element("div", {"class": "tab-content"});
// Create event handlers
this.tab.addEvent("click", this.activate.bind(this));
},
"activate": function () {
if (this.creator.activeBundle && this.creator.activeBundle !== this) {
this.creator.activeBundle.deactivate();
}
this.tab.addClass("active");
this.content.addClass("show");
this.creator.activeBundle = this;
},
"deactivate": function () {
this.tab.removeClass("active");
this.content.removeClass("show");
this.creator.activeBundle = null;
}
});
this.Tab = new Class({
"activeBundle": null,
"initialize": function (tabContainer, tabContentContainer) {
this.tabContainer = tabContainer;
this.tabContentContainer = tabContentContainer;
},
"create": function () {
var bundle = new Bundle(this);
bundle.tab.inject(this.tabContainer);
bundle.content.inject(this.tabContentContainer);
if (!this.activeBundle) { bundle.activate(); }
return bundle;
}
});
}());
+27
View File
@@ -0,0 +1,27 @@
//
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/fancy-settings
// License: LGPL v2.1
//
(function () {
var lang = navigator.language.split("-")[0];
if (this.i18n === undefined) { this.i18n = {}; }
this.i18n.get = function (value) {
if (value === "lang") {
return lang;
}
if (this.hasOwnProperty(value)) {
value = this[value];
if (value.hasOwnProperty(lang)) {
return value[lang];
} else if (value.hasOwnProperty("en")) {
return value["en"];
} else {
return Object.values(value)[0];
}
} else {
return value;
}
};
}());
+467
View File
@@ -0,0 +1,467 @@
/*
// Copyright (c) 2007 - 2010 blueprintcss.org
// Modified and extended by Frank Kohlhepp in 2011
// https://github.com/frankkohlhepp/default-css
// License: MIT-license
*/
/*
// Reset the default browser CSS
*/
html {
margin: 0;
padding: 0;
border: 0;
}
body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, code,
del, dfn, em, img, q, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, dialog, figure, footer, header,
hgroup, nav, section {
margin: 0;
padding: 0;
border: 0;
font-family: inherit;
font-size: 100%;
font-weight: inherit;
font-style: inherit;
vertical-align: baseline;
}
article, aside, dialog, figure, footer, header,
hgroup, nav, section {
display: block;
}
body {
background-color: white;
line-height: 1.5;
}
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
table, th, td {
vertical-align: middle;
}
blockquote:before, blockquote:after, q:before, q:after {
content: "";
}
blockquote, q {
quotes: "" "";
}
a img {
border: none;
}
/*
// Default typography
*/
html {
font-size: 100.01%;
}
body {
background-color: white;
font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
font-size: 75%;
color: #222222;
}
/* Headings */
h1, h2, h3, h4, h5, h6 {
font-weight: normal;
color: #111111;
}
h1 {
margin-bottom: 0.5em;
font-size: 3em;
line-height: 1;
}
h2 {
margin-bottom: 0.75em;
font-size: 2em;
}
h3 {
margin-bottom: 1em;
font-size: 1.5em;
line-height: 1;
}
h4 {
margin-bottom: 1.25em;
font-size: 1.2em;
line-height: 1.25;
}
h5 {
margin-bottom: 1.5em;
font-size: 1em;
font-weight: bold;
}
h6 {
font-size: 1em;
font-weight: bold;
}
h1 img, h2 img, h3 img,
h4 img, h5 img, h6 img {
margin: 0;
}
/* Text elements */
p {
margin: 0 0 1.5em;
}
.left {
float: left !important;
}
p .left {
margin: 1.5em 1.5em 1.5em 0;
padding: 0;
}
.right {
float: right !important;
}
p .right {
margin: 1.5em 0 1.5em 1.5em;
padding: 0;
}
a:focus, a:hover {
color: #0099FF;
}
a {
color: #0066CC;
text-decoration: underline;
}
blockquote {
margin: 1.5em;
font-style: italic;
color: #666666;
}
strong, dfn {
font-weight: bold;
}
em, dfn {
font-style: italic;
}
sup, sub {
line-height: 0;
}
abbr, acronym {
border-bottom: 1px dotted #666666;
}
address {
margin: 0 0 1.5em;
font-style: italic;
}
del {
color: #666666;
}
pre {
margin: 1.5em 0;
white-space: pre;
}
pre, code, tt {
font: 1em "andale mono", "lucida console", monospace;
line-height: 1.5;
}
/* Lists */
li ul, li ol {
margin: 0;
}
ul, ol {
margin: 0 1.5em 1.5em 0;
padding-left: 1.5em;
}
ul {
list-style-type: disc;
}
ol {
list-style-type: decimal;
}
dl {
margin: 0 0 1.5em 0;
}
dl dt {
font-weight: bold;
}
dd {
margin-left: 1.5em;
}
/* Tables */
table {
width: 100%;
margin-bottom: 1.4em;
}
th {
font-weight: bold;
}
table.zebra thead th, table.zebra tfoot th {
background-color: #BFBFBF;
}
th, td, caption {
padding: 4px 10px 4px 5px;
}
table.zebra tbody tr:nth-child(even) td, table.zebra tbody tr.even td {
background-color: #E6E6E6;
}
caption {
background-color: #EEEEEE;
}
/* Misc classes */
.fancy {
text-shadow: white 0 1px 0;
}
.bfancy {
text-shadow: black 0 1px 0;
}
.fancyt {
text-shadow: white 0 -1px 0;
}
.bfancyt {
text-shadow: black 0 -1px 0;
}
.no-fancy {
text-shadow: none;
}
.select {
cursor: auto;
user-select: auto;
-webkit-user-select: auto;
-moz-user-select: auto;
-o-user-select: auto;
}
img.select, .select img {
user-drag: auto;
-webkit-user-drag: auto;
-moz-user-drag: auto;
-o-user-drag: auto;
}
.no-select {
cursor: default;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-o-user-select: none;
}
img.no-select, .no-select img {
user-drag: none;
-webkit-user-drag: none;
-moz-user-drag: none;
-o-user-drag: none;
}
.focus:focus, .focus :focus {
outline: auto;
}
.no-focus:focus, .no-focus :focus {
outline: 0;
}
.small {
margin-bottom: 1.875em;
font-size: .8em;
line-height: 1.875em;
}
.large {
margin-bottom: 1.25em;
font-size: 1.2em;
line-height: 2.5em;
}
.show {
display: block !important;
}
.show-inline {
display: inline-block !important;
}
.hide {
display: none;
}
.quiet {
color: #666666;
}
.loud {
color: black;
}
.highlight {
background-color: yellow;
}
.added {
background-color: #006600;
color: white;
}
.removed {
background-color: #990000;
color: white;
}
.first {
margin-left: 0;
padding-left: 0;
}
.last {
margin-right: 0;
padding-right: 0;
}
.top {
margin-top: 0;
padding-top: 0;
}
.bottom {
margin-bottom: 0;
padding-bottom: 0;
}
/*
// Default styling for forms
*/
fieldset {
margin: 0 0 1.5em 0;
padding: 0 1.4em 1.4em 1.4em;
border: 1px solid #CCCCCC;
}
legend {
margin-top: -0.2em;
margin-bottom: 1em;
font-weight: bold;
font-size: 1.2em;
}
/* Form fields */
input[type=text], input[type=password], textarea {
background-color: white;
border: 1px solid #BBBBBB;
}
input[type=text], input[type=password],
textarea, select {
margin: 0.5em 0;
}
input[type=text], input[type=password] {
width: 300px;
padding: 4px;
}
textarea {
width: 450px;
height: 170px;
padding: 5px;
}
/* success, info, notice and error boxes */
.success, .info, .notice, .error {
margin-bottom: 1em;
padding: 0.8em;
border: 2px solid #DDDDDD;
}
.success {
background-color: #E6EFC2;
border-color: #C6D880;
color: #264409;
}
.info {
background-color: #D5EDF8;
border-color: #92CAE4;
color: #205791;
}
.notice {
background-color: #FFF6BF;
border-color: #FFD324;
color: #514721;
}
.error {
background-color: #FBE3E4;
border-color: #FBC2C4;
color: #8A1F11;
}
.success a {
color: #264409;
}
.info a {
color: #205791;
}
.notice a {
color: #514721;
}
.error a {
color: #8A1F11;
}
File diff suppressed because it is too large Load Diff
+99
View File
@@ -0,0 +1,99 @@
//
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/store-js
// License: MIT-license
//
(function () {
var Store = this.Store = function (name, defaults) {
var key;
this.name = name;
if (defaults !== undefined) {
for (key in defaults) {
if (defaults.hasOwnProperty(key) && this.get(key) === undefined) {
this.set(key, defaults[key]);
}
}
}
};
Store.prototype.get = function (name) {
name = "store." + this.name + "." + name;
if (localStorage.getItem(name) === null) { return undefined; }
try {
return JSON.parse(localStorage.getItem(name));
} catch (e) {
return null;
}
};
Store.prototype.set = function (name, value) {
if (value === undefined) {
this.remove(name);
} else {
if (typeof value === "function") {
value = null;
} else {
try {
value = JSON.stringify(value);
} catch (e) {
value = null;
}
}
localStorage.setItem("store." + this.name + "." + name, value);
}
return this;
};
Store.prototype.remove = function (name) {
localStorage.removeItem("store." + this.name + "." + name);
return this;
};
Store.prototype.removeAll = function () {
var name,
i;
name = "store." + this.name + ".";
for (i = (localStorage.length - 1); i >= 0; i--) {
if (localStorage.key(i).substring(0, name.length) === name) {
localStorage.removeItem(localStorage.key(i));
}
}
return this;
};
Store.prototype.toObject = function () {
var values,
name,
i,
key,
value;
values = {};
name = "store." + this.name + ".";
for (i = (localStorage.length - 1); i >= 0; i--) {
if (localStorage.key(i).substring(0, name.length) === name) {
key = localStorage.key(i).substring(name.length);
value = this.get(key);
if (value !== undefined) { values[key] = value; }
}
}
return values;
};
Store.prototype.fromObject = function (values, merge) {
if (merge !== true) { this.removeAll(); }
for (var key in values) {
if (values.hasOwnProperty(key)) {
this.set(key, values[key]);
}
}
return this;
};
}());
+94
View File
@@ -0,0 +1,94 @@
// SAMPLE
this.manifest = {
"name": "Mostly Harmless",
"icon": "../alien.png",
"settings": [
{
"tab": "Performance",
"group": "Cache Time",
"name": "cacheTime",
"type": "slider",
"label": "",
"max": 5,
"min": 1,
"step": 1,
"display": true,
"displayModifier": function(value) {
if(value === 1)
return value.toString() + " minute";
return value.toString() + " minutes";
}
},
{
"tab": "Performance",
"group": "Cache Time",
"name": "cacheDescription",
"type": "description",
"text": "<p>Mostly Harmless grabs data from the Reddit API every time you load a page. However, that data can be cached, or saved for a short time, to improve performance and reduce the load on the reddit API.</p><p>This option allows you to change how long a page's data is cached. Longer cache times mean less bandwidth, faster results, and less load on reddit. Shorter cache times mean fresher data.</p>"
},
{
"tab": "Preferences",
"group": "Excluded Sites",
"name": "excludedDescription",
"type": "description",
"text": "<h3>Excluding sites does not work yet!</h3><p><big>I am waiting on Fancy Settings to support textareas.</big></p><p>Mostly Harmless grabs data from the Reddit API every time you load a page. This takes time and bandwidth, taxes the reddit API, and sends the unencrypted URL to reddit. However, you can exclude certain domains or URL patterns from being looked up.</p>"
},
{
"tab": "Preferences",
"group": "Excluded Sites",
"name": "excludedDomains",
"type": "text",
"label": "Excluded domains:",
"text": "secure.ingdirect.com\nchaseonline.chase.com\nonline.wellsfargo.com"
},
{
"tab": "Preferences",
"group": "Excluded Sites",
"name": "excludedDomainsDescription",
"type": "description",
"text": "<p>Put domains or subdomains, one per line, in the above text box. Any page on the listed domains will <strong>not</strong> activate Mostly Harmless.</p>"
},
{
"tab": "Preferences",
"group": "Excluded Sites",
"name": "excludedRegex",
"type": "text",
"label": "Excluded regex matches",
"text": "chrome:\/\/.*\nhttps?:\/\/www\.google\.com\/search.*\nhttps?:\/\/search\.yahoo\.com\/search.*\nhttps?:\/\/www\.bing\.com\/search.*"
},
{
"tab": "Preferences",
"group": "Excluded Sites",
"name": "excludedRegexDescription",
"type": "description",
"text": "<p>Put regular expressions, one per line, in the above text box. Please do not use the <code>\\n</code> character, because there should be no newlines in a URL. Any page that matches the listed regular expressions will <strong>not</strong> activate Mostly Harmless."
},
{
"tab": "Preferences",
"group": "Fresh Content",
"name": "freshCutoff",
"type": "slider",
"label": "",
"max": 90,
"min": 1,
"step": 1,
"display": true,
"displayModifier": function(value) {
if(value === 1)
return value.toString() + " day";
if(value <= 2 * 7)
return value.toString() + " days";
if(value > 2 * 7 && value < 7 * 7)
return Math.floor(value / 7).toString() + " weeks";
return Math.ceil(value / 30).toString() + " months";
}
},
{
"tab": "Preferences",
"group": "Fresh Content",
"name": "freshCutoffDescription",
"type": "description",
"text": "<p>This setting allows you to choose the oldest reddit posts you&rsquo;d like to see. Anything posted before the value you&rsquo;ve chosen will not be indicated in the browser button's total, and will not be shown in the popup."
}
]
};
+56
View File
@@ -0,0 +1,56 @@
window.addEvent("domready", function () {
// Option 1: Use the manifest:
new FancySettings.initWithManifest();
// Option 2: Do everything manually:
/*
var settings = new FancySettings("My Extension", "icon.png");
var username = settings.create({
"tab": i18n.get("information"),
"group": i18n.get("login"),
"name": "username",
"type": "text",
"label": i18n.get("username"),
"text": i18n.get("x-characters")
});
var password = settings.create({
"tab": i18n.get("information"),
"group": i18n.get("login"),
"name": "password",
"type": "text",
"label": i18n.get("password"),
"text": i18n.get("x-characters-pw"),
"masked": true
});
var myDescription = settings.create({
"tab": i18n.get("information"),
"group": i18n.get("login"),
"name": "myDescription",
"type": "description",
"text": i18n.get("description")
});
var myButton = settings.create({
"tab": "Information",
"group": "Logout",
"name": "myButton",
"type": "button",
"label": "Disconnect:",
"text": "Logout"
});
// ...
myButton.addEvent("action", function () {
alert("You clicked me!");
});
settings.align([
username,
password
]);
*/
});
+5
View File
@@ -4,6 +4,11 @@ The following images are (C) 2008 CondeNet, Inc. All rights reserved:
gradient-button-hover.png
sprite.png
The files found in the fancy-settings/ directory are based on Fancy Settings,
by Frank Kohlhepp, licensed under the GNU GPL v2.1, which is available at the
URL http://www.gnu.org/licenses/lgpl-2.1.html online. Fancy Settings can be
found and forked at https://github.com/frankkohlhepp/fancy-settings/ on Github.
The following license applies to all other files unless noted within the file:
Copyright (C) 2011 by Kerrick Long
+2 -1
View File
@@ -9,5 +9,6 @@
"http://*.reddit.com/",
"tabs"
],
"background_page": "background.html"
"background_page": "background.html",
"options_page": "fancy-settings/index.html"
}
+1
View File
@@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>Chrome Popup</title>
<link href="popup.css" type="text/css" rel="stylesheet">
<script src="fancy-settings/lib/store.js" type="text/javascript"></script>
<script src="popup.js" type="text/javascript"></script>
</head>
<body>
+4 -17
View File
@@ -1,30 +1,17 @@
var db = openDatabase('mhdb', '1.0', 'Mostly Harmless Database', 5 * 1024 * 1024);
var cacheTime;
var over18;
var settings = new Store("settings", {
"cacheTime": 1
}).toObject();
var commentsMatchPattern = /https?:\/\/www\.reddit\.com(\/r\/(.+?))?\/comments\/(.+?)\/.*/;
var isCommentsPage = false;
init();
function init() {
if(window.localStorage.getItem('installed') !== 'true') {
installDefaults();
}
db.transaction(function(tx){
tx.executeSql('SELECT * FROM prefs WHERE pref=?', ['cacheTime'], function(tx, results) {
cacheTime = results.rows.item(0).choice;
});
tx.executeSql('SELECT * FROM prefs WHERE pref=?', ['over18'], function(tx, results) {
over18 = results.rows.item(0).choice;
});
});
}
chrome.tabs.getSelected(undefined, function(currTab) {
buildPage(currTab.url);
});
function buildPage(pageUrl) {
isCommentsPage = commentsMatchPattern.test(pageUrl);
var sqlQuery = isCommentsPage ? 'SELECT * FROM posts WHERE id=?' : 'SELECT * FROM posts WHERE url=?';
var sqlSearch = isCommentsPage ? pageUrl.match(commentsMatchPattern)[3] : pageUrl;
var sqlSearch = isCommentsPage ? pageUrl.match(commentsMatchPattern)[3] : pageUrl.split('#')[0];
db.transaction(function(tx){
tx.executeSql(sqlQuery, [sqlSearch], function(tx, results) {
console.log(results.rows);