Skip to content

Commit b6d4f19

Browse files
committed
GreaskFork++ | Feature Change
### Changed the implementation of customBlacklist filtering * Now you can use re/xxx/i to do filtering * Now you can use "AND" logic for filtering (with regexp used)
1 parent cb74160 commit b6d4f19

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

473830-greasyfork++.user.js

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name Greasy Fork++
33
// @namespace https://github.com/iFelix18
4-
// @version 3.3.0
4+
// @version 3.3.1
55
// @author CY Fung <https://greasyfork.org/users/371179> & Davide <[email protected]>
66
// @icon https://www.google.com/s2/favicons?domain=https://greasyfork.org
77
// @description Adds various features and improves the Greasy Fork experience
@@ -1046,6 +1046,60 @@ inIframeFn() || (async () => {
10461046
return null;
10471047
}
10481048

1049+
const ruleFn = function (text) {
1050+
/** @type {String[]} */
1051+
const { rules, regExpArr } = this;
1052+
let text0 = text.replace(/\uE084/g, '\uE084x');
1053+
let j = 0;
1054+
for (const rule of rules) {
1055+
let r = false;
1056+
if (!rule.includes('\uE084')) {
1057+
r = (text.toLocaleLowerCase("en-US").includes(rule.toLocaleLowerCase("en-US")));
1058+
} else {
1059+
const s = rule.split(/\uE084(\d+)r/);
1060+
r = s.every((t, i) => {
1061+
if (t === undefined || t.length === 0) return true;
1062+
if (i % 2) {
1063+
return regExpArr[+t].test(text0);
1064+
} else {
1065+
return text0.includes(t.trim());
1066+
}
1067+
});
1068+
}
1069+
if (r) return j;
1070+
j++;
1071+
}
1072+
}
1073+
1074+
/** @param {String} txtRule */
1075+
const preprocessRule = (txtRule) => {
1076+
const regExpArr = [];
1077+
txtRule = txtRule.replace(/\uE084/g, '\uE084x');
1078+
let maxCount = 800; // avoid deadloop
1079+
while (maxCount--) {
1080+
const idx1 = txtRule.search(/\bre\//);
1081+
if (idx1 < 0) break;
1082+
const str = txtRule.substring(idx1 + 3);
1083+
let idx2 = -1;
1084+
const searcher = /(.?)\//g;
1085+
let m;
1086+
while (m = searcher.exec(str)) {
1087+
if (m[1] === '\\') continue;
1088+
idx2 = searcher.lastIndex + idx1 + 3;
1089+
break;
1090+
}
1091+
if (idx2 < 0) break;
1092+
const optionStr = txtRule.substring(idx2);
1093+
const optionM = /^[a-z]+/.exec(optionStr);
1094+
const option = optionM ? optionM[0] : '';
1095+
const regexContent = txtRule.substring(idx1 + 2 + 1, idx2 - 1);
1096+
txtRule = `${txtRule.substring(0, idx1)}${('\uE084' + regExpArr.length + 'r')}${txtRule.substring(idx2 + option.length)}`;
1097+
regExpArr.push(new RegExp(regexContent, option));
1098+
}
1099+
const rules = txtRule.split(',').map(e => e.trim());
1100+
return ruleFn.bind({ rules, regExpArr });
1101+
}
1102+
10491103
const useHashedScriptName = true;
10501104
const fixLibraryScriptCodeLink = true;
10511105
const addAdditionInfoLengthHint = true;
@@ -1143,7 +1197,7 @@ inIframeFn() || (async () => {
11431197
});
11441198
gmc.initialized = new Promise(r => (gmc.initializedResolve = r));
11451199
await gmc.initialized.then();
1146-
const customBlacklistRE = createRE((gmc.get('customBlacklist') || '').replace(/\s/g, '').split(',').join('|'), 'giu');
1200+
const customBlacklistRF = preprocessRule(gmc.get('customBlacklist') || '');
11471201

11481202
const valHideRecentUsersWithin_ = Math.floor(+gmc.get('hideRecentUsersWithin'));
11491203
const valHideRecentUsersWithin = valHideRecentUsersWithin_ > 168 ? 168 : valHideRecentUsersWithin_ > 0 ? valHideRecentUsersWithin_ : 0;
@@ -2099,8 +2153,8 @@ inIframeFn() || (async () => {
20992153
}
21002154
break;
21012155
case 'customBlacklist': {
2102-
const customBlacklist = customBlacklistRE;
2103-
if (customBlacklist && (customBlacklist.test(name) || customBlacklist.test(description)) && !element.classList.contains('blacklisted')) {
2156+
const customBlacklist = customBlacklistRF;
2157+
if (customBlacklist && (customBlacklist(name) >= 0 || customBlacklist(description) >= 0) && !element.classList.contains('blacklisted')) {
21042158
element.classList.add('blacklisted', 'custom-blacklist');
21052159
if (gmc.get('hideBlacklistedScripts') && gmc.get('debugging')) {
21062160
let scriptLink = element.querySelector('.script-link');

0 commit comments

Comments
 (0)