gpt4 book ai didi

javascript - document.getElementsByClassName(...)[0] 在 GM 脚本中未定义,在 JS 中有效

转载 作者:行者123 更新时间:2023-11-28 06:23:56 27 4
gpt4 key购买 nike

我正在尝试使用这行 JavaScript 作为 GreaseMonkey 脚本:

javascript: document.getElementsByClassName("widget-contents")[0].style.height='640px';void(0);

我尝试将其转换为 GreaseMonkey 脚本,如下所示:

// ==UserScript==
// @name First GM Script
// @namespace http://www.example.net/
// @description first gm script
// @include https//www.example.net/*
// @version 1
// @grant none
// ==/UserScript==
document.getElementsByClassName('widget-contents') [0].style.height = '640px';

我收到此错误:

document.getElementsByClassName(...)[0] is undefined

有人可以向我解释一下我做错了什么吗?

最佳答案

尝试

document.onload = function() {
document.getElementsByClassName('widget-contents') [0].style.height = '640px';
}

关于javascript - document.getElementsByClassName(...)[0] 在 GM 脚本中未定义,在 JS 中有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35289157/

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