Last active
November 22, 2019 07:27
-
-
Save TheDrHax/4e837578aa5d2898779a9d24a09a045f to your computer and use it in GitHub Desktop.
Скрипт для GreaseMonkey, быстро прокликивающий все нужные кнопки на https://auth.wi-fi.ru/
This file contains 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 MosMetroV2.js | |
// @description This script skips annoying quizes and full screen ads on https://auth.wi-fi.ru | |
// @author Dmitry Karikh <[email protected]> (https://github.com/mosmetro-android) | |
// @version 2 | |
// @grant none | |
// @include *://auth.wi-fi.ru/auth* | |
// ==/UserScript== | |
(function () { | |
const MO = window.MutationObserver || window.WebKitMutationObserver; | |
/* https://stackoverflow.com/a/4588211 */ | |
function fullPath(el) { | |
var names = []; | |
while (el.parentNode) { | |
if (el.id) { | |
names.unshift('#' + el.id); | |
} else { | |
if (el == el.ownerDocument.documentElement) { | |
names.unshift(el.tagName.toLowerCase()); | |
} else { | |
var sel = el.tagName.toLowerCase(); | |
var siblings = Array.apply([], el.parentElement.children).filter(function (e) { | |
return e.tagName == el.tagName; | |
}).length; | |
if (el.className) { | |
sel += "." + el.className.replace(/\s+/g, '.'); | |
} else if (siblings > 1) { | |
for (var c = 1, e = el; e.previousElementSibling; e = e.previousElementSibling, c++); | |
sel += ":nth-child(" + c + ")"; | |
} | |
names.unshift(sel); | |
} | |
} | |
el = el.parentNode; | |
} | |
return names.join(" > "); | |
} | |
const IGNORE = [ | |
'img.pixel' | |
]; | |
const CLICK = [ | |
'.join', | |
'.cross', | |
'.mt-banner-fullscreen__button-close', | |
'.interaction_button__joke', | |
'.interaction_button_quiz', | |
'.interaction_button', | |
'.button_blue' | |
]; | |
function log(msg) { | |
console.log('MosMetroV2.js | ' + msg.replace(/\n/, '')) | |
} | |
function each(query, f) { | |
[].forEach.call(document.querySelectorAll(query), f); | |
} | |
function click(el) { | |
/* click only visible elements */ | |
var style = window.getComputedStyle(el); | |
if (el.offsetParent !== null && style.visibility != 'hidden') { | |
log("Click | " + fullPath(el)); | |
el.click(); | |
} | |
} | |
function onNodeChange(el) { | |
if (el.matches(IGNORE)) { | |
return; | |
} | |
if (el.matches(CLICK)) { | |
setTimeout(function () { click(el); }, 500); | |
} | |
el.querySelectorAll(CLICK).forEach(function (child) { | |
setTimeout(function () { click(child); }, 500); | |
}); | |
} | |
function onMutation(ml, o) { | |
ml.forEach(function (m) { | |
if (m.target.outerHTML !== undefined) { | |
if (m.type == 'attributes') { | |
log('Mutation (' + m.type + ') | ' + fullPath(m.target) + | |
' | "' + m.attributeName + '": "' + m.oldValue + '" > "' + | |
m.target.getAttribute(m.attributeName) + '"'); | |
} else { | |
log('Mutation (' + m.type + ') | ' + fullPath(m.target)); | |
} | |
} | |
onNodeChange(m.target); | |
}); | |
each('video', function (el) { | |
el.pause(); | |
}); | |
} | |
if (document.location.pathname.lastIndexOf('/auth', 0) !== 0) { | |
log('Wrong page: ' + document.location); | |
} | |
var o = new MO(onMutation); | |
o.observe(document.body, { | |
childList: true, | |
attributes: true, | |
subtree: true, | |
attributeOldValue: true | |
}); | |
log('Loaded successfully'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment