Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options page #4

Merged
merged 9 commits into from
Feb 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
});
chrome.runtime.onInstalled.addListener(function(details) {
chrome.alarms.create("updater", { "periodInMinutes": 1 });
chrome.tabs.create({url: "options.html"}, function (tab) {});
});

// Update number on navigate to a new thread
chrome.webNavigation.onCompleted.addListener(function (details) {
ITCheck.getUnreadThreadCount(null);
},{url: [{hostSuffix: 'ivorytower.com', pathPrefix: '/IvoryTower/ForumThread.aspx'}]});
})(window);
})(window);
37 changes: 25 additions & 12 deletions cohort-year-adder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@
// @include http://ivorytower.dyndns.org/*
// @include http://ivorytower.go.dyndns.org/*
// ==/UserScript==
(function(){
var years = {
// Sanitized for GitHub. Added back on building.
};

var years = {
// Sanitized for GitHub. Added back on building.
};

var elements = document.evaluate("//a[starts-with(@href,'ProfileShow.aspx')]",
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for(var i = 0; i < elements.snapshotLength; i++) {
var cur = elements.snapshotItem(i);
var name = cur.getAttribute('href').split('=')[1];
var year = document.createTextNode(" (" + years[name] + ")");
cur.appendChild(year);
}
function runadder(showCohorts){
if(showCohorts){
var elements = document.evaluate("//a[starts-with(@href,'ProfileShow.aspx')]",
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for(var i = 0; i < elements.snapshotLength; i++) {
var cur = elements.snapshotItem(i);
var name = cur.getAttribute('href').split('=')[1];
var year = document.createTextNode(" (" + years[name] + ")");
cur.appendChild(year);
}
}
}

function storageGet(key, callback){
var k = key;
chrome.storage.sync.get(k, function(storageObj){
callback(storageObj[k]);
});
}
storageGet('ITCheck.showCohorts', runadder);
})();
21 changes: 21 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,30 @@
chrome.browserAction.setTitle({ title: newTitle});
}

function storageGet(key, callback){
var k = key;
chrome.storage.sync.get(k, function(storageObj){
callback(storageObj[k]);
})
}

function storageSet(key, val){
var pair = {};
pair[key] = val;
chrome.storage.sync.set(pair);
}

var shortcutKeys = ["nextPost","previousPost","unreadThread","rateUp","rateDown","showHidden"];
storageSet("ITCheck.shortcutKeys", shortcutKeys);

// core exports
window.ITCheck.getUnreadThreadCount = getUnreadThreadCount;
window.ITCheck.shouldSkipRequest = shouldSkipRequest;
window.ITCheck.updateBadge = updateBadge;
window.ITCheck.setTitle = setTitle;
window.ITCheck.baseUrl = baseUrl;
window.ITCheck.storageGet = storageGet;
window.ITCheck.storageSet = storageSet;
//window.ITCheck.shortcutKeys = shortcutKeys;

})(window);
12 changes: 7 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "IvoryTower Checker",
"short_name": "IT Check",
"author": "Cody Jung",
"version": "1.3.0",
"description": "Checks IvoryTower for unread threads",
"author": "Cody Jung, Eric Clymer",
"version": "1.4.0",
"description": "Checks IvoryTower for unread threads, adds misc other functionality.",
"icons": {
"48": "icon48.png",
"128": "icon128.png"
Expand All @@ -16,16 +16,18 @@
"permissions": [
"alarms",
"webNavigation",
"http://ivorytower.com/"
"http://ivorytower.com/",
"storage"
],
"options_page": "options.html",
"background": {
"scripts": ["jquery-2.1.3.min.js", "core.js", "background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["http://*.ivorytower.com/*"],
"js": ["jquery-2.1.3.min.js", "core.js", "cohort-year-adder.js", "shortcuts.js"]
"js": ["jquery-2.1.3.min.js", "cohort-year-adder.js", "shortcuts.js"]
}
],
"manifest_version": 2
Expand Down
53 changes: 53 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<html>
<head>
<script src='jquery-2.1.3.min.js' type='text/javascript'></script>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<h1>IvoryTower Checker</h1>
<hr>
<h2>Options</h2>
<form id="options">
<div id="topLevelSettings">
<div class="topLevelSetting">
<label for="showCohorts">Show Cohort By Users</label>
<input type="checkbox" name="showCohorts" />
</div>
<div class="topLevelSetting">
<label for="shortcuts">Enable Shortcuts</label>
<input type="checkbox" name="shortcuts" />
</div>
</div>
<div id="shortcutSection">
<h3>Customize Shortcut Keys</h3>
<div class="shortcutKey">
<label for="nextPost">Next Post</label>
<input type="text" size="1" name="nextPost" placeholder="j" />
</div>
<div class="shortcutKey">
<label for="previousPost">Previous Post</label>
<input type="text" size="1" name="previousPost" placeholder="k" />
</div>
<div class="shortcutKey">
<label for="unreadThread">Next Unread Thread</label>
<input type="text" size="1" name="unreadThread" placeholder="n" />
</div>
<div class="shortcutKey">
<label for="rateUp">Rate Up</label>
<input type="text" size="1" name="rateUp" placeholder="u" />
</div>
<div class="shortcutKey">
<label for="rateDown">Rate Down</label>
<input type="text" size="1" name="rateDown" placeholder="d" />
</div>
<div class="shortcutKey">
<label for="showHidden">Show Hidden</label>
<input type="text" size="1" name="showHidden" placeholder="h" />
</div>
</div>
</form>

<script src='core.js' type='text/javascript'></script>
<script src='options.js' type='text/javascript'></script>
</body>
</html>
53 changes: 53 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(function(window, $){
window.ITCheck = window.ITCheck || {};

ITCheck.storageGet("ITCheck.shortcutKeys", function(shortcutKeys){
ITCheck.storageGet('ITCheck.showCohorts', function(val){
if(val){
options.showCohorts.checked = val;
}else{
ITCheck.storageSet('ITCheck.showCohorts', true);
val = true;
}
options.showCohorts.checked = val;
});
ITCheck.storageGet('ITCheck.shortcuts', function(val){
if(val){
options.shortcuts.checked = val;
}else{
ITCheck.storageSet('ITCheck.shortcuts', true);
val = true;
}
options.shortcuts.checked = val;
});
for(var i = 0; i < shortcutKeys.length; i++){
var shortcutKey = shortcutKeys[i];
populateShortcutKey(shortcutKey);
}
for(var i = 0; i < shortcutKeys.length; i++){
var shortcutKey = shortcutKeys[i];
options[shortcutKey].onchange = function(e, shortcutKey){
var target = e.target;
ITCheck.storageSet('ITCheck.shortcutKey.'+target.name, target.value);
}
}
});

function populateShortcutKey(shortcutKey){
ITCheck.storageGet('ITCheck.shortcutKey.'+shortcutKey, function(val){
if(val){
options[shortcutKey].value = val;
}
});
}

var options = $('#options')[0];
options.showCohorts.onchange = function() {
ITCheck.storageSet('ITCheck.showCohorts', options.showCohorts.checked);
};

options.shortcuts.onchange = function() {
ITCheck.storageSet('ITCheck.shortcuts', options.shortcuts.checked);
$('#shortcutSection').toggle(options.shortcuts.checked);
};
})(window, jQuery);
2 changes: 1 addition & 1 deletion popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
} else {
// Or set it to blank
ITCheck.updateBadge("");
updatePopup("No unread threads.<br /><a href='#' id='ITToday'>Go to IvoryTower Today</a>");
updatePopup("No unread threads.<div><a href='#' id='ITToday'>Go to IvoryTower Today</a></div>");

$("#ITToday").click(function() {
openIvoryTowerToday();
Expand Down
Loading