Created
May 20, 2015 16:29
-
-
Save anonymous/a9b9956baf1d59a107c5 to your computer and use it in GitHub Desktop.
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
/** | |
* The MIT License (MIT) | |
* | |
* Copyright (c) 2015 Putzkolonne@forums.lanik.us | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ | |
// ==UserScript== | |
// @name Anti-AntiAdblock | |
// @namespace antiantiadblock | |
// @include * | |
// @run-at document-start | |
// @version 1.0 | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
/** | |
* Filter list description: | |
* | |
* filters[array(filterobject)] ... Array of filterobjects. | |
* | |
* filterobject[object]: { | |
* name[string] ... Name of the filter used for console logging. | |
* hosts[array(hostname)] ... Array of hostnames the filter shall be applied to. | |
* filter[string|RegExp] ... The filter which is matched against the source code | |
* of every embedded script node within the website. If | |
* it is used for replacement, the whole matching is | |
* replaced. | |
* replace[null|string] ... If null, the execution of the script node is prevented. | |
* If it is a string, it replaces the filter-match and | |
* a new script with the replacement is executed after all | |
* filters are applied to the script node. | |
* } | |
* | |
* hostname[string|RegEXp]: ... If it is a string, it is matched against the hostname | |
* from the end. If it is a regular expression, it can | |
* match any part of the hostname. | |
* | |
* If a hostname matches within multiple filter objects, all filters are applied in the | |
* order they are defined (especially meaningful for replacement filters). A matching | |
* of a filter with replace value null will always prevent the execution of the script | |
* node (replacements are ignored in this case). | |
*/ | |
var filters = [ | |
{ | |
'name': 'AdDefend', | |
'hosts': [ | |
'4wheelfun.de', | |
'auto-motor-und-sport.de', | |
'autostrassenverkehr.de', | |
'boerse-online.de', | |
'brigitte.de', | |
'dshini.net', | |
'fem.com', | |
'finanzen.net', | |
'focus.de', | |
'gala.de', | |
'gamepro.de', | |
'gamestar.de', | |
'gamona.de', | |
'kabeleins.de', | |
'lustich.de', | |
'motor-klassik.de', | |
'pcwelt.de', | |
'pnn.de', | |
'promobil.de', | |
'prosieben.de', | |
'prosiebenmaxx.de', | |
'sat1.de', | |
'sat1gold.de', | |
'sixx.de', | |
'serienjunkies.de', | |
'sportal.de', | |
'sportauto.de', | |
'stern.de', | |
'testedich.de', | |
'the-voice-of-germany.de', | |
'tvspielfilm.de', | |
'webfail.com', | |
'wetter.com', | |
'wetteronline.de', | |
'woxikon.de' | |
], | |
'filter': 'function UABPInject()', | |
'replace': null | |
}, | |
{ | |
'name': 'Tisoomi (direkt)', | |
'hosts': [ | |
'autozeitung.de', | |
'formel1.de', | |
'fremdwort.de', | |
'inside-handy.de', | |
'motorsport-total.com' | |
], | |
'filter': 'function tsCheckCookie()', | |
'replace': null | |
}, | |
{ | |
'name': 'Tisoomi (indirekt)', | |
'hosts': [ | |
'energy.de', | |
'getvids.de', | |
'gewinde-normen.de', | |
'podcast.de', | |
'spielespielen24.de' | |
], | |
'filter': 'n="abcdefghijklm",r="nopqrstuvwxyz",i="0123456789";var s=t==0?i:t==1?n', | |
'replace': null | |
}, | |
{ | |
'name': 'Golem Videos werbefrei', | |
'hosts': [ | |
'golem.de' | |
], | |
'filter': /new SwfVideo\("http:\/\/video.golem.de\/nvplayer\/NonverBlaster_.+?\.swf"/, | |
'replace': 'new SwfVideo("http://video.golem.de/nvplayer/NonverBlaster-lgc.swf"' | |
} | |
]; | |
/* === End of filter list. Do not edit below this line! === */ | |
(function () { | |
if (window.top !== window.self) { | |
// do not run in IFrames | |
return; | |
} | |
let activeFilters = [ | |
]; | |
let ignoreNodes = [ | |
]; | |
let currentHost; | |
let matchPos; | |
for (let i = 0; i < filters.length; i++) { | |
for (let j = 0; j < filters[i].hosts.length; j++) { | |
currentHost = window.location.hostname; | |
matchPos = - 1; | |
if (typeof filters[i].hosts[j] === 'string') { | |
matchPos = currentHost.indexOf(filters[i].hosts[j]); | |
} | |
if (((matchPos !== - 1) && (matchPos === currentHost.length - filters[i].hosts[j].length)) || ((typeof filters[i].hosts[j] === 'object') && (filters[i].hosts[j] instanceof RegExp) && (filters[i].hosts[j].test(currentHost)))) { | |
activeFilters.push({ | |
'name': filters[i].name, | |
'filter': filters[i].filter, | |
'replace': filters[i].replace | |
}); | |
break; | |
} | |
} | |
} | |
if (activeFilters.length > 0) { | |
window.addEventListener('beforescriptexecute', function (a_event) { | |
let ignorePos = ignoreNodes.indexOf(a_event.target); | |
if (ignorePos !== - 1) { | |
ignoreNodes.splice(ignorePos, 1); | |
return; | |
} | |
let scriptText = a_event.target.text; | |
let oldScriptText; | |
for (let i = 0; i < activeFilters.length; i++) { | |
if (activeFilters[i].replace !== null) { | |
oldScriptText = scriptText; | |
scriptText = scriptText.replace(activeFilters[i].filter, activeFilters[i].replace); | |
if (scriptText !== oldScriptText) { | |
console.log('Anti-AntiAdblock: Modified script according to template \'' + activeFilters[i].name + '\'.'); | |
} | |
} | |
else { | |
if (((typeof activeFilters[i].filter === 'object') && (activeFilters[i].filter instanceof RegExp) && (activeFilters[i].test(scriptText))) || ((typeof activeFilters[i].filter === 'string') && (scriptText.indexOf(activeFilters[i].filter) !== - 1))) { | |
a_event.preventDefault(); | |
a_event.stopPropagation(); | |
console.log('Anti-AntiAdblock: Prevented execution of script \'' + activeFilters[i].name + '\'.'); | |
return; | |
} | |
} | |
} | |
if (scriptText !== a_event.target.text) { | |
a_event.preventDefault(); | |
a_event.stopPropagation(); | |
let scriptElement = document.createElement('script'); | |
scriptElement.setAttribute('type', 'application/javascript'); | |
scriptElement.text = scriptText; | |
ignoreNodes.push(scriptElement); | |
a_event.target.parentNode.insertBefore(scriptElement, a_event.target) | |
// will run even if cleaned up immediately | |
a_event.target.parentNode.removeChild(scriptElement); | |
} | |
}); | |
} | |
}) (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment