如何增强不应修改源代码的页面的功能? [英] How can I enhance the functionality of a page whose source I shouldn't modify?

查看:126
本文介绍了如何增强不应修改源代码的页面的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一位朋友使用网络应用程序进行工作相关的目的。
该应用程序是使用PHP / MySQL构建的,虽然它有一些JavaScript可以让它更容易使用,但它不够用户友好,并且有一些额外的JS,很多东西都可以实现自动化。

A friend of mine uses a web-app for work related purposes. The app's built using PHP/MySQL , and while it has some JavaScript to make it easier to work with, it's not user friendly enough, and with a bit of extra JS, a lot of stuff could be automated.

我想增强该应用程序,但我不想修改原始服务器端代码。要做到这一点,我能想到的只有Greasemonkey。这是唯一的方法,或者我错过了什么?我也希望能够使用现代的JS框架,比如jQuery。

I would like to enhance that app, but I'd like to not have to modify the original server-side code. To do this, all I could think of was Greasemonkey. Is this the only way to do it, or am I missing out something? I'd also like to be able to use a modern JS framework, like jQuery.

编辑:我应该告诉你我想做什么改进。页面上有很多字段,因此自动完成功能确实会有很大帮助。这将用于输入数据,因此AJAX也可用于某些错误检查。

I should tell you what improvements I want to make. There are a lot of fields on the page, so autocompletion would really help a lot. This will be used for data entering, so AJAX may be used for some error checking as well.

推荐答案

Greasemonkey当然是一个选项。另一个想法是对您的改进进行编码,然后从中调出 bookmarklet 。您的朋友可以使用书签(可能在书签栏中)来完成您所改进的内容。 Bookmarklets可以访问该页面,就好像它们是页面的一部分一样。

Greasemonkey is certainly an option. Another idea is to code up your improvements, and then make bookmarklets out of them. Your friend can use the bookmarks (probably in a bookmark bar) to do the things you've improved. Bookmarklets have access to the page as though they were a part of the page.

编辑1 事实上,现在我想到了, bookmarklet 能够通过向脚本标记将脚本文件(来自不同的源)加载到文档中> head 部分(好吧,或者任何地方,真的)。由于 SOP 基于文档的来源,而不是脚本,......这样,他只需要按一次按钮(对于他去的任何给定页面)来加载你的改进。

Edit 1 In fact, now I think about it, a bookmarklet should be able to load a script file (from a different origin) into a document by adding a script tag to the head section (well, or anywhere, really). Since the SOP is based on where the document came from, not the script, ... That way, he'd just have to press the button once (for any given page he goes to) to load your improvements.

编辑2 Yup,可以使用bookmarklet将任何脚本文件引导到页面中;这是一个例子:

Edit 2 Yup, a bookmarklet can be used to bootstrap any script file into the page; here's an example:

javascript:(function(){var%20d=document,db=d.body||d.documentElement,elm;elm=d.createElement('script');elm.src="http://example.com/yourscript.js";db.appendChild(elm);db.removeChild(elm);})();

为文件添加脚本元素 http://example.com/yourscript.js 到当前文档的正文,执行它。 (书签然后删除脚本元素;只需添加它就足够了,它不必坚持下去; 详细信息。)然后,您的脚本可以执行诸如添加其他脚本(在您的示例中为jQuery)之类的操作有点方法,启动自动完成器等。使用Chrome和Firefox测试上述(可能需要调整); IE不喜欢它,但我认为这是我对书签的编码或其他问题而不是根本问题。 (我对bookmarklets比较新。)

That adds a script element for the file http://example.com/yourscript.js to the body of the current document, which executes it. (The bookmarklet then removes the script element; just adding it is enough, it doesn't have to stick around; details.) Your script can then do things like add other scripts (jQuery, in your example) in the same sort of way, fire up auto-completers, etc. Tested the above (which probably needs tuning) with Chrome and Firefox; IE isn't liking it but I think that's an issue with my encoding of the bookmarklet or something rather than a fundamental problem. (I'm relatively new to bookmarklets.)

这篇关于如何增强不应修改源代码的页面的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆