gpt4 book ai didi

javascript - 在 Opera User JavaScript 中使用 jQuery

转载 作者:数据小太阳 更新时间:2023-10-29 03:50:16 25 4
gpt4 key购买 nike

我想知道是否可以在 Opera User JavaScript 内加载 jQuery ,这样我就可以在其中使用 jQuery 功能,即使在当前未使用 jQuery 的页面上也是如此。

最佳答案

我刚刚编写了一个 Opera userJS,它是我从 Google Chrome 扩展程序转换而来的,可以轻松加载 jQuery,但在 Opera 中我不得不使用另一种解决方案,并且我想对我的代码进行最少的更改。

我只是在文档的 header 中附加了一个新的脚本标记,其中包含一个有效的 jQuery 源代码。它会在 DOM 准备就绪之前开始下载。

这是我的工作解决方案,希望对您有所帮助!

// ==UserScript==
// @name This is the name of my userJS
// @description That's the description of my userJS
// @include http://blahblah.hu/*
// @include http://*.blahblah.hu/*
// @match http://blahblah.hu/*
// @match http://*.blahblah.hu/*
// @version 1.0
// ==/UserScript==

(function( ) {

// include jQuery
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.id = 'myjQuery';
newScript.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
headID.appendChild(newScript);

window.addEventListener('load', function (e) {

// you can write your jQuery code now!
$('#yourElementId').css('background-color', 'yellow');

// further jQuery codes
// ...

}, false);

})( );

关于javascript - 在 Opera User JavaScript 中使用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2648042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com