Giter Site home page Giter Site logo

how to repace inline script or css about harmon HOT 7 OPEN

no9 avatar no9 commented on July 23, 2024
how to repace inline script or css

from harmon.

Comments (7)

No9 avatar No9 commented on July 23, 2024

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.

from harmon.

epubreader avatar epubreader commented on July 23, 2024

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?

from harmon.

No9 avatar No9 commented on July 23, 2024

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

from harmon.

epubreader avatar epubreader commented on July 23, 2024

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

from harmon.

No9 avatar No9 commented on July 23, 2024

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

from harmon.

dlei avatar dlei commented on July 23, 2024

do we support modifying JSON response?

from harmon.

No9 avatar No9 commented on July 23, 2024

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.

from harmon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.