Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to repace inline script or css #28

Open
epubreader opened this issue Aug 31, 2015 · 7 comments
Open

how to repace inline script or css #28

epubreader opened this issue Aug 31, 2015 · 7 comments

Comments

@epubreader
Copy link

I want to replace url in script and css.
how to repace inline script or css

@No9
Copy link
Owner

No9 commented Aug 31, 2015

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.

@epubreader
Copy link
Author

thanks, I want to replace js file , not just html.

<script src="http://www.iteye.com/javascripts/application.js?1358214518" type="text/javascript"></script>

how to replace url in the application.js?

@No9
Copy link
Owner

No9 commented Sep 1, 2015

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

@epubreader
Copy link
Author

Thanks, No9,
but I don't want to replace the tag, I want to replace the content in the js file.
for example,

https://assets-cdn.github.com/assets/frameworks-06e65f5639cc52d1aaada53115a54614b60fa90ab446a673e3e1818df167663b.js

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

@No9
Copy link
Owner

No9 commented Sep 7, 2015

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

@dlei
Copy link

dlei commented Apr 19, 2016

do we support modifying JSON response?

@No9
Copy link
Owner

No9 commented Apr 21, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants