当前位置: 首页 > 工具软件 > uBlock > 使用案例 >

如何让ublock规则变短,优化,精简,去重,变少,减少。不更改原本的意思,把规则变短

越欣怡
2023-12-01

例子1-去重:
优化前:

studio.ixigua.com##.popup-btn,div.video-from-base-title:nth-of-type(2),.recommend
studio.ixigua.com##
studio.ixigua.com##
studio.ixigua.com##div.video-from-sub-title:nth-of-type(2)
studio.ixigua.com##div.parting-line:nth-of-type(7)
studio.ixigua.com##div.extra-padding.video-from-base-title:nth-of-type(8)
studio.ixigua.com##.sub.parting-line
studio.ixigua.com##div.video-from-sub-title:nth-of-type(12)
studio.ixigua.com##.m-anchor
studio.ixigua.com##.video-from-base-timer.extra-padding.video-from-base-title
studio.ixigua.com##div.video-form-item:nth-of-type(13) > .video-form-item-label > .label
studio.ixigua.com##div.video-form-item:nth-of-type(13) > .video-form-item-label
studio.ixigua.com##.form-item-download.video-form-item
studio.ixigua.com##.form-item-abstract.video-form-item
studio.ixigua.com##.form-item-add-caption.video-form-item
studio.ixigua.com##.form-item-video-segmentation.video-form-item
studio.ixigua.com###js-video-preview
studio.ixigua.com##.form-item-privacy.video-form-item
studio.ixigua.com##.form-item-dy-setting.video-form-item
studio.ixigua.com##.video-form-item-help
studio.ixigua.com##.form-item-poster.video-form-item > .required.video-form-item-label
studio.ixigua.com##.video-form-head-tip
studio.ixigua.com##.form-item-hash_tag.video-form-item > .video-form-item-label
studio.ixigua.com##.form-item-title.video-form-item > .required.video-form-item-label
studio.ixigua.com##.form-item-origin.video-form-item > .required.video-form-item-label
studio.ixigua.com##.form-item-activity-tags.video-form-item > .video-form-item-label
studio.ixigua.com##.form-item-praise.video-form-item
studio.ixigua.com##.upload-activity-modal__title
studio.ixigua.com##.form-item-reprint.video-form-item
studio.ixigua.com##.label
studio.ixigua.com##div.parting-line
studio.ixigua.com##.fold-title-tip
studio.ixigua.com##.m-xigua-upload-video-content > div:nth-of-type(1)
studio.ixigua.com##.m-progress
studio.ixigua.com##.user-info
studio.ixigua.com##.user-info__username
studio.ixigua.com##.origin-tip
studio.ixigua.com##.arco-tag-close-btn.arco-tag-icon-hover.arco-icon-hover
studio.ixigua.com##.xs-menu-list__divider
||ixigua.com^$script
studio.ixigua.com##.errorTips
studio.ixigua.com##.multi-titles__container
studio.ixigua.com##.upload-banner-container
studio.ixigua.com##.slide
studio.ixigua.com##.ext-option
studio.ixigua.com##.option-bar.btn-action-warp
studio.ixigua.com##.footer-options-wrap
studio.ixigua.com##.byte-modal-title
studio.ixigua.com##.m-create-action
studio.ixigua.com##.community-sticker-panel-empty
studio.ixigua.com##.community-sticker-panel-form-item-duration.community-sticker-panel-form-item.arco-form-layout-horizontal.arco-form-item.arco-row-justify-start.arco-row-align-start.arco-row
studio.ixigua.com##.arco-form-extra
studio.ixigua.com##.community-sticker-panel-form-item-has-extra.community-sticker-panel-form-item-start-time.community-sticker-panel-form-item.arco-form-layout-horizontal.arco-form-item.arco-row-justify-start.arco-row-align-start.arco-row
studio.ixigua.com##.community-sticker-panel-form-item-start-time-smart.community-sticker-panel-form-item-start-time.community-sticker-panel-form-item.arco-form-layout-horizontal.arco-form-item.arco-row-justify-start.arco-row-align-start.arco-row
studio.ixigua.com##.community-sticker-panel-form-item-start-time.community-sticker-panel-form-item.arco-form-layout-horizontal.arco-form-item.arco-row-justify-start.arco-row-align-start.arco-row
studio.ixigua.com##.community-sticker-panel-form-name
studio.ixigua.com##.percent

优化后:

studio.ixigua.com##.popup-btn,div.video-from-base-title:nth-of-type(2),.recommend,div.video-from-sub-title:nth-of-type(2),div.parting-line:nth-of-type(7),div.extra-padding.video-from-base-title:nth-of-type(8),.sub.parting-line,div.video-from-sub-title:nth-of-type(12),.m-anchor,.video-from-base-timer.extra-padding.video-from-base-title,div.video-form-item:nth-of-type(13) > .video-form-item-label,.form-item-download.video-form-item,.form-item-abstract.video-form-item,.form-item-add-caption.video-form-item,.form-item-video-segmentation.video-form-item,#js-video-preview,.form-item-privacy.video-form-item,.form-item-dy-setting.video-form-item,.video-form-item-help,.form-item-poster.video-form-item > .required.video-form-item-label,.video-form-head-tip,.form-item-hash_tag.video-form-item > .video-form-item-label,.form-item-title.video-form-item > .required.video-form-item-label,.form-item-origin.video-form-item > .required.video-form-item-label,.form-item-activity-tags.video-form-item > .video-form-item-label,.form-item-praise.video-form-item,.upload-activity-modal__title,.form-item-reprint.video-form-item,.label,div.parting-line,.fold-title-tip,.m-xigua-upload-video-content > div:nth-of-type(1),.m-progress,.user-info,.user-info__username,.origin-tip,.arco-tag-close-btn.arco-tag-icon-hover.arco-icon-hover,.xs-menu-list__divider,.errorTips,.multi-titles__container,.upload-banner-container,.slide,.ext-option,.option-bar.btn-action-warp,.footer-options-wrap,.byte-modal-title,.m-create-action,.community-sticker-panel-empty,.community-sticker-panel-form-item-duration,community-sticker-panel-form-item.arco-form-layout-horizontal,arco-form-item.arco-row-justify-start.arco-row-align-start.arco-row,.arco-form-extra,.community-sticker-panel-form-item-has-extra,community-sticker-panel-form-item-start-time,community-sticker-panel-form-item.arco-form-layout-horizontal,arco-form-item.arco-row-justify-start.arco-row-align-start.arco-row,.community-sticker-panel-form-item-start-time-smart,community-sticker-panel-form-item-start-time,community-sticker-panel-form-item.arco-form-layout-horizontal,arco-form-item.arco-row-justify-start.arco-row-align-start.arco-row,.community-sticker-panel-form-item-start-time,community-sticker-panel-form-item.arco-form-layout-horizontal,arco-form-item.arco-row-justify-start.arco-row-align-start.arco-row,.community-sticker-panel-form-name,.percent
||ixigua.com^$script

原理:ublock支持用逗号来分隔两个规则,这两个规则都将在每行最开始指定的网站执行,所以我们可以去除重复的开头网站,然后换成逗号添加到一行中

正则表达式快速替换:^(.+?)##(.+)\n\1##(.+)$
把这个替换为$1##$2,$3

效果:

baike.baidu.com##.lark-error-text
baike.baidu.com##.lark-error-cnt

变成了baike.baidu.com##.lark-error-text,.lark-error-cnt
提示:可以多替换几次,因为如果行比较多的话,它是这样执行的:
1
1
1
1
1
1
1
1
变成
2
2
2
2
变成
4
4
所以,这种情况需要多运行几遍,最终变成:
8

 类似资料: