Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elvismunyikiiru/f727dcf5f079f71456c56b8bff902eb2 to your computer and use it in GitHub Desktop.
Save elvismunyikiiru/f727dcf5f079f71456c56b8bff902eb2 to your computer and use it in GitHub Desktop.
MOSHI SMOKE
HUEL IKPME
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "./";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 17);
/******/ })
/************************************************************************/
/******/ ({
/***/ 17:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXTERNAL MODULE: ./shared/types.js
var types = __webpack_require__(2);
// CONCATENATED MODULE: ./contentScripts/injection/cssInjection.js
var cssInjection_processCssRules = function processCssRules(rules) {
var content = '';
var disabledCss = rules.find(function (item) {
return item.type === types["b" /* TYPES */].IGNORE_CSS.name;
});
if (disabledCss) {
var disabledCssRulesExceptions = rules.find(function (item) {
return item.type === types["b" /* TYPES */].IGNORE_CSS_EXCEPTIONS.name;
});
if (disabledCssRulesExceptions && disabledCssRulesExceptions.content) {
return content + disabledCssRulesExceptions.content.split(',').map(function (item) {
return "".concat(item, "{display: none!important;}");
}).join('') || '';
}
return;
}
var extendedCssSelectors = [];
var extendedCssSelectorsExceptions = [];
for (var i = 0; i < rules.length; i += 1) {
var rule = rules[i];
if (rule.type === types["b" /* TYPES */].CSS.name) {
content += rule.content;
}
if (rule.type === types["b" /* TYPES */].CSS_STYLES.name) {
extendedCssSelectors.push(rule.content);
}
if (rule.type === types["b" /* TYPES */].CSS_EXCEPTIONS.name) {
extendedCssSelectorsExceptions.push(rule.content);
}
}
var cssSelectorsWithoutExceptions = extendedCssSelectors.filter(function (selector) {
return !extendedCssSelectorsExceptions.find(function (exc) {
return exc === selector;
});
});
setTimeout(function () {
cssSelectorsWithoutExceptions.forEach(function (selector) {
var element = document.querySelector(selector);
if (element) {
localStorage.setItem('recently-blocked', element.className);
}
});
}, 3000);
return content + cssSelectorsWithoutExceptions.map(function (ruleContent) {
return "".concat(ruleContent, "{display: none !important;}");
}).join('');
};
function protectStyleTag(protectStyleEl) {
var _window = window,
MutationObserver = _window.MutationObserver;
if (!MutationObserver) {
return;
}
var innerObserver = new MutationObserver(function observeMutations(mutations) {
for (var i = 0; i < mutations.length; i += 1) {
var m = mutations[i];
if (protectStyleEl.hasAttribute('mod') && protectStyleEl.getAttribute('mod') === 'inner') {
protectStyleEl.removeAttribute('mod');
break;
}
protectStyleEl.setAttribute('mod', 'inner');
var isProtectStyleElModified = false;
if (m.removedNodes.length > 0) {
for (var j = 0; j < m.removedNodes.length; j += 1) {
isProtectStyleElModified = true;
protectStyleEl.appendChild(m.removedNodes[j]);
}
} else if (m.oldValue) {
isProtectStyleElModified = true;
protectStyleEl.textContent = m.oldValue;
}
if (!isProtectStyleElModified) {
protectStyleEl.removeAttribute('mod');
}
}
});
innerObserver.observe(protectStyleEl, {
childList: true,
characterData: true,
subtree: true,
characterDataOldValue: true
});
}
var injectCss = function injectCss(content) {
var css = document.createElement('style');
css.type = 'text/css';
css.textContent = content;
var styleTagInsertionTarget = document.head || document.documentElement;
styleTagInsertionTarget.appendChild(css);
protectStyleTag(css);
};
var applyCss = function applyCss(rules) {
var cssContent = cssInjection_processCssRules(rules);
injectCss(cssContent);
};
// CONCATENATED MODULE: ./contentScripts/injection/cosmeticInjection.js
var cosmeticInjection_cosmeticInjections = function cosmeticInjections(rules) {
var disabledCssRules = rules.find(function (item) {
return item.type === types["b" /* TYPES */].IGNORE_CSS.name;
});
if (disabledCssRules) {
return '';
}
function findElementsToBeBlocked(cosmeticUnblockingRules, cosmeticBlockingRules) {
var elementsToBeBlocked = [];
for (var i = 0; i < cosmeticBlockingRules.length; i += 1) {
try {
var elems = document.querySelectorAll(cosmeticBlockingRules[i]);
elems.forEach(function (elem) {
elementsToBeBlocked.push(elem);
});
} catch (e) {}
}
function filterUnblockedElements(elemToBeBlocked) {
var shouldStayBlocked = true;
for (var _i = 0; _i < cosmeticUnblockingRules.length; _i += 1) {
if (elemToBeBlocked.matches(cosmeticUnblockingRules[_i])) {
shouldStayBlocked = false;
}
}
return shouldStayBlocked;
}
return elementsToBeBlocked.filter(filterUnblockedElements);
}
var cosmeticUnblockingRules = [];
var cosmeticBlockingRules = [".ytd-display-ad-renderer", ".ytd-player-legacy-desktop-watch-ads-renderer", ".GoogleActiveViewElement"];
var rulesItems = Object.values(rules).reverse();
for (var i = 0; i < rulesItems.length; i += 1) {
var rule = rulesItems[i];
if (rule.type === types["b" /* TYPES */].CSS_EXCEPTIONS.name) {
cosmeticUnblockingRules.push(rule.content);
}
if (rule.type === types["b" /* TYPES */].CSS_STYLES.name && cosmeticBlockingRules.length < 3500) {
cosmeticBlockingRules.push(rule.content);
}
}
function blockElements(elementsToBlock, blocked) {
elementsToBlock.forEach(function (elem) {
elem.style.display = "none";
if (!blocked[elem.className]) {
localStorage.setItem("recently-blocked", elem.className);
}
});
}
function protectElementStyles() {
var MAX_STYLE_PROTECTION_COUNT = 50;
var protectionObserverOption = {
attributes: true,
attributeOldValue: true,
attributeFilter: ['style']
};
function hideElem(elem) {
elem.style.display = 'none';
}
function protectElementHiding(mutations, observer) {
if (!mutations.length) {
return;
}
var mutation = mutations[0];
var target = mutation.target;
observer.disconnect();
hideElem(target);
if (++observer.styleProtectionCount < MAX_STYLE_PROTECTION_COUNT) {
observer.observe(target, protectionObserverOption);
}
}
function protectStyleAttribute(node) {
if (!MutationObserver) {
return null;
}
var protectionObserver = new MutationObserver(protectElementHiding);
protectionObserver.observe(node, protectionObserverOption); // protectionObserver.styleProtectionCount = 0;
return protectionObserver;
}
return protectStyleAttribute;
}
return "\n try {\n var cosmeticUnblockingRulesJSON = String.raw`".concat(JSON.stringify(cosmeticUnblockingRules), "`;\n var cosmeticBlockingRulesJSON = String.raw`").concat(JSON.stringify(cosmeticBlockingRules), "`;\n\n var blocked = {}\n\n var cosmeticUnblockingRules = JSON.parse(cosmeticUnblockingRulesJSON);\n var cosmeticBlockingRules = JSON.parse(cosmeticBlockingRulesJSON);\n\n ", "".concat(findElementsToBeBlocked), "\n ", "".concat(blockElements), "\n ", "".concat(protectElementStyles), "\n\n var protectElemStyleAttribute = ").concat(protectElementStyles.name, "();\n\n var elemsToBeBlocked = ").concat(findElementsToBeBlocked.name, "(cosmeticUnblockingRules, cosmeticBlockingRules);\n\n ").concat(blockElements.name, "(elemsToBeBlocked, blocked);\n\n elemsToBeBlocked.forEach((elem) => {\n protectElemStyleAttribute(elem);\n });\n\n } catch(e) {\n console.log(e)\n }");
};
// CONCATENATED MODULE: ./utils/regExpFromException.js
function constructRegexFromExceptionRule(rule) {
var firstSlashIndex = rule.indexOf('/');
var lastSlashIndex = rule.lastIndexOf('/');
var regexBody = rule.slice(firstSlashIndex + 1, lastSlashIndex);
var modifiers = rule.slice(lastSlashIndex + 1);
return new RegExp(regexBody, modifiers);
}
// CONCATENATED MODULE: ./utils/checkExceptionRule.js
var checkExceptionRule_isExceptionRule = function isExceptionRule(rules, type) {
var isUnblocked = false;
for (var i = 0; i < rules.length; i += 1) {
var rule = rules[i];
if (rule.type === type) {
var regexFromRule = constructRegexFromExceptionRule(rule.content);
if (regexFromRule.test(window.location.href)) {
isUnblocked = true;
break;
}
}
}
return isUnblocked;
};
// CONCATENATED MODULE: ./contentScripts/injection/javascriptInjection.js
var javascriptInjection_javascriptInjections = function javascriptInjections(rules) {
var result = '';
if (checkExceptionRule_isExceptionRule(rules, types["b" /* TYPES */].JAVASCRIPT_EXCEPTION.name)) {
return result;
}
for (var i = 0; i < rules.length; i += 1) {
var rule = rules[i];
if (rule.type === types["b" /* TYPES */].JAVASCRIPT.name) {
result += "".concat(rule.content, ";");
}
}
return "try {\n ".concat(result, "\n } catch(e) {\n console.log(e)\n }");
};
// CONCATENATED MODULE: ./contentScripts/injection/mainScriptInject.js
var mainScriptInject = function mainScriptInject(injectionString, tagIg) {
var isInjected = Boolean(document.getElementById(tagIg));
if (!isInjected) {
var TagWithScript = document.createElement('script');
TagWithScript.type = "text/javascript";
TagWithScript.innerHTML = injectionString;
TagWithScript.id = tagIg;
document.head.appendChild(TagWithScript);
if (TagWithScript.parentNode) {
TagWithScript.parentNode.removeChild(TagWithScript);
}
}
};
// CONCATENATED MODULE: ./contentScripts/injection/injectionDefender.js
function executeInjectionOnDocumentChanges(executeInjection) {
var EventTracker = function () {
var ignoredEventTypes = ['mouseover', 'mouseleave', 'mouseenter', 'mouseout'];
var LAST_EVENT_TIMEOUT_MS = 2000;
var trackedEvents = ['keydown', 'keypress', 'keyup', 'auxclick', 'click', 'contextmenu', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup', 'pointerlockchange', 'pointerlockerror', 'select'];
var lastEventType;
var lastEventTime;
var trackEvent = function trackEvent(e) {
lastEventType = e.type;
lastEventTime = Date.now();
};
trackedEvents.forEach(function (evName) {
document.documentElement.addEventListener(evName, trackEvent, true);
});
var getLastEventType = function getLastEventType() {
return lastEventType;
};
var getTimeSinceLastEvent = function getTimeSinceLastEvent() {
return Date.now() - lastEventTime;
};
return {
isIgnoredEventType: function isIgnoredEventType() {
return ignoredEventTypes.indexOf(getLastEventType()) > -1 && getTimeSinceLastEvent() < LAST_EVENT_TIMEOUT_MS;
}
};
}();
var domObserved;
var domMutationObserver;
function observeDocument(callback) {
var isIgnoredMutation = function isIgnoredMutation(mutations) {
for (var i = 0; i < mutations.length; i += 1) {
if (mutations[i].type !== 'attributes') {
return false;
}
}
return true;
};
domMutationObserver = new MutationObserver(function mutationHandler(mutations) {
if (!mutations || mutations.length === 0) {
return;
}
if (EventTracker.isIgnoredEventType() && isIgnoredMutation(mutations)) {
return;
}
callback();
});
domMutationObserver.observe(document, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['id', 'class']
});
}
function disconnectDocument() {
if (domMutationObserver) {
domMutationObserver.disconnect();
}
}
var executionTimesLimit = 3;
var executionCount = 0;
function applyRules() {
if (executionCount > executionTimesLimit) {
return;
}
stopObserve();
executeInjection();
executionCount++;
startObserve();
}
function startObserve() {
if (domObserved) {
return;
}
domObserved = true;
observeDocument(applyRules);
}
function stopObserve() {
if (!domObserved) {
return;
}
domObserved = false;
disconnectDocument();
}
return applyRules;
}
function InjectWithObserver(injectionString) {
return "\n ".concat(executeInjectionOnDocumentChanges, "\n\n function execute() {\n ").concat(injectionString, "\n }\n\n ").concat(executeInjectionOnDocumentChanges.name, "(execute)();\n ");
}
// CONCATENATED MODULE: ./contentScripts/blockingLogic.js
// eslint-disable-next-line import/named
var getRules = function getRules() {
var rulesTag = document.getElementById('5223075137228');
var rules = [];
if (rulesTag) {
rulesTag.childNodes.forEach(function (el) {
var rule = {
type: el.getAttribute('blocker-type'),
content: el.textContent
};
rules.push(rule);
});
rulesTag.remove();
}
return rules;
};
var injected;
(function () {
var rules = getRules();
applyCss(rules);
var injectCosmeticRules = InjectWithObserver(cosmeticInjection_cosmeticInjections(rules));
if (!injected) {
mainScriptInject(injectCosmeticRules || '', 'kyb9g3zmzpb55ab');
mainScriptInject(javascriptInjection_javascriptInjections(rules), 'kyb9g3zmzpb55ab');
}
injected = true;
})();
/***/ }),
/***/ 2:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return TYPES; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return CHANGE_UA_TYPES; });
var TYPES = {
CSS_EXCEPTIONS: {
name: 'CSS_EXCEPTIONS',
format: /^(.*)#@#(.+)$/
},
CSS_STYLES: {
name: 'CSS_STYLES',
format: /^(.*[^#])?##(.+)$/
},
CSS: {
name: 'CSS',
format: /^(.*)#\$#(.+)$/
},
IGNORE_CSS: {
name: "IGNORE_CSS",
format: /^(.*?)\^\$css_ignore$/
},
IGNORE_CSS_EXCEPTIONS: {
name: "IGNORE_CSS_EXCEPTIONS",
format: /^(.*?)\^\$css_ignore_exceptions=(.+)$/
},
JAVASCRIPT: {
name: 'JAVASCRIPT',
format: /^(.*)#%#(.+)$/
},
JAVASCRIPT_EXCEPTION: {
name: 'EXCEPTION_JAVASCRIPT',
format: /^(.*)@%@%@%@(.*)$/
}
};
var CHANGE_UA_TYPES = {
MODIFY_UA: {
name: "MODIFY_UA",
format: /^(.*?)\^\$change_ua=(.+)$/
},
EXCEPTION_UA: {
name: "EXCEPTION_UA",
format: /^(.*?)\^\$exception_ua\@\@domains=(.*?)\@\@val=(.+)$/
},
IGNORE_UA: {
name: "IGNORE_UA",
format: /^(.*?)\^\$ua_ignore$/
},
PARTNER_UA: {
name: "PARTNER_UA",
format: /^(.*?)\^\$partner_change_ua=(.+)$/
},
HEADERS: {
name: "HEADERS",
format: /\|\|(.+)\^\$re\D{2}(?:[hve]{3}(?:(?:d|a|e){3}\w{2}=))([ -~]+)$/
}
};
/***/ })
/******/ });
ELHU EMKPI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment