Add your javascript to any page (using proxy or something else)

强颜欢笑 提交于 2020-06-11 05:49:07

问题


What I want to do is be able to see how it will look any website with my javascript attached . I want to create something like selectorgadget working on any website.

The first idea is to use a proxy (eg privoxy) and define a regular expression changing in html: </head> to <script src="http://myserver.com/my_javascript.js"></script></head>. It works, but in such case, I need to set proxy in my browser. And it is not cool because It visible only for me.

Another idea is to write a website that will download page under the hood and show it. How it will work:

  1. Go to page eg.: http://myserver.com/

  2. My index.php will download eg.: www.google.com using http client or curl, replace page source (add my <script> before </head>) and return page to user. It works, but when page contains relative images I'm not able to see it. Rewriting image src, and other script src is not so simple.

Because I want to add only javascript, I thought that you can use iframes. But there is a restriction to the same domain.

Any ideas on how to do it? Maybe some tool? Something with cross-domain iframe?


回答1:


You can configure Apache web server to work in reverse proxy mode and use your first approach. Hence it will work very similar to your second case, but all replacement Apache server will do for you.




回答2:


Bookmarklets let you do exactly this without any kludges.




回答3:


if you are using Chrome, you can develop a simple extension and use the content scripts.




回答4:


I'll throw Greasemonkey into the list of suggestions. Also note that FireBug allows you to run arbitrary JavaScript on a page, plus a lot more useful stuff for developing & debugging web apps.

(Although from your short description, I agree with awoodland that bookmarklets are probably the best solution.)




回答5:


You can use the following project which is a node based proxy that can allow you to include any arbitrary JS or CSS in all pages

https://github.com/amitamb/plugin-proxy

I am the developer of the project.



来源:https://stackoverflow.com/questions/4826522/add-your-javascript-to-any-page-using-proxy-or-something-else

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!