Greymonkey 插入 JavaScript
我有一个小书签,单击该小书签包含一个 PHP 脚本(评估为 JavaScript 文件)到页面上的几个表值并选择作为 GET 参数传递的值。 PHP脚本将页面数据写入MySQL数据库,并输出成功消息,该消息被视为JavaScript代码并由浏览器执行。是否有可能使用greasemonkey 来执行此操作,并在单击网页上的现有按钮时调用此函数。
受本教程的启发,我编写了上述书签。
http://tutorialzine.com/2010/04/simple -bookmarking-app-php-javascript-mysql/
这是书签代码:
(function () {
var jsScript = document.createElement('script');
jsScript.setAttribute('type', 'text/javascript');
jsScript.setAttribute('src', '/bookmark.php?url=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title));
document.getElementsByTagName('head')[0].appendChild(jsScript);
})();
请帮助我。
I have a bookmarklet, clicking the bookmarklet includes a PHP script (evaluated as a JavaScript file) to the page few table values and select values passed as GET parameters. The PHP script writes the page data to the MySQL database, and outputs a success message that is treated as JavaScript code and executed by the browser. Is there any possibility to do this using greasemonkey and call this function when a existing button is clicked on the web page.
I wrote the above bookmarklet inspired by this tutorial.
http://tutorialzine.com/2010/04/simple-bookmarking-app-php-javascript-mysql/
This is the bookmarklet code:
(function () {
var jsScript = document.createElement('script');
jsScript.setAttribute('type', 'text/javascript');
jsScript.setAttribute('src', '/bookmark.php?url=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title));
document.getElementsByTagName('head')[0].appendChild(jsScript);
})();
Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们经常这样做。
这是一个适合您的脚本,只需编辑
@include
语句以匹配将使用 Greasemonkey 脚本的页面即可。另外,
/bookmark.php
可能需要更改为完整地址,而不是相对地址。We do this a lot.
Here's a script that should work for you, just edit the
@include
statement to match the pages the Greasemonkey script will be used on.Also,
/bookmark.php
will probably have to be changed to a full address, rather than a relative one.使其成为一个实际的命名函数,而不是一个闭包(就在 Greasemonkey 脚本中),然后将该函数添加为所述按钮的 onclick= 事件,直接内嵌在实际函数的下方。
尽管如此,为此目的劫持预先存在的网页按钮并不安全,也不是官方祝福的方法 - 将其附加到 Greasemonkey 菜单命令并从那里启动它(右键单击菜单的小猴子图标)。
Make this an actual named function, not a closure (right in Greasemonkey script), then add that function as an onclick= event of said button, straight inline just below the actual function.
Although, hijacking pre-existing webpage buttons for that purpose is not safe nor an officially blessed method - it's much better and easier to attach it to a Greasemonkey Menu Command and launch it from there (rightclick the small monkey icon for the menu).