- Force https.
- Auto-login.
- Skip logout reminder.
- Switch to mail tab after login.
- Periodically refresh inbox to avoid auto-logout.
Last active
July 20, 2016 15:09
-
-
Save pyhedgehog/f26b40fbcbd1b1a5227b to your computer and use it in GitHub Desktop.
MailCom disable ads (v10)
- Changes on mail page.
- Better handle timeouts and connection errors (progressive retries).
- Changes on login page.
- Better handle timeouts and connection errors.
- Fix of auto-login.
- Code refactoring.
- Auto-refresh every 5 minutes to avoid auto-logout.
- Switch login page to https.
- Auto-login.
- Auto-click on "Mail" tab.
- Code improve and error handling.
- https support.
Version 1 (against http://userscripts-mirror.org/scripts/review/3348)
- remove "The checkbox of all unread messages is now checked" feature. It should be separate script.
- Click "Continue to Inbox" button on "/remindlogout" page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name MailCom disable ads | |
// @id [email protected] | |
// @namespace https://gist.github.com/pyhedgehog/ | |
// @description Skip Mail.Com ad pages and ads. Origin (http://userscripts-mirror.org/scripts/review/3348) | |
// @homepage https://gist.github.com/pyhedgehog/f26b40fbcbd1b1a5227b/ | |
// @downloadURL https://gist.github.com/pyhedgehog/f26b40fbcbd1b1a5227b/raw/mailcomNoAds.user.js | |
// @updateURL https://gist.github.com/pyhedgehog/f26b40fbcbd1b1a5227b/raw/mailcomNoAds.meta.js | |
// @include http://*.mail.com/* | |
// @include https://*.mail.com/* | |
// @version 11 | |
// @grant none | |
// ==/UserScript== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name MailCom disable ads | |
// @id [email protected] | |
// @namespace https://gist.github.com/pyhedgehog/ | |
// @description Skip Mail.Com ad pages and ads. Origin (http://userscripts-mirror.org/scripts/review/3348) | |
// @homepage https://gist.github.com/pyhedgehog/f26b40fbcbd1b1a5227b/ | |
// @downloadURL https://gist.github.com/pyhedgehog/f26b40fbcbd1b1a5227b/raw/mailcomNoAds.user.js | |
// @updateURL https://gist.github.com/pyhedgehog/f26b40fbcbd1b1a5227b/raw/mailcomNoAds.meta.js | |
// @include http://*.mail.com/* | |
// @include https://*.mail.com/* | |
// @version 11 | |
// @grant none | |
// ==/UserScript== | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_registerMenuCommand | |
(function() { | |
var debug = true; | |
/*var debug = GM_getValue('debug', false); | |
var debugCmd = GM_registerMenuCommand('Switch debug', debugMenuClick, 'd'); | |
console.log(debugCmd); | |
function debugMenuClick() { | |
debug = !debug; | |
GM_setValue('debug', debug); | |
console.log('debug =', debug); | |
}*/ | |
function xpath(query) { | |
return document.evaluate(query, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
} | |
function getAppName() { | |
try { | |
return document.getElementById('app-contents-wrapper').getElementsByClassName('pos-app-stack__children--active')[0].getAttribute('name'); | |
} catch(ex) { | |
if(debug)console.log("getAppName exception: "+ex) | |
return undefined; | |
} | |
} | |
function checkHome(to) { | |
if(!to) to = 1000; | |
if(getAppName() === undefined) { | |
if(debug)console.log("checkHome: wait"); | |
if(to<=60000) { | |
return setTimeout(checkHome.bind(null, to*1.2), to); | |
} | |
} | |
if(debug)console.log("checkHome: getAppName() = "+getAppName()); | |
if(getAppName() === 'home') { | |
return setTimeout(switchMail, 1000); | |
} | |
} | |
function switchMail() { | |
if(debug)console.log("switchMail: getAppName() = "+getAppName()); | |
if(getAppName() !== 'home') return; | |
var l = xpath('//*[@icon="core_mail"]//a'); | |
if(l.snapshotLength) { | |
var mailappbutton = l.snapshotItem(0); | |
if(debug)console.log("switchMail: mailappbutton = "+mailappbutton); | |
if(mailappbutton) { | |
mailappbutton.click(); | |
} | |
} | |
} | |
function gotoLogin() { | |
top.location.href = 'https://www.mail.com/int/'; | |
} | |
function autoLogin(to) { | |
if(!to) to = 2000; | |
var logLayer = document.getElementsByClassName('login-layer')[0]; | |
if(debug)console.log('autoLogin: logLayer =', logLayer); | |
var login = document.getElementById('login-button'); | |
if(debug)console.log('autoLogin: login =', login); | |
if(login && (document.location.protocol === 'http:')) { | |
setTimeout(gotoLogin,1000); | |
return true; | |
} | |
if(debug)console.log('autoLogin: login check'); | |
if(!login) return false; | |
if(!logLayer) return false; | |
if(debug)console.log('autoLogin: login open', logLayer.classList); | |
if(!logLayer.classList.contains('open')) { | |
if(debug)console.log('autoLogin: login.click'); | |
login.click(); | |
if(to<=60000) { | |
setTimeout(autoLogin.bind(null, to*1.5), to); | |
} | |
return true; | |
} | |
if(debug)console.log('autoLogin: login setup'); | |
if(debug)console.log('autoLogin: login.setTimeout'); | |
var email = document.getElementById('login-email'); | |
if(debug)console.log('autoLogin: email.value =', email?email.value:email); | |
if(!email || !email.value) return; | |
var pass = document.getElementById('login-password'); | |
if(debug)console.log('autoLogin: pass.value =', pass?pass.value:pass); | |
if(!pass || !pass.value) return; | |
var logform = document.getElementById('login-form'); | |
var logbut; | |
if(logform) logbut = logform.getElementsByTagName('button'); | |
if(debug)console.log('autoLogin: logbut =', logbut); | |
if(debug)console.log('autoLogin: login check = '+(email && email.value && pass && pass.value && logbut && (logbut.length === 1))); | |
if(!logbut | (logbut.length !== 1)) return; | |
logbut = logbut[0]; | |
if(debug)console.log('autoLogin: logbut.click'); | |
logbut.click(); | |
return true; | |
} | |
function autoSkip() { | |
if(debug)console.log('autoSkip: window.name =', window.name); | |
if(document.location.pathname === "/remindlogout") { | |
if(debug)console.log('autoSkip: /remindlogout'); | |
var save = document.getElementById('save'); | |
if(save) { | |
var skipbut = save.getElementsByTagName('button'); | |
if(debug)console.log('autoSkip: /remindlogout + skip +', skipbut.length); | |
if(skipbut && skipbut.length>0) { | |
if(debug)console.log('autoSkip: skipbut[0].click'); | |
skipbut[0].click(); | |
} | |
return true; | |
} | |
} | |
if(window.name == "splash_nav") { | |
Array.prototype.forEach.call(document.getElementsByTagName('a'),function(elem){ | |
if(elem.attributes.getNamedItem('data-skip')) { | |
elem.click(); | |
} | |
}); | |
} | |
return false; | |
} | |
function removeAds() { | |
var act=1; | |
var script_var = "var adShown = 'true'; if(window.seenAd) seenAd();"; | |
var skip_ad = document.createElement("script"); | |
skip_ad.setAttribute('type', 'text/javascript'); | |
skip_ad.innerHTML = script_var; | |
document.body.appendChild(skip_ad); | |
var ads = xpath("//div[script]"); | |
for(var i = 0; i < ads.snapshotLength; i++, act++) { | |
ad = ads.snapshotItem(i); | |
divname = ad.getAttribute("class"); | |
if(!(divname == "bdviolet")) { | |
ad.parentNode.removeChild(ad); | |
} | |
} | |
if(debug)console.log('removeAds: act = '+act); | |
} | |
var refreshIntervalId; | |
function refreshInbox() { | |
var refresh = document.getElementsByClassName('refresh'); | |
if(debug) console.log("refreshInbox()", refresh.length, refresh); | |
if(refresh && refresh.length>0) { | |
if(debug) console.log("refresh.click"); | |
refresh[0].click(); | |
} | |
} | |
var reloginIntervalId; | |
function checkRelogin() { | |
var sessionExpiredMsg = document.getElementById('session-expired'); | |
console.log('sessionExpiredMsg =', sessionExpiredMsg); | |
if(sessionExpiredMsg) { | |
console.log('sessionExpiredMsg.display =', window.getComputedStyle(sessionExpiredMsg).display); | |
if(window.getComputedStyle(sessionExpiredMsg).display == 'block') { | |
clearInterval(reloginIntervalId); | |
return gotoLogin(); | |
} | |
} | |
} | |
if(autoSkip()) return; | |
if(autoLogin()) return; | |
if(window === top) { | |
removeAds(); | |
checkHome(); | |
reloginIntervalId = setInterval(checkRelogin, 300000); | |
} | |
if(window.name == 'mail') { | |
refreshIntervalId = setInterval(refreshInbox, 300000); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment