假设我有两个内容脚本,codeA.js并且codeB.js. 我想知道是否可以在http://www.example.comcodeA.js上运行并在http://www.domain.com上运行。codeB.js
是否可以将文件content_scripts中的my 设置manifest.json为:
"content_scripts": [
{
"matches": ["http://www.example.com", "http:www.domain.com"],
"js": ["codeA.js", "codeB.js"]
}
]
Run Code Online (Sandbox Code Playgroud)
然后让每个脚本检查页面当前位于哪个 URL?如果是这样,我将如何去做这件事?
更新:
我尝试使用以下代码
if(document.location == "http://*.google.com/*" || "https://*.google.com/*") {
alert("you are using google");
} else if(document.location == "http://*.yahoo.com/*" || "https://*.yahoo.com") {
alert("you are using yahoo!");
}
Run Code Online (Sandbox Code Playgroud)
但我不断得到you are using google。
javascript google-chrome google-chrome-extension content-script
我有一个 XPath /html/body/div[1]/div/div/center[1]/table,我想让它不再可见。
我看到我可以使用,document.evaluate()但我不知道如何隐藏它。
我有这个用户脚本 (在Stack Overflow的帮助下写的)用于网站metal-archives.com.
它的结构是这样的:
function appendColumn(...) {
// code for appending column
// code for making the table sortable
}
waitForKeyElements ("table", appendColumn);
Run Code Online (Sandbox Code Playgroud)
当您切换子标签(表格)时,脚本可以正常工作,除了视觉故障/延迟.
切换时,额外(第6列)最初显示为预期.但是,表格会以原始形式暂时显示,然后最终显示第6列.
要查看此内容,请安装脚本,访问此典型目标页面,然后切换子选项卡(完成唱片,主要,生命,演示,杂项等).
它看起来像这样:
我试图通过添加以下内容来显示初始表:
GM_addStyle(".display.discog {display: none;} ");
Run Code Online (Sandbox Code Playgroud)
到和的开头appendColumn():
GM_addStyle(".display.discog {display: inline !important;} ");
Run Code Online (Sandbox Code Playgroud)
到了最后appendColumn().
但它没有任何区别.
我在该页面上使用了Firefox网络监视器,当你切换标签时似乎:
如何更改代码(使用waitForKeyElements时)以防止显示关键元素,并仅在我的代码修改后显示它?
或者我如何加快响应速度?
谢谢.
我有一个小问题,我有一个脚本(我正在使用Tampermonkey),当我发出POST请求时,它说:
VM2584:33拒绝连接到" https://my_url.com/sub1/sub2/":URL不是@connect列表的一部分
它是"@connect列表"的一部分
// @name My Script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match url.com/*
// @grant GM_xmlhttpRequest
// @grant GM_getValue
// @grant GM_setValue
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
// @require https://raw.githubusercontent.com/js-cookie/js-cookie/master/src/js.cookie.js
// @connect https://my_url.com/sub1/sub2/
Run Code Online (Sandbox Code Playgroud)
那么问题出在哪里?
我对 CSS 和 javascript 很陌生,所以别着急。
我试图disable-stream从 div class="stream-notifications" 下的每个 div 元素中删除该类。(见下图)
我在 Tampermonkey 中尝试了以下方法,但似乎不起作用:
(function() {
'use strict';
disable-stream.classList.remove("disable-stream");})();
Run Code Online (Sandbox Code Playgroud)
假设我有一个列表,其中包含任意数量的缩进级别,如下所示:
Item
Item
Item
Item
Item
Item
Item
Item
Item
Item
Item
Run Code Online (Sandbox Code Playgroud)
如果我在HTML文档中显示此列表,我如何使用CSS来处理缩进?可能存在任意数量的缩进级别(尽管实际上不会超过5个左右).
我不想创建一个缩进10个像素的"indent1"类,一个缩进20个像素的"indent2"类等 - 这很笨拙.是否可以创建一个通用规则,该规则将根据属性值或层次结构中元素的位置缩进一定距离?
我有这样的函数...我试图使用变量插入一个类名gotValue.我如何在jQuery中传递它?我在if子句中尝试过,但它没有用.
function fullData(gotValue)
{
alert(gotValue);
var count = gotvalue.substring(9);
if($('.'+gotValue+'').is(':checked'))
{
alert('working');
}
}
Run Code Online (Sandbox Code Playgroud) 我试图在SQL 2008中创建一个链接服务器到Advantage v7数据库服务器.我已经使用下面的命令在SQL 2008中成功创建了链接服务器,并且连接测试正常.另外,我连接的Advantage DB没有数据字典.
SQL创建链接服务器
EXEC master.dbo.sp_addlinkedserver
@server = N'ADVANTAGE', @srvproduct=N'Advantage',
@provider=N'Advantage.OLEDB',
@datasrc=N'\\asc1\questtest$\spaulrun'
/* For security reasons the linked server remote logins password is changed with ######## */
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname=N'ADVANTAGE',
@useself=N'False',
@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL
Run Code Online (Sandbox Code Playgroud)
当我运行以下查询时:
select * from
openquery(ADVANTAGE,'select * from members')
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Advantage.OLEDB" for linked server "ADVANTAGE" reported an error. Access denied.
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE …Run Code Online (Sandbox Code Playgroud) var
calculator = document.calculator;
input1 = calculator.input1;
input2 = calculator.input2;
result = calculator.result;
equals = calculator.equals;
function add(a,b) {
equals.value = a+b;
}
result.addEventListener("click", function() {
add.apply(add, [input1.value, input2.value]);
});
<form name="calculator">
<input type="text" name="input1" /><br />
<input type="text" name="input2" /><br />
<input type="button" name="result" value="result" /><br /><br />
<input type="text" name="equals" readonly="true" />
</form>
Run Code Online (Sandbox Code Playgroud)
它只返回数字 - 不添加.例如:5 + 3 = 53不是8.我该如何解决这个问题?
我想$('body:contains("")')用来搜索部分HTML代码.
例如:
var thing = $('body:contains("Web</a></td></tr>")').text()
if(thing) {
alert(thing);
}
else{
alert("not found")
}
Run Code Online (Sandbox Code Playgroud)
此代码始终提醒"未找到".
是否可以搜索html代码的一部分并在发现时发出警报?
谢谢...
javascript ×8
jquery ×4
css ×3
tampermonkey ×3
ajax ×2
greasemonkey ×2
html ×2
firefox ×1
xpath ×1