Skip to content

Commit

Permalink
Optimize ads blocking, update analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
edanchenkov committed Jun 29, 2020
1 parent 36a7ff9 commit e4e8362
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
10 changes: 9 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,16 @@
ga('set', 'checkProtocolTask', null);
ga('send', 'pageview');
ga('set', 'appVersion', remote && remote.app && remote.app.getVersion());
ga('send', 'appVersion', remote && remote.app && remote.app.getVersion());

ga('send', {
'hitType': 'event',
'eventCategory': 'app',
'eventAction': 'init',
'eventLabel': remote && remote.app && remote.app.getVersion(),
// 'hitCallback': function () {
// alert("Event received");
// }
});
})();
}, 500)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MenuTube",
"version": "1.7.2",
"version": "1.7.3",
"description": "Catch YouTube into your macOS menu bar!",
"main": "main.js",
"scripts": {
Expand Down
45 changes: 35 additions & 10 deletions src/wvHelper.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
const l = document.addEventListener;
const _newListener = document.addEventListener;

// Hijack event listener to prevent YouTube from stopping on blue window (lose focus)
document.addEventListener = () => {
l.apply(document, arguments);
_newListener.apply(document, arguments);
};

(function () {
var AppConfig = require('./../config.js');
var config = AppConfig.store.userPreferences;

if (!!config.adBlock) {
const _check = v => v !== null && v !== undefined;
setInterval(() => {
const ad = [...document.querySelectorAll('.ad-showing')][0];
if (_check(ad)) {
const video = document.querySelector('video');
if (_check(video) && !isNaN(video.duration)) {
video.currentTime = video.duration;
var observeDOM = (function () {
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;

return function (obj, callback) {
if (!obj || !obj.nodeType === 1) {
return;
} // validation

if (MutationObserver) {
// define a new observer
var obs = new MutationObserver(function (mutations, observer) {
callback(mutations);
});
// have the observer observe foo for changes in children
obs.observe(obj, { childList: true, subtree: true });
} else if (window.addEventListener) {
obj.addEventListener('DOMNodeInserted', callback, false);
obj.addEventListener('DOMNodeRemoved', callback, false);
}
}
}, 500);
})();

_newListener('DOMContentLoaded', () => {
observeDOM(document.body, function (m) {
const _check = v => v !== null && v !== undefined;
const ad = [...document.querySelectorAll('.ad-showing')][0];
if (_check(ad)) {
const video = document.querySelector('video');
if (_check(video) && !isNaN(video.duration)) {
video.currentTime = video.duration;
}
}
});
});

}

var ipcRenderer = require('electron').ipcRenderer;
Expand Down

0 comments on commit e4e8362

Please sign in to comment.