Own handler for links.

All external links (not belonging to mail.yandex.ru domain) should
open in external browser now. Related to #3.
parent 0b64bda8
......@@ -36,7 +36,6 @@ function createWindow() {
//mainWindow.webContents.openDevTools();
mainWindow.loadURL('https://mail.yandex.ru/');
//mainWindow.loadFile(path.join(__dirname, "index.html"));
mainWindow.on('closed', function () {
mainWindow = null;
})
......
// This file is loaded by Chromium engine and executes in browser.
console.log(window);
var ipc = require("electron").ipcRenderer;
const ipc = require('electron').ipcRenderer;
const { shell } = require('electron')
// Unread mails check.
function checkForUnreads() {
unread = parseInt(document.title.split(" ")[0]);
unread = parseInt(document.title.split(' ')[0]);
if (typeof (unread) != NaN && unread > 0) {
ipc.send('has-unread', unread);
} else {
......@@ -10,4 +14,35 @@ function checkForUnreads() {
};
}
setInterval(checkForUnreads, 1000);
\ No newline at end of file
setInterval(checkForUnreads, 1000);
// Handle all clicks on links.
function clickHandler(event) {
console.log(event);
// We should check not only specified element, but also all other
// parent elements until we found a.daria-goto-anchor.
var linkFound = false;
var link = "";
if (!event.target.hasOwnProperty('href')) {
for (var i = 0; i < event.path.length; i++) {
if (event.path[i].tagName == 'A' && (event.path[i].className.indexOf('daria-goto-anchor') !== -1 || event.path[i].className.indexOf('mail-ui-IconList-Item') !== -1 && event.path[i].hostname != "mail.yandex.ru")) {
linkFound = true;
link = event.path[i].href;
break;
}
}
} else {
linkFound = true;
link = event.target.href;
}
if (linkFound) {
event.preventDefault();
shell.openExternal(link);
} else {
console.log("No external link found, doing nothing");
}
}
document.addEventListener('click', clickHandler);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment