如果鼠标在一段时间内(例如,五秒钟)处于非活动状态并且将其重新设置为再次激活时,是否可以使用JavaScript将cursor属性设置为属性?noneauto
编辑:我意识到这none不是该cursor属性的有效值.尽管如此,许多网络浏览器似乎都支持它.此外,这方面的主要用户是我自己,因此几乎不会出现混淆的可能性.
我有两个可以做类似的脚本:
window.addEventListener("mousemove",
function(){
document.querySelector("#editor").style.background = "#000";
setTimeout("document.querySelector('#editor').style.background = '#fff'", 5000);
}
, true);
Run Code Online (Sandbox Code Playgroud)
和
var timeout;
var isHidden = false;
document.addEventListener("mousemove", magicMouse);
function magicMouse() {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
if (!isHidden) {
document.querySelector("body").style.cursor = "none";
document.querySelector("#editor").style.background = "#fff";
isHidden = true;
}
}, 5000);
if (isHidden) {
document.querySelector("body").style.cursor = "auto";
document.querySelector("#editor").style.background = "#000";
isHidden = false;
}
};
Run Code Online (Sandbox Code Playgroud)
对于其中的每一个,当鼠标处于非活动状态超过五秒时,背景颜色变为白色,而当光标移动时,背景变为黑色.但是,它们不能使光标消失.让我感到惊讶的是,如果我将命令document.querySelector("body").style.cursor = "none";放入JavaScript控制台,它就能完美运行.在脚本中,它似乎不起作用.
我已经发布了上面的脚本,因为这是我开始使用它.我不一定要求修复任何一个脚本; …
我一直在为Web应用程序中的纯文本文件设置导入脚本.
我的脚本如下:
function dataImport(files) {
confirm("Are you sure you want to import the selected file? This will overwrite any data that is currently saved in the application workspace.");
for (i = 0; i < files.length; i++) {
file = files[i]
console.log(file)
var reader = new FileReader()
ret = []
reader.onload = function(e) {
window.localStorage.setItem("ApplicationData", e.target.result);
}
reader.onerror = function(stuff) {
console.log("error", stuff)
console.log (stuff.getMessage())
}
reader.readAsText(file)
}
}
Run Code Online (Sandbox Code Playgroud)
它基本上是对这个问题的修改.
但是,目前用户可以在技术上尝试导入任何文件.由于它是为纯文本文件设计的,因此如果导入了不同类型的文件,则可能会出现问题.
我注意到,该浏览器检测正在导入的内容类型文件的控制台.这是一个例子.
fileName: "ideas.txt"
fileSize: 377
name: "ideas.txt"
size: …Run Code Online (Sandbox Code Playgroud) 我一直在使用以下CSS3选项来更改网页上文本的突出显示颜色.但是,网页上唯一的元素是textarea,以下CSS似乎没有做任何事情.
::selection { background:#B9B9B9; color:#000000; }
Run Code Online (Sandbox Code Playgroud)
我做错了吗?是否可以更改textarea的高亮颜色?或者我只是在浪费时间?
在官方文档建议检索国际化的字符串,像这样:
document.querySelector("#appname").innerHTML = chrome.i18n.getMessage("appname");
Run Code Online (Sandbox Code Playgroud)
但是,内置页面的源代码(如新选项卡页面和选项卡内设置页面(此处为示例))使用不同的方法,不需要设置其他JavaScript命令:
<title i18n-content="appname"></title>
Run Code Online (Sandbox Code Playgroud)
我试图在我自己的Web应用程序和扩展中使用它,但我似乎无法让它工作.
任何人都可以对此有所了解吗?是否可以在Web应用程序和扩展中使用它?
更新:我已经将Mohamd Mansour的回应标记为已被接受,因为从技术上讲它是正确的.如果有人在寻找基于JavaScript的解决方案,我在下面发布了自己的答案.
我是Python脚本的新手,所以如果这个问题的答案看起来很明显,请提前原谅我.
我正在尝试使用Python组建一个大规模的查找和替换脚本.我使用的代码类似于以下内容:
infile = sys.argv[1]
charenc = sys.argv[2]
outFile=infile+'.output'
findreplace = [
('term1', 'term2'),
]
inF = open(infile,'rb')
s=unicode(inF.read(),charenc)
inF.close()
for couple in findreplace:
outtext=s.replace(couple[0],couple[1])
s=outtext
outF = open(outFile,'wb')
outF.write(outtext.encode('utf-8'))
outF.close()
Run Code Online (Sandbox Code Playgroud)
如何让脚本执行查找并替换正则表达式?
具体来说,我希望它能够找到文本文件顶部指定的一些信息(元数据).例如:
Title: This is the title
Author: This is the author
Date: This is the date
Run Code Online (Sandbox Code Playgroud)
并将其转换为LaTeX格式.例如:
\title{This is the title}
\author{This is the author}
\date{This is the date}
Run Code Online (Sandbox Code Playgroud)
也许我正在以错误的方式解决这个问题.如果有比正则表达更好的方式,请告诉我!
谢谢!
更新:感谢您在答案中发布一些示例代码!只要我替换了findreplace动作,我就可以让它工作,但我不能让它们都工作.现在的问题是我无法将其正确地集成到我所拥有的代码中.如何让脚本在下面的代码段中对'outtext'执行多项操作?
for couple in findreplace:
outtext=s.replace(couple[0],couple[1])
s=outtext
Run Code Online (Sandbox Code Playgroud) 我一直在HTML5中编写一个简单的文本编辑器,它应该可以脱机工作.但是,我不能让脱机应用程序缓存工作,我无法弄清楚为什么不工作.
我的清单文件是这样的:
CACHE MANIFEST
application.html
options.html
...
Run Code Online (Sandbox Code Playgroud)
它被调用如下:
<!DOCTYPE html>
<html manifest="cache.manifest">
<head>
...
Run Code Online (Sandbox Code Playgroud)
我正在使用Google App Engine来托管Web应用程序.
我把网页放在W3C HTML验证器(http://validator.w3.org/check?uri=https%3A%2F%2Fwrite-space.appspot.com%2F)中,它很好.
我在Chrome和Firefox中测试了它.在Chrome中,没有任何内容添加到缓存存储中(window.applicationCache.status返回0).在Firefox中,不会出现要求缓存文件的通知栏.基本上,文件没有被缓存.
我已经查看了为脱机查看缓存的各种演示,并且无法解释为什么我的代码不起作用.
有人可以帮忙吗?
我需要指定用于检查网址的Google Chrome网络应用程序的ID(例如:chrome-extension:// [id_goes_here] /application.html).有什么方法可以用JavaScript调用ID然后构造URL?
我正在考虑使用以下方面的内容:
"chrome-extension://" + whatever_calls_the_ID + "/application.html";
Run Code Online (Sandbox Code Playgroud)
检查URL,但需要知道如何调用ID.
谢谢你的帮助.
javascript google-chrome web-applications google-chrome-extension
我正在尝试以编程方式创建一个包含UITableView的应用程序,该应用程序根据应用程序的Documents目录中的文件生成项目列表.我已经能够将文件读入数组_filepathsArray,但是当我尝试使用数组填充表时,编译崩溃并且Xcode抛出警告.Xcode指出了以下几行的问题:
_tableView.delegate = self;
_tableView.dataSource = _filepathsArray;
Run Code Online (Sandbox Code Playgroud)
这两者都引发了"语义问题".第一次抛出
`Assigning to 'id<UITableViewDataSource>' from incompatible type 'NSArray *__strong'`,
Run Code Online (Sandbox Code Playgroud)
而第二次抛出
`Assigning to 'id<UITableViewDelegate>' from incompatible type 'BrowserViewController *const __strong'`.
Run Code Online (Sandbox Code Playgroud)
如果我删除这些行,应用程序将正确编译(但当然不使用数据填充表),所以我认为问题与这些有关.
我是Objective C和Xcode的初学者,所以我无法弄清楚我在这里做错了什么.谢谢您的帮助.
UPDATE
我已经改变了这条线_tableView.dataSource = _filepathsArray;,_tableView.dataSource = self;正如下面的几个答案所解释的那样.现在,两行都抛出相同的错误:
`Assigning to 'id<UITableViewDelegate>' from incompatible type 'BrowserViewController *const __strong'`.
Run Code Online (Sandbox Code Playgroud)
这个错误可能是视图控制器配置方式的结果吗?在头文件中,它被定义为UIViewController
@interface BrowserViewController : UIViewController
Run Code Online (Sandbox Code Playgroud)
然后我将UITableView包含为子视图.
我已经创建了一个JavaScript正则表达式来更改LaTeX渲染器的垂直条组的实例,但是当我在同一段落中有多个这样的实例时,它只影响第一个和最后一个条形,当我更喜欢它时匹配每组酒吧.正则表达式是:
replace(/\|(.*)\|/g, "\\textsc{$1}");
Run Code Online (Sandbox Code Playgroud)
例如,使用以下示例:
Lorem | ipsum | dolor sit | amet |,consectetur | adipiscing | ELIT.
我的正则表达式产生:
Lorem\textsc {ipsum | dolor sit | amet |,consectetur | adipiscing} elit.
但我希望它尽可能地匹配所有设置,就像这样;
Lorem\textsc {ipsum} dolor sit\textsc {amet},consectetur\textsc {adipiscing} elit.
我怎样才能最好地纠正我的正则表达式来解决这个问题?
javascript ×4
regex ×2
caching ×1
colors ×1
content-type ×1
css ×1
css3 ×1
cursor ×1
filereader ×1
highlight ×1
html5 ×1
import ×1
ios ×1
mousemove ×1
offline ×1
plaintext ×1
python ×1
selection ×1
uitableview ×1
xcode ×1