Open epubreader opened 9 years ago
Hi @eimhee There is a sample in doge.js on how you can replace a tag that has different content. https://github.com/No9/harmon/blob/master/examples/doge.js#L27
Your request should be quite simple to map to that but let me know if you have other issues.
thanks, I want to replace js file , not just html.
how to replace url in the application.js?
Hi @eimhee I am not quite following here. The sample shows
<img id="logo" src="/images/logo.svg" alt="node.js">
Being replaced with
<img id="logo" src="http://i.imgur.com/LKShxfc.gif" alt="node.js">
If you want to replace the js returned by the server then you need to intercept the request here https://github.com/No9/harmon/blob/master/examples/doge.js#L57
Thanks, No9, but I don't want to replace the tag, I want to replace the content in the js file. for example,
some content in this file, var i = e.document, o = e.SelectorSet, a = t.event.add, s = t.event.remove, c = {}; if (!o) throw "SelectorSet undefined - https://github.com/josh/jquery-selector-set"; t.event.add = function(e, n, s, u, l) { if (e !== i || n.match(/./) || u || !l) a.call(this, e, n, s, u, l); else for (var f = n.match(/\S+/g), d = f.length; d--;) { var p = f[d], h = t.event.special[p] || {}; p = h.delegateType || p; var m = c[p]; m || (m = c[p] = { handler: r, selectorSet: new o }, m.selectorSet.match
I want to replace https://github.com/josh/jquery-selector-set to https://xxx.com/josh/jquery-selector-set
ok so at the line I mentioned above https://github.com/No9/harmon/blob/master/examples/doge.js#L57 You probably want to do something like
function (req, res) {
if (req.url === 'https://github.com/josh/jquery-selector-set ') {
http.get('https://xxx.com/josh/jquery-selector-set', function (getres) {
getres.pipe(res)
})
} else {
proxy.web(req, res);
}
}
See https://nodejs.org/api/http.html#http_http_get_options_callback and http://dailyjs.com/2012/11/19/streams-part-2/ as a guide N.B. This code probably won't run but should give you an idea of what needs to be done
do we support modifying JSON response?
We don't right now and my feeling is that it should probably be a separate library as people who want a tag parser may not want a JSON parser and vica versa.
I want to replace url in script and css. how to repace inline script or css