Skip to content

Instantly share code, notes, and snippets.

@boyangwang
Created May 15, 2017 00:47
Show Gist options
  • Save boyangwang/9c519bbc1964f703849dcf31fa137e07 to your computer and use it in GitHub Desktop.
Save boyangwang/9c519bbc1964f703849dcf31fa137e07 to your computer and use it in GitHub Desktop.
techmeetup-2017may13-boyang
// if (MutationObserver) {
// var observer = new MutationObserver(function(mutations) {
// let scripts = Array.from(document.querySelectorAll('script'));
// console.log(scripts);
// let bjs;
// if (!(bjs = scripts.find(s => s.src.includes('b.js'))))
// return;
// // bjs.addEventListener('loaded', function(e) {bjs.remove();});
// bjs.remove();
// manipulate(bjs.src);
// this.disconnect();
// });
// observer.observe(document, {childList: true, subtree: true});
// }
// function manipulate(src) {
// var oReq = new XMLHttpRequest();
// oReq.onerror = function(e) { console.log('xxx Err', e); };
// oReq.onload = function() {
// // console.log('xxx Success', this);
// let manipulatedCode = this.responseText.replace('\'b\'', '\'c\'');
// eval(manipulatedCode);
// };
// oReq.open('get', src, true);
// oReq.send();
// }
function myfunc() { console.log('a\'s target'); }
Object.defineProperty(window, 'myTarget', {
set: function(newValue) { console.log('rejected!'); },
get: function() { return myfunc; },
configurable: false
});
<!DOCTYPE html>
<html>
<head>
<!-- <script async crossorigin="anonymous" src="//player.h-cdn.com/loader.js?customer=boyang_test"></script> -->
</head>
<body>
<!-- <script async src="a.js"></script> -->
<script src="a.js"></script>
<script src="b.js"></script>
<!--
<script>
window.myTarget();
</script> -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment