Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为tampermonkey添加自定义指针?_Javascript_Tampermonkey - Fatal编程技术网

Javascript 如何为tampermonkey添加自定义指针?

Javascript 如何为tampermonkey添加自定义指针?,javascript,tampermonkey,Javascript,Tampermonkey,嘿,伙计们!我真的是一个新的编码我在tampermonkey中编码我真的不知道什么东西,这让我有点愚蠢我想添加一个指向光标的指针一个自定义光标,但我添加了这个代码,但仍然无法工作,因为某些原因它仍然与正常的指针保持一致 GM_addStyle('body{cursor:url(https://ani.cursors-4u.net/cursors/cur-13/cur1160.png)16,指针;}') 例如,我认为您应该在附加样式之前添加样式 无论如何,我认为您不需要返回elementSty

嘿,伙计们!我真的是一个新的编码我在tampermonkey中编码我真的不知道什么东西,这让我有点愚蠢我想添加一个指向光标的指针一个自定义光标,但我添加了这个代码,但仍然无法工作,因为某些原因它仍然与正常的指针保持一致
GM_addStyle('body{cursor:url(https://ani.cursors-4u.net/cursors/cur-13/cur1160.png)16,指针;}')

  • 例如,我认为您应该在附加样式之前添加样式
  • 无论如何,我认为您不需要返回elementStyle变量,因为您已经附加了它,并且不会将其用于其他用途
  • 你可以用另一种方法
  • 或者,如果您只想将新样式设置为exist元素,则可以使用此函数
  • 此外,对于tampermonkey,我建议将代码添加到
    setTimeout()
    中,因为某些网页需要一些时间来加载内容

这个“div”、“content”、“background color:red”有什么作用?你可以用它做一个示例吗?你可以添加
光标:指针
或者使用任何css属性
// @name         Master's Watermark Script
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Editable Watermark for Gota.io
// @author       Master
// @match        https://gota.io/web/*
// @icon         https://www.google.com/s2/favicons?domain=google.com
// @grant        GM_addStyle
// ==/UserScript==

function addStyleSheet(style){
  var getHead = document.getElementsByTagName("HEAD")[0];
  var cssNode = window.document.createElement( 'style' );
  var elementStyle= getHead.appendChild(cssNode);
  elementStyle.innerHTML = style;
  return elementStyle;
}

//Custom Crosshair
GM_addStyle ('body {cursor: url(https://ani.cursors-4u.net/cursors/cur-13/cur1160.png)16 16, auto;}');
GM_addStyle ('body {cursor: url(https://ani.cursors-4u.net/cursors/cur-13/cur1160.png)16 16, pointer;}');
function addStyleSheet(style){
  var getHead = document.getElementsByTagName("HEAD")[0];
  var cssNode = document.createElement( 'style' );
  cssNode.innerHTML = style;
  var elementStyle= getHead.appendChild(cssNode);
  return elementStyle;
}
function createElement(elem, content, css) {
  let newElem = document.createElement(elem);
  newElem.innerHTML = content;
  newElem.style.cssText = css;
  return newElem;
}
document.body.append(createElement('div', 'content', 'background-color: red'))
function setStyle(id, style) {
   let elem = document.getElementById(id);
   elem.style.cssText = style;
}
setStyle('elem', 'background-color: red');