-
Notifications
You must be signed in to change notification settings - Fork 71
/
index.js
81 lines (73 loc) · 2.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var self = require('sdk/self');
var pageMod = require('sdk/page-mod');
function notDataUrl(name) {
return self.data.url(name).replace("/data/", "/");
}
function notDataRead(name) {
return self.data.load("../" + name);
}
let { Cc, Ci } = require('chrome');
var modules = {
mark_as_read: {
toggle: function (params) {
var self = this;
let { search } = require("sdk/places/history");
search(params)
.on("end", function (results) {
if (results.length > 0) {
self.delete(params);
} else {
self.add(params);
}
});
},
delete: function (params) {
console.error("Removing: ", params.url);
Cc["@mozilla.org/browser/nav-history-service;1"]
.getService(Ci.nsIBrowserHistory).removePage(params);
},
add: function (params) {
console.error("Adding: ", params.url);
Cc["@mozilla.org/browser/history;1"]
.getService(Ci.mozIAsyncHistory).updatePlaces({
uri: params.url,
visitDate: new Date().toJSON().slice(0, 10)
});
}
}
};
pageMod.PageMod({
include: "*.ycombinator.com",
attachTo: ["top", "existing"],
contentScriptFile: [
notDataUrl("lib/tools/utility.js"),
notDataUrl("lib/settings.js"),
notDataUrl("lib/modules/visual_theme.js"),
notDataUrl("lib/modules/dark_theme.js"),
notDataUrl("lib/modules/high_contrast.js"),
notDataUrl("lib/modules/gray_visited_links.js"),
notDataUrl("lib/modules/open_links_in_new_tabs.js"),
notDataUrl("lib/modules/highlight_links_when_returning.js"),
notDataUrl("lib/modules/infinite_scrolling.js"),
notDataUrl("lib/modules/accurate_domain_names.js"),
notDataUrl("lib/modules/mark_as_read.js"),
notDataUrl("lib/modules/sticky_header.js"),
notDataUrl("lib/modules/user_tooltips.js")
],
contentScriptOptions: {
urlBase: notDataUrl(""),
defaultOptions: notDataRead("lib/defaults.json")
},
onAttach: function(worker) {
for(var moduleName in modules)
{
var module = modules[moduleName];
for(var actionName in modules[moduleName])
{
worker.port.on(moduleName + "#" + actionName, function(params) {
module[actionName].call(module, params);
});
}
}
}
});