This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
/
app.js
132 lines (113 loc) · 2.68 KB
/
app.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* _ _ _
* | | _ _| | |
* | | | | | | | |
* | |__| |_| | | |
* |_____\__,_|_|_|
* By: Jason Stallings
*/
var robot = require("robotjs");
var gui = require("nw.gui");
var async = require("async");
var loudness = require("loudness");
var appVersion = gui.App.manifest.version;
var ua = require("universal-analytics");
var visitor = ua("UA-67011723-3");
var win = gui.Window.get();
//Pixels to check for ad.
var adPixels = [[25, 22], [24, 23], [27, 19], [28, 21], [31, 23], [33, 24]];
var screenSize = robot.getScreenSize();
var middle = screenSize.width/2;
var start;
//Create tray.
var tray = new gui.Tray(
{
icon: "tray.png",
iconsAreTemplates: false
});
//Give it a menu.
var menu = new gui.Menu();
menu.append(new gui.MenuItem(
{
label: "v" + appVersion
}));
menu.append(new gui.MenuItem(
{
type: "separator"
}));
menu.append(new gui.MenuItem(
{
label: "Exit",
click: function()
{
gui.App.quit();
},
}));
tray.menu = menu;
//Muted state.
var alreadyMuted = 0;
//App Start.
visitor.event("App event", "App opened").send();
scan();
setInterval(scan, 1000);
//Check to see if ad is playing using screen reading.
function scan()
{
//Array of tasks for async parallel.
var tasks = [];
//Loop through adPixels array.
for (var x in adPixels)
{
//Closure to keep value of x.
(function(x)
{
tasks.push(function(done)
{
var hex = robot.getPixelColor(adPixels[x][0], adPixels[x][1]);
//If hex is 000000, return true.
var pass = hex === "ededed" ? true : false;
done(null, pass);
});
}(x));
}
//Special check, make sure the whole screen isn't ededed.
tasks.push(function(done)
{
var hex = robot.getPixelColor(middle, 1);
//If hex is ededed, return false.
var pass = hex === "ededed" ? false : true;
done(null, pass);
});
async.parallel(tasks, function(err, results)
{
//If false isn't found, ad must be playing.
if (results.indexOf(false) == -1)
{
//If not muted, mute it!
loudness.getMuted(function (err, mute)
{
if (!mute && !alreadyMuted)
{
loudness.setMuted(true, function(err) {});
alreadyMuted = 1;
visitor.event("App event", "Muted ad").send();
start = new Date().getTime();
}
});
}
else
{
//If muted, unmute it!
loudness.getMuted(function (err, mute)
{
if (mute && alreadyMuted)
{
loudness.setMuted(false, function(err) {});
var end = new Date().getTime();
var time = end - start;
visitor.timing("App event", "Total ad length", time).send();
}
alreadyMuted = 0;
});
}
});
}