利用webpack4的call调用找到vuex插件后对install函数做劫持拿到Vue静态实例混入初始化函数
// ==UserScript==
// @name 智慧树Webpack Core注入
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author 李恒道
// @match https://onlineexamh5new.zhihuishu.com/*
// @icon https://www.google.com/s2/favicons?domain=qpanpan.com
// @grant none
// @run-at document-start
// ==/UserScript==
function enableWebpackHook(callback) {
let originCall = Function.prototype.call
Function.prototype.call = function (...args) {
const result = originCall.apply(this, args)
if (args[0]?.a?.version === '2.5.0') {
const install = args[1].exports.a.install
args[1].exports.a.install = function (...args) {
args[0].mixin({
mounted: function () {
this.$el['__Ivue__'] = this
}
})
return install.apply(this, args)
}
return result
}
return result
}
}
enableWebpackHook()