Own handler for links.
All external links (not belonging to mail.yandex.ru domain) should open in external browser now. Related to #3.
This commit is contained in:
parent
0b64bda855
commit
9be3323859
1
main.js
1
main.js
@ -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;
|
||||
})
|
||||
|
43
renderer.js
43
renderer.js
@ -1,8 +1,12 @@
|
||||
console.log(window);
|
||||
var ipc = require("electron").ipcRenderer;
|
||||
// This file is loaded by Chromium engine and executes in browser.
|
||||
|
||||
console.log(window);
|
||||
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);
|
||||
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);
|
Reference in New Issue
Block a user