如何增强我不应该修改其源代码的页面的功能?

发布于 2024-08-20 19:10:19 字数 294 浏览 1 评论 0原文

我的一个朋友使用网络应用程序来实现与工作相关的目的。 该应用程序是使用 PHP/MySQL 构建的,虽然它有一些 JavaScript 使其更易于使用,但它对用户不够友好,并且通过一些额外的 JS,很多东西可以自动化。

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

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

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.

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.

EDIT: 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无风消散 2024-08-27 19:10:19

油猴当然是一个选择。另一个想法是对你的改进进行编码,然后用它们制作小书签。您的朋友可以使用书签(可能在书签栏中)来完成您已改进的操作。小书签可以访问页面,就好像它们是页面的一部分一样。

编辑1 事实上,现在我想了一下,小书签应该能够通过添加将脚本文件(来自不同来源)加载到文档中script 标记到 head 部分(好吧,或者任何地方,真的)。由于SOP基于文档的来源,而不是脚本,...这样,他只需按一次按钮(对于他访问的任何给定页面)即可加载您的改进。

编辑 2 是的,小书签可用于将任何脚本文件引导到页面中;这是一个示例:

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.jsscript 元素添加到当前文档的正文中,并执行它。 (然后,小书签会删除 script 元素;只需添加它就足够了,不必保留下来;详细信息。)然后,您的脚本可以以相同的方式执行诸如添加其他脚本(在您的示例中为 jQuery)之类的操作,启动使用 Chrome 和 Firefox 测试了上述内容(可能需要调整); IE 不喜欢它,但我认为这是我的书签或其他编码的问题,而不是根本问题。 (我对小书签比较陌生。)

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.

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.

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);})();

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.)

樱&纷飞 2024-08-27 19:10:19

我认为 Javascript 可以跨帧操作,不是吗?

难道你不能只制作一个页面,在一个框架中加载原始站点,并在另一个框架中加载你的 js 界面改进吗?

(如果没有解决的话,获得雇主的许可也是一个好主意)

I think Javascript can manipulate across frames, can't it?

Can't you just make a page that loads the original site in one frame and your js interface improvements in another?

(Getting the permission of the employer is also a good idea, if thats not been addressed)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文