Last active
March 3, 2020 13:47
-
-
Save HelloWorld017/c62a83a8bda76ba5c56e864406cdafdb to your computer and use it in GitHub Desktop.
Blocks adblock-block in DaumPotTV (Kakao TV)
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 DaumPotTV Block blockAdBlock | |
// @namespace http://tampermonkey.net/ | |
// @version 0.02 | |
// @description Blocks adblock-block in DaumPotTV (Kakao TV) | |
// @author Khinenw | |
// @match *://kakaotv.daum.net/* | |
// @match *://tv.kakao.com/* | |
// @match *://play-tv.kakao.com/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
const hookProperty = (hookTarget, hookPath, replaceFn) => { | |
if(!hookTarget) | |
return hookTarget; | |
if(hookTarget.$DPTBAB_MonkeyPatched) | |
return hookTarget; | |
console.log(`Hook: ${hookPath[0]}`); | |
hookTarget.$DPTBAB_MonkeyPatched = true; | |
if(hookPath.length <= 1) | |
return replaceFn(hookTarget); | |
const nextPath = hookPath.slice(); | |
nextPath.shift(); | |
if(hookTarget[hookPath[1]]) | |
hookTarget[hookPath[1]] = hookProperty(hookTarget[hookPath[1]], nextPath, replaceFn); | |
return new Proxy(hookTarget, { | |
get(target, name) { | |
return target[name]; | |
}, | |
set(target, name, value) { | |
if(name === hookPath[1]) { | |
target[name] = hookProperty(value, nextPath, replaceFn); | |
} else { | |
target[name] = value; | |
} | |
return true; | |
} | |
}); | |
}; | |
const currentVideoHook = currentVideo => { | |
return new Proxy(currentVideo, { | |
get(target, name) { | |
if(name === 'skipOnErrorOfAdApi' || name === 'skipOnErrorOfAdContents') | |
return true; | |
return target[name]; | |
} | |
}); | |
}; | |
const hookPath = ['monet', 'modules', 'controller.state', 'currentVideo']; | |
let monetHook = window.monet; | |
if(monetHook) | |
monetHook = hookProperty(monetHook, hookPath, currentVideoHook); | |
Object.defineProperty(window, 'monet', { | |
get() { | |
return monetHook; | |
}, | |
set(value) { | |
monetHook = hookProperty( | |
value, | |
hookPath, | |
currentVideoHook | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment