Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否在一个规则内添加多个排除 #10

Closed
ivysrono opened this issue Sep 4, 2017 · 10 comments
Closed

能否在一个规则内添加多个排除 #10

ivysrono opened this issue Sep 4, 2017 · 10 comments

Comments

@ivysrono
Copy link

ivysrono commented Sep 4, 2017

#2 引发。
正则虽然能写,但数量多了以后就很难维护了。
如果分多条规则写也是很麻烦的事情。

@sylingd
Copy link
Member

sylingd commented Sep 4, 2017

并不打算单独增加此功能。但正在编写中的自定义函数功能可以满足此需求

@sylingd sylingd closed this as completed Sep 4, 2017
@ivysrono
Copy link
Author

不好意思,实在是不怎么会JS,只好请教下,怎么用自定义函数实现如下需求:
响应头:Content-Security-Policy 插入头内容:upgrade-insecure-requests
排除:
a.com
b.cn
c.info
d.com/efg
(?!www).h.com/.+
……

@sylingd
Copy link
Member

sylingd commented Sep 14, 2017

目前自定义函数功能功能还不足够,增强正在计划中

@sylingd
Copy link
Member

sylingd commented Sep 22, 2017

例如,下面规则会给所有域名包含baidu,但不包含example.com(即对baidu.demo.com、baidu.org生效),修改User-Agent头:

const domain = /.*?:\/*([^\/:]+)/.exec(detail.url)[1];
if (!domain.includes('baidu') || domain.includes('example.com')) {
return;
}
for (let a in val) {
	if (val[a].name.toLowerCase() === 'user-agent') {
		val[a].value += ' HE/2.0.0';
		break;
	}
}

@ivysrono
Copy link
Author

2.3.0就行?还是要等新版?

@sylingd
Copy link
Member

sylingd commented Sep 23, 2017

2.3.0

@ivysrono
Copy link
Author

不成功,烦请指导。
default

const domain = /.*?:\/*([^\/:]+)/.exec(detail.url)[1];
if (!domain.includes('lofter.com') || domain.includes('cmbchina.com')) {
return;
}
for (let a in val) {
	if (val[a].name.toLowerCase() === 'Content-Security-Policy') {
		val[a].value += ' upgrade-insecure-requests';
		break;
	}
}

@sylingd
Copy link
Member

sylingd commented Sep 24, 2017

使用了toLowerCase,请使用小写英文字母作比较

@ivysrono
Copy link
Author

ivysrono commented Sep 24, 2017

thanks.
但我测试结果,还是不符合我的需求。我是希望在所有 https 页面生效,仅排除个别域名或网址。

https://github.com/ivysrono/UpgradeMixedContentBlacklist 这个规则主要缺点是必须精确匹配域名,不支持正则或通配符,且只支持域名不支持指定网址。

if (!domain.includes('1') || domain.includes('2'))

这个语句如何替换 1 实现全页面生效?

而且下面这句貌似无效:

const domain = /.*?:\/*([^\/:]+)/.exec(detail.url)[1];
if (!domain.includes('cmbchina.com') || domain.includes('hk.cmbchina.com')) {
return;
}
for (let a in val) {
	if (val[a].name.toLowerCase() === 'content-security-policy') {
		val[a].value += ' upgrade-insecure-requests';
		break;
	}
}

@sylingd
Copy link
Member

sylingd commented Sep 24, 2017

const domain = /.*?:\/*([^\/:]+)/.exec(detail.url)[1];

这行代码会提取出URL的域名部分,例如https://github.com/FirefoxBar/HeaderEditor/issues/10的提取结果是github.com
下面使用的是includes方法作判断,这是关于includes方法的说明:MDN,类似的方法还有indexOf等,详情请在MDN查看。
return的作用是打断执行,即不会再执行下面的代码。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants