Skip to content

Instantly share code, notes, and snippets.

@TheDrHax
Last active November 22, 2019 07:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheDrHax/4e837578aa5d2898779a9d24a09a045f to your computer and use it in GitHub Desktop.
Save TheDrHax/4e837578aa5d2898779a9d24a09a045f to your computer and use it in GitHub Desktop.
Скрипт для GreaseMonkey, быстро прокликивающий все нужные кнопки на https://auth.wi-fi.ru/
// ==UserScript==
// @name MosMetroV2.js
// @description This script skips annoying quizes and full screen ads on https://auth.wi-fi.ru
// @author Dmitry Karikh <mosmetro@thedrhax.pw> (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