Comments (7)
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.
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.
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.
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
from harmon.
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.
do we support modifying JSON response?
from harmon.
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)
- how to use harmon on specify url HOT 1
- prepareRequestSelectors HOT 1
- Dealing with bad html HOT 9
- How to use in non-html? HOT 2
- Connection hangs for very generic selectors HOT 6
- doge.js is redirecting to original site with no injection HOT 7
- Request hangs
- gzip content length issue HOT 2
- Proxy a m3u8 file HOT 1
- Variable Targets
- Use with browsersync HOT 2
- js/css filter with query params HOT 2
- Doesn't work nowadays? Examples and tests fail HOT 9
- Replacing the value inside an element HOT 3
- write() getting called before writeHead() on gzip'd content causes failures HOT 2
- help w/ hello world, they don't require harmon? HOT 1
- got error on zlib HOT 1
- No selector callbacks being invoked for certain sites HOT 2
- How to modify a file from a response
- Content Length not deleted on HTML rewrite if HTML Only HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from harmon.